Category: Python Programming Examples

python tutorials and learn python

Created with Sketch.

Python | Print an Inverted Star Pattern

Python | Print an Inverted Star Pattern Here we are going to print inverted star pattern of desired sizes. Examples: 1) Below is the inverted star pattern of size n=5 (Because there are 5 horizontal lines or rows consist of stars). ***** **** *** ** * 2) Below is the inverted star pattern of size…
Read more

Python Program for Stooge Sort

Python Program for Stooge Sort The Stooge sort is a recursive sorting algorithm. It is defined as below (for ascending order sorting). Step 1 : If value at index 0 is greater than value at last index, swap them. Step 2: Recursively, a) Stooge sort the initial 2/3rd of the array. b) Stooge sort the…
Read more

Python Program for Cycle Sort

Python Program for Cycle Sort Cycle sort is an in-place sorting Algorithm, unstable sorting algorithm, a comparison sort that is theoretically optimal in terms of the total number of writes to the original array. It is optimal in terms of number of memory writes. It minimizes the number of memory writes to sort (Each value…
Read more

Python Program for BogoSort or Permutation Sort

Python Program for BogoSort or Permutation Sort BogoSort also known as permutation sort, stupid sort, slow sort, shotgun sort or monkey sort is a particularly ineffective algorithm based on generate and test paradigm. The algorithm successively generates permutations of its input until it finds one that is sorted.(Wiki) For example, if bogosort is used to…
Read more

Python Program for Odd-Even Sort / Brick Sort

Python Program for Odd-Even Sort / Brick Sort This is basically a variation of bubble-sort. This algorithm is divided into two phases- Odd and Even Phase. The algorithm runs until the array elements are sorted and in each iteration two phases occurs- Odd and Even Phases. In the odd phase, we perform a bubble sort…
Read more

Python Program for Gnome Sort

Python Program for Gnome Sort Algorithm Steps If you are at the start of the array then go to the right element (from arr[0] to arr[1]). If the current array element is larger or equal to the previous array element then go one step right if (arr[i] >= arr[i-1]) i++; If the current array element…
Read more

Python Program for Cocktail Sort

Python Program for Cocktail Sort Cocktail Sort is a variation of Bubble sort. The Bubble sort algorithm always traverses elements from left and moves the largest element to its correct position in first iteration and second largest in second iteration and so on. Cocktail Sort traverses through a given array in both directions alternatively. Algorithm:…
Read more

Python Program for Pigeonhole Sort

Python Program for Pigeonhole Sort Pigeonhole sorting is a sorting algorithm that is suitable for sorting lists of elements where the number of elements and the number of possible key values are approximately the same. It requires O(n + Range) time where n is number of elements in input array and \’Range\’ is number of…
Read more

Python Program for Comb Sort

Python Program for Comb Sort Comb Sort is mainly an improvement over Bubble Sort. Bubble sort always compares adjacent values. So all inversions are removed one by one. Comb Sort improves on Bubble Sort by using gap of size more than 1. The gap starts with a large value and shrinks by a factor of…
Read more

Python Program for Bitonic Sort

Python Program for Bitonic Sort In this blog post, we’ll delve into the concept of Bitonic Sort, a parallel sorting algorithm that performs particularly well on hardware parallel processors. We’ll discuss the Bitonic Sort algorithm, provide a detailed explanation of its working principle, and present a Python implementation of the algorithm. Additionally, we’ll include the…
Read more