Question
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.
Step 1
We compare the first two numbers in the sequence and assign `large` to the larger number and `second_large` to the smaller number. In LaTeX format: \[ \text{{if }} s_1 < s_2 \text{{ then}} \] \[ \text{{large}} = s_2, \text{{second\_large}} = Show more…
Show all steps
Your feedback will help us improve your experience
Adriano Chikande and 59 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 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
Algorithms
Introduction
Write an algorithm that outputs the smallest and largest values in the sequence $s_{1}, \ldots, s_{n}$
Write an algorithm that returns the index of the first occurrence of the largest element in the sequence $s_{1}, \ldots, s_{n} .$ Example: If the sequence is $6.2,8.9,4.2,8.9,$ the algorithm returns the value 2 .
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD