Searching and Sorting in Python

Python Programming Examples - Searching & Sorting

Searching algorithms are used to locate an element or retrieve it from a data structure. These algorithms are divided into two categories based on the type of search operation, namely sequential search (Linear Search) and interval search (Binary Search). Sorting is the process of arranging data in a specific format. Sorting algorithms specify how to sort data in a specific order such as numerical order (ascending or descending order) or lexical order.

The following section contains Python programs on searching, linear search, and binary search. It also includes Python programs that demonstrate sorting algorithms such as bubble sort, selection sort, insertion sort, quick sort, merge sort, heap sort, bucket sort, counting, and radix sort. Each sample program includes a program description, Python code, and program output. All examples have been compiled and tested on Windows and Linux systems.

Here is the listing of Python programming examples on Searching & Sorting:

  1. Searching Algorithms in Python
  2. Sorting Algorithms in Python
  3. Python Programs on Sorting using Trees

1. Searching Algorithms in Python

Program Description
Linear Search in Python Python Program to Implement Linear Search
Binary Search using Recursion in Python Python Program to Perform Binary Search using Recursion
Binary Search without Recursion in Python Python Program to Perform Binary Search without Recursion
Find ith Smallest Element from List in Linear Time in Python Python Program to Find ith Smallest Element from List in Linear Time
Find ith Largest Element from List in Linear Time in Python Python Program to Find ith Largest Element from List in Linear Time
Maximum Subarray Problem using Divide & Conquer in Python Python Program to Solve Maximum Subarray Problem using Divide and Conquer
Maximum Subarray Problem using Kadane’s Algorithm in Python Python Program to Solve Maximum Subarray Problem using Kadane’s Algorithm

advertisement
advertisement

2. Sorting Algorithms in Python

Program Description
Insertion Sort in Python Python Program to Implement Insertion Sort
Selection Sort in Python Python Program to Implement Selection Sort
Bubble Sort in Python Python Program to Implement Bubble Sort
Merge Sort in Python Python Program to Implement Merge Sort
Quick sort in Python Python Program to Implement Quick Sort
Shell Sort Algorithm in Python Python Program to Implement Shell Sort Algorithm
Heap sort in Python Python Program to Implement Heap Sort
Introsort in Python Python Program to Implement Introsort
CockTail Sort in Python Python Program to Implement CockTail Sort
Comb Sort in Python Python Program to Implement Comb Sort
Gnome Sort in Python Python Program to Implement Gnome Sort
Radix Sort in Python Python Program to Implement Radix Sort
Counting Sort in Python Python Program to Implement Counting Sort
Bucket Sort in Python Python Program to Implement Bucket Sort
Find Second Element using Bubble Sort in Python Python Program to Find the Second Largest Number in a List using Bubble Sort
Sort List by Elements Length in Python Python Program to Sort a List According to the Length of the Elements

3. Python Programs on Sorting using Trees

Program Description
Binary Insertion Sort in Python Python Program to Implement Binary Insertion Sort
Sort List of Tuples by Last Element in Python Python Program to Sort a List of Tuples in Increasing Order by the Last Element in Each Tuple
Sort using BST in Python Python Program to Sort using a Binary Search Tree
DFS Traversal using Post Order in Python Python Program to Implement Depth First Search Traversal using Post Order

advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.