Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Expressing Algorithms - Finding the Maximum Number In this assignment, you will modify an existing algorithm to solve a slightly different problem. Problem 1 (
Expressing AlgorithmsFinding the Maximum Number
In this assignment, you will modify an existing algorithm to solve a slightly different problem.
Problem 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
min and min
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 min to the first value of the collection and min to the
second.
If the element is less than min and min is less than min
Then set min to that element's value
Otherwise, if the element is less than min but min is greater than min
Then set min to that element's value
Otherwise, if the element is greater than min and is less than min
Then set min to that element's value
After inspecting all elements, output min and min which hold the two smallest values.
Given the list numbers please fill in the following table based
on the algorithm in Problem and answer the following questions.
What is the final value for min and min
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started