Draw a flowchart comparing two simple algorithms that find the largest number in a list of 5 numbers: Algorithm A checks each number one by one (slow), Algorithm B uses a method that compares pairs to reduce steps (faster). Show the steps and decisions clearly.
Algorithm efficiency basics (fast vs slow) in Intro to Computing - Draw & Compare
Start | v +-----------------------------+ +-----------------------------+ | Algorithm A: Check each num | | Algorithm B: Compare pairs | | 1. Set largest = first num | | 1. Compare num1 & num2 | | 2. For each next number: | | 2. Keep larger of pair | | - If number > largest | | 3. Compare num3 & num4 | | largest = number | | 4. Keep larger of pair | | 3. Compare largest with num5 | | 5. Compare winner of pairs & num5 | | 4. Result: largest | | 6. Result: largest number | +-----------------------------+ +-----------------------------+ | | v v End End
This flowchart shows two ways to find the largest number in a list of 5 numbers.
Algorithm A checks each number one by one. It starts by assuming the first number is the largest. Then it compares each of the other numbers to this largest value, updating it if a bigger number is found. This method requires 4 comparisons.
Algorithm B compares numbers in pairs to reduce the total comparisons. First, it compares the first two numbers and keeps the larger. Then it compares the next two numbers and keeps the larger. Finally, it compares the winner of these pairs with the last number to find the largest. This method uses fewer steps and is faster.
The flowchart uses ovals for start/end, rectangles for steps, and diamonds for decisions, making it easy to follow the logic.