KwickAcademy Python · 7 min · free
List Programs: Maximum, Minimum, Mean, Linear Search and Frequency
Write five classic list programs without built-ins: maximum, minimum, mean, linear search and frequency, plus output prediction practice. Each program needs just one loop that visits every element, and the logic earns the marks.
Follows the syllabus of: CBSE Class 11 Computer Science (083), CBSE Class 11 Computer Science Essentials (083)
On screen in this lesson
Why write them by hand?
| Built-ins: max(), min(), sum(), len(), count() |
| Exams often say: do not use built-in functions |
| Every program uses one loop over the list |
| The logic is what earns the marks |
Tracing big step by step
| mark | mark > big? | big after |
|---|---|---|
| 67 | No | 67 |
| 82 | Yes | 82 |
| 45 | No | 82 |
| 91 | Yes | 91 |
| 58 | No | 91 |
Why start with marks[0]?
| Start with the first element, not with 0 |
| With big = 0, a list of negatives gives 0 |
| 0 is not even in the list |
| For minimum, just flip > to < |
What is linear search?
| Search: is a value present, and where? |
| Check elements one by one from index 0 |
| Stop at the first match |
| Not found after the last element? Say so |
The pointer moves: find 91
| Index | Value | Equal to 91? |
|---|---|---|
| 0 | 67 | No, move on |
| 1 | 82 | No, move on |
| 2 | 45 | No, move on |
| 3 | 91 | Yes, stop |
Common exam traps
| Starting max at 0 fails for negative numbers |
| Mixing up the index pos with the value L[pos] |
| Forgetting break prints a later match |
| Dividing by 0 when the list is empty |
Quick answers
Why start the maximum at L[0] instead of 0?
With 0, a list of only negative numbers wrongly gives 0, which is not even in the list.
What does linear search return when the value is missing?
It stays at the not-found value, for example an index of -1.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
Why not start at 0?40 sec
Where does linear search start?41 sec
What does get(r, 0) do?40 sec
What does p hold in the loop?43 secThe full lesson, in text
Hello students, welcome to Kwickprep. Can you find the highest marks in a class without using max? Exams ask this every year. Today we write maximum, minimum, mean, linear search and frequency programs by hand. Then we practise output prediction questions.
A built-in function is one that Python already gives us, ready to use. Max, min, sum, len and count are all built-in functions. But exam questions often say, do not use built-in functions. Each program today needs just one loop that visits every element. The examiner wants to see that logic, so let us build it step by step.
Here are the marks of five students. We store the first element in a variable called big. Then the loop visits every mark. If the mark is greater than big, then big takes that mark. So big becomes eighty two, and later ninety one. At the end, big holds the highest mark.
Let us trace the loop in a table. First, sixty seven is not greater than sixty seven, so big stays the same. Eighty two is greater, so big becomes eighty two. Forty five is smaller, so nothing changes. Ninety one is greater, so big becomes ninety one. Fifty eight is smaller, so the answer stays ninety one.
Why did we start with the first element and not with zero? Starting from the first element always works. Suppose the list is minus five and minus two, and big starts at zero. No element is bigger than zero, so the program wrongly prints zero. For the minimum, keep the same idea and flip greater than to less than.
This one loop finds the minimum and the mean together. The mean is the average, which is the total divided by the number of elements. Small starts at the first element and keeps the smaller value. Total adds every mark, and count counts the marks, without using len. The total is three hundred forty three, and count is five. So the mean is sixty eight point six.
Next, searching. Searching means finding whether a value is present in a list, and at which position. In linear search, we check the elements one by one, starting from index zero. The index is the position number, and it starts at zero. As soon as we find a match, we stop. If we reach the end with no match, the value is not in the list.
Imagine a pointer, an arrow, moving along the list to find ninety one. At index zero the value is sixty seven, so the pointer moves on. At index one, eighty two is not a match either. At index two, forty five is not a match. At index three we find ninety one, so the search stops there.
The value we are searching for is called the key. We set found to minus one, which means not found yet. The loop variable pos is the index, our pointer. Double equals checks if the element at pos equals the key. On a match, found stores the index, and break stops the loop at once. Pause and predict. What prints if key is one hundred? Found at index minus one.
Frequency means how many times each value appears. These are runs scored off six balls in an over. A dictionary stores pairs of a key and a value, so here the key is the run, and the value is its count. If the run is already in the dictionary, plus equals one adds one to its count. Otherwise, we add it with a count of one. So four came three times, six came twice, and one came once.
Some questions ask for frequency using lists, not a dictionary. The list seen remembers values we have already reported. For each run not yet seen, we add it to seen. Then count gives how many times it appears in runs. This way, each value prints only once. Count is a built-in function, so use it only when the question does not forbid built-ins.
Now, exam style output questions. Pause the video and predict first. The loop finds the largest value, which is eight. The method index gives the position of the first eight, which is index one. So the output is one and eight. Greater than or equal to changes big again at the second eight, but the value is still eight.
Here is one more question to try. Watch the difference between the index, pos, and the value, L of pos. When pos is zero, five times zero adds zero. When pos is one, ten times one adds ten. When pos is two, fifteen times two adds thirty. So total is forty.
Keep four traps in mind. Starting the maximum at zero fails when all numbers are negative. Many students mix up the index with the value stored at that index. Without break, the search keeps going and may store a later match. And the mean of an empty list divides by zero, which gives a ZeroDivisionError.
Let us revise what we learned today. For maximum and minimum, start with the first element and compare every element. The mean is the total divided by the count. Linear search checks elements one by one and breaks on the first match. Frequency is easiest with a dictionary of value and count. And before predicting output, trace the loop in a table.
Courses that teach this
| Course | Unit |
|---|---|
| CBSE Class 11 Computer Science (083) | Computational Thinking and Programming - I |
| CBSE Class 11 Computer Science Essentials (083) | Computational Thinking and Programming - I |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

