Python Program to Sort using a Binary Search Tree

This is a Python program to sort using a binary search tree. Problem Description The program sorts a list using a binary search tree. Problem Solution 1. Create a class BSTNode with instance variables key, left, right and parent. 2. Define methods insert and inorder in BSTNode. 3. The method insert takes a node as … Read more

advertisement

Python Program to Implement Binary Insertion Sort

This is a Python program to implement binary insertion sort. Problem Description The program sorts a list by binary insertion sort. Problem Solution 1. Create a function binary insertion_sort that takes a list as argument. 2. Inside the function create a loop with a loop variable i that counts from 1 to the length of … Read more

advertisement

Python Program to Implement Introsort

This is a Python program to implement introsort. Problem Description The program sorts a list by introsort. Problem Solution 1. Create a function introsort that takes a list argument. 2. In the function, an appropriate value for maxdepth is chosen. Here maxdepth is chosen equal to 2 times floor of log base 2 of the … Read more

advertisement

Python Program to Implement Shell Sort Algorithm

This is a Python program to implement shell sort. Problem Description The program sorts a list by shell sort. Problem Solution 1. Create a generator gaps that takes the size of the list as argument and returns the next element in the sequence of gaps on each successive call. Here the gap sequence chosen is … Read more

advertisement

Python Program to Implement Comb Sort

This is a Python program to implement comb sort. Problem Description The program sorts a list by comb sort. Problem Solution 1. Create a function comb_sort that takes a list as argument. 2. Set gap equal to the length of the list. 3. Choose an appropriate shrink factor. Here shrink = 1.3. 4. Create a … Read more

advertisement

Python Program to Implement CockTail Sort

This is a Python program to implement cocktail shaker sort. Problem Description The program sorts a list by cocktail shaker sort. Problem Solution 1. Create a function cocktail_shaker_sort that takes a list as argument. 2. Set upper to length of the list – 1 and lower to 0. 3. Create a loop inside which bubble … Read more

advertisement

Python Program to Implement Gnome Sort

This is a Python program to implement gnome sort. Problem Description The program sorts a list by gnome sort. Problem Solution 1. Create a function gnome_sort that takes a list as argument. 2. Inside the function create a loop with loop variable pos that iterates from 1 to the length of the list – 1. … Read more

advertisement

Python Program to Implement Bucket Sort

This is a Python program to implement bucket sort. Problem Description The program sorts a list by bucket sort. Problem Solution 1. Create a function bucket_sort that takes a list as argument. 2. Inside the function set largest to the maximum element in the list and set length equal to the length of the list. … Read more

advertisement

Python Program to Implement Radix Sort

This is a Python program to implement radix sort. Problem Description The program sorts a list by radix sort. Problem Solution 1. Create a function radix_sort that takes a list and a variable base as arguments. 2. Create an inner function key_factory that takes two variables digit and base as arguments and returns a function. … Read more

advertisement

Python Program to Implement Counting Sort

Problem Description Write a Python program that implements counting sort to sort a given list. What is Counting Sort? Counting Sort is a linear sorting algorithm that sorts a list of integers by counting the number of occurrences of each element and using that information to determine their correct positions in the sorted sequence. How … Read more

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
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.