Here is the listing of Python programming examples on Searching and Sorting.
1. Python Examples on Searching Algorithms
The Python programs in this section illustrate searching algorithms. Linear search is a method for finding a particular value in a list. It starts searching the value from the beginning of the list and continues till the end of the list until the value is found. Binary search is an algorithm for locating the position of an item in a sorted array. The following python programs implements linear search and binary search algorithms with and without using recursion. It also finds the smallest and largest elements from the list in a expected linear time.
2. Python Examples on Sorting Algorithms
Bubble sort is a sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swaps them if they are in the wrong position. Heapsort is a comparison based sorting algorithm. It is similar to a selection sort algorithm. Selection sort algorithm sort the data by comparing one element to every other element and decides its position. Quick sort is based on an algorithmic design pattern called divide and conquer. It is mainly used for sorting numbers, structure and files. Merge Sort divides the input array into two halves, sorts the two halves and merges the two sorted halves. Insertion Sort algorithm sorts the array by shifting the elements one by one. Gnome sort algorithm sorts the items by comparing the current item with the previous item. For example if they are in order, move to the next item. If they are out of order, swap them and move to the previous item. If there is no previous item, move to the next item. The Python programs in this section demonstrates special sorting algorithms like bubble sort, selection sort, merge sort, quicksort, heap sort, comb sort, shell sort, gnome sort, introsort and bucket sort.
3. Python Examples on Sorting using Binary Trees
The Python programs in this section demonstrate Sorting Algorithm using Binary Trees. Binary Insertion Sort is used to find the correct location to insert new elements. Binary search trees also called sorted binary trees. Binary search trees allow fast lookup, addition and removal of items. The Python programs in this section implements binary insertion sort and soting methods using binary search tree.
Python Program to Implement Binary Insertion Sort
Python Program to Sort using a Binary Search Tree