A question from life
Meera explains how to find the mean of a nonempty list. What makes her instructions an algorithm rather than a vague suggestion?
Chapter 11: The World of Algorithms
Images coming soon — الصور تُضاف قريبًا
Meera explains how to find the mean of a nonempty list. What makes her instructions an algorithm rather than a vague suggestion?
A finite, unambiguous procedure for producing an output from allowed inputs.
Review lesson not available yet.
Meera explains how to find the mean of a nonempty list. What makes her instructions an algorithm rather than a vague suggestion?
An algorithm specifies inputs, unambiguous steps and an output. For the stated allowed inputs it should finish after finitely many steps. A stopping rule and exceptional cases are part of the instructions.
Run the mean algorithm on 3, 5, 10.
To find a nonempty list's mean, start a running total at zero and a count at zero, process each value once, then divide total by count. An empty list needs a separate response because division by zero is undefined.
Find the largest of 4, 9, 2.
Why must an algorithm state allowed inputs?
Why not start a largest-value algorithm at zero for all nonempty real lists?
Largest of −8, −2, −6?
Specify the domain, trace each step and handle exceptional inputs.