Question: Expressing Algorithms - Finding the Maximum Number In this assignment, you will modify an existing algorithm to solve a slightly different problem. Problem 1 (

Expressing Algorithms-Finding the Maximum Number
In this assignment, you will modify an existing algorithm to solve a slightly different problem.
Problem 1(1 point) Please draw a flowchart for an algorithm that finds the two smallest
values in the collection. You can assume that the collection has at least two values and that all
values are distinct.
The algorithm works by making one pass through the collection and keeping track of the two
smallest values seen so far:
Initialize the two smallest values so far to be the first two elements of the list, name them as
min1 and min2.
For each remaining value in the list: if the value is smaller than either of the two smallest so
far, replace the larger of the two. Set min1 to the first value of the collection and min2 to the
second.
If the element is less than min1 and min1 is less than min2,
Then set min2 to that element's value
Otherwise, if the element is less than min1 but min1 is greater than min2,
Then set min1 to that element's value
Otherwise, if the element is greater than min1 and is less than min2,
Then set min2 to that element's value
After inspecting all elements, output min1 and min2, which hold the two smallest values.
Given the list numbers =[213,576,458,3,1001,5,783], please fill in the following table based
on the algorithm in Problem 1 and answer the following questions.
What is the final value for min1 and min2.
 Expressing Algorithms-Finding the Maximum Number In this assignment, you will modify

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve the problem of finding the two smallest numbers in the given list using one ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!