Category: Python Programming Examples

python tutorials and learn python

Created with Sketch.

Python Program for Binary Insertion Sort

Python Program for Binary Insertion Sort We can use binary search to reduce the number of comparisons in normal insertion sort. Binary Insertion Sort find use binary search to find the proper location to insert the selected item at each iteration.

Python Program for Radix Sort

Python Program for Radix Sort The Radix Sort Algorithm 1) Do following for each digit i where i varies from least significant digit to the most significant digit. ………….a) Sort input array using counting sort (or any stable sort) according to the i\’th digit. Python # Python program for implementation of Radix Sort   #…
Read more

Python Program for Topological Sorting

Python Program for Topological Sorting Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v in the ordering.

Python Program for ShellSort

Python Program for ShellSort In shellSort, we make the array h-sorted for a large value of h. We keep reducing the value of h until it becomes 1. An array is said to be h-sorted if all sublists of every h\’th element is sorted. # Python program for implementation of Shell Sort   def shellSort(arr):…
Read more

Python Program for Counting Sort

Python Program for Counting Sort Counting sort is a sorting technique based on keys between a specific range.

Python Program for Heap Sort

Python Program for Heap Sort Heap sort is a comparison based sorting technique based on Binary Heap data structure. It is similar to selection sort where we first find the maximum element and place the maximum element at the end. We repeat the same process for remaining element. # Python program for implementation of heap…
Read more

Python Program for Iterative Merge Sort

Python Program for Iterative Merge Sort Following is a typical recursive implementation of Merge Sort that uses last element as pivot. Python # Recursive Python Program for merge sort def merge(left, right):     if not len(left) or not len(right):         return left or right     result = []     i, j = 0, 0     while (len(result) < len(left) +…
Read more

Python Program for Merge Sort

Python Program for Merge Sort Merge Sort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves.

Python Program for Bubble Sort

Python Program for Bubble Sort Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. Python # Python program for implementation of Bubble Sort def bubbleSort(arr):     n = len(arr)     # Traverse through all array elements     for i in range(n):         # Last i elements are…
Read more

Python Program for Selection Sort

Python Program for Selection Sort The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order)