HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Programming
  2. /Python Essentials
  3. /Searching and Sorting

Searching and Sorting

Python Programming · High School (9–10) · 1 course, 13 worked problems, 20 practice questions

Finding a name in a list and putting marks in order are two of the most common jobs a program does. Linear search checks each item in turn, and it works on any list. Binary search needs a sorted list. It checks the middle item and throws away half of the list at each step, so it is much faster on long lists. Bubble sort swaps neighbouring items that are out of order, and insertion sort builds a sorted part one item at a time. Python also has sorted() and .sort(). Counting the steps lets you compare algorithms.

With practice you will be able to

  • Write a linear search and a binary search in Python
  • Write a bubble sort and an insertion sort
  • Compare the number of steps two algorithms take on a list

On the syllabus of

  • AP
  • A-Level
  • IGCSE

Lessons

  • Find It and Put It in OrderHow can ten looks find a word in a 1000-page dictionary? How do ties get a rank?High School (9–10)

Practice questions

Choose an answer, then check it. Each one shows a full explanation.

A missing value: the target 9 is not in [4, 7, 1, 8]. How many comparisons does linear search make before it gives up?

Sorting by a key: what does print(sorted(['kiwi', 'fig', 'banana'], key=len)) show?

The first pass of bubble sort on [5, 2, 9, 1]: which value ends in the last place?

Worked problems

Each one has a hint, the key idea and a full worked solution.

  • Write a function first_above(items, limit) that gives the position of the first item that is more…Easy
  • Bubble sort needs n * (n - 1) // 2 comparisons…Medium
  • The marks, already sorted from the highest, are [95, 90, 90, 90, 80, 75, 75]…Medium
  • For fruits = ["apple", "mango", "kiwi", "plum"], find the position of kiwi, and test if fig is in…Easy
  • A linear search looks for 90 in [72, 85, 64, 90, 58]. How many checks does it need?Easy

Python labs

  • Search by hand
  • Search a sorted list
  • Sort the class
  • Count the work
  • Project: a class ranking
  • A race: linear against binary

Related topics

  • Python Essentials
  • Dictionaries
  • Tuples and Sets
  • Errors and Exceptions
  • Modules and Libraries
  • Recursion
  • Text Processing
  • Essentials Projects

A list grows from 1000 to 2000 sorted items. How many more checks, at most, does binary search need?

A linear search looks for 8 in [5, 3, 8]. How many items does it check?

What must be true about a list before you use binary search?

What does print(sorted([3, 1, 2], reverse=True)) show?

What is the largest number of steps that binary search needs for 100 items?

A student uses binary search on [9, 2, 7, 4], which is not in order, and sometimes it misses a value that is there. What is the mistake?

What does print(sorted(["b", "A", "c"])) show?

All 20 practice questions on Searching and Sorting →

A binary search looks for 37 in the numbers from 1 to 100 (in order)…
Medium
  • Sort ["Meera", "asha", "Kabir", "Ravi"]. Why does asha come last, and how do you fix it?Medium
  • Sort ["banana", "fig", "cherry", "kiwi"] by length, shortest first and then longest first.Easy
  • Find the three highest scores in [72, 85, 64, 90, 58, 77].Medium
  • Find the median of [9, 3, 7, 5, 1] by sorting.Medium
  • Do one pass of bubble sort on [5, 2, 9, 1]: compare each pair of neighbours from the left and swap…Medium
  • In selection sort, you find the smallest value and put it first, then the smallest of the rest and…Hard
  • All 13 worked problems on Searching and Sorting →