Algorithms · Python Programs
Algorithm programs show how to solve a problem efficiently. Each page explains the idea, walks through a worked example, gives runnable code with output and notes on the running time.
All 5
Python Program for Linear Search (with Examples)
Linear search checks every item of a list from left to right and returns the index of the first match, or `-1` if the target is n…
Python Binary Search Program (Iterative and Recursive)Binary search finds a value in a **sorted** list by repeatedly comparing the target with the middle item and discarding the half …
Python Bubble Sort Program (with Explanation)Bubble sort sorts a list by repeatedly comparing neighbouring items and swapping them when they are in the wrong order, so the la…
Python Selection Sort Program (with Explanation)Selection sort sorts a list by repeatedly finding the smallest remaining item and swapping it into the next position at the front…
Python Tower of Hanoi Program (Recursion Explained)The Tower of Hanoi puzzle is solved in Python with a short recursive function: move n − 1 disks to the spare peg, move the bigges…
Explore more
Python ReferencePython ComparisonsPython How-To GuidesPython Cheat SheetsPython glossaryPython tutorial