Question
Write an algorithm that finds the second-smallest element among $a, b,$ and $c .$ Assume that the values of $a, b,$ and $c$ are distinct
Step 1
If $a$ is less than $b$, then $a$ is the minimum and $b$ is the second minimum. Otherwise, $b$ is the minimum and $a$ is the second minimum. We can write this as: \[ \text{if } a < b \text{ then } \begin{cases} \text{min} = a \\ \text{second\_min} = Show more…
Show all steps
Your feedback will help us improve your experience
Adriano Chikande and 100 other Precalculus educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write an algorithm that finds the smallest element among $a, b$, and $c$
Algorithms
Introduction
Write an algorithm that returns the largest and second-largest values in the sequence $s_{1}, \ldots, s_{n} .$ Assume that $n>1$ and the values in the sequence are distinct.
Write an algorithm that returns the smallest and secondsmallest values in the sequence $s_{1}, \ldots, s_{n} .$ Assume that $n>1$ and the values in the sequence are distinct
Transcript
Watch the video solution with this free unlock.
EMAIL
PASSWORD