Answered step by step
Verified Expert Solution
Link Copied!

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 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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions