Python Program to Implement Heap Sort

Problem Description Write a Python program to implement heap sort and use it to sort a list. What is Heapsort? Heapsort in Python is a sorting algorithm that utilizes a binary heap data structure to efficiently sort elements in an array. Heapsort Example Let’s say we have an unsorted list of numbers: [8, 5, 3, … Read more

advertisement

Python Program to Implement Quicksort

What is Quicksort? Quicksort is a sorting algorithm in Python that uses the divide-and-conquer approach to sort elements by recursively partitioning the array and placing elements in the correct order based on a pivot element. Quicksort Algorithm in python def quicksort(arr): if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x … Read more

advertisement

Python Program to Implement Merge Sort

What is Merge Sort? Merge Sort in Python is a recursive sorting algorithm that divides the input list into smaller halves, sorts them separately, and then merges them back together to produce a sorted list. Problem Description Write a Python program that sorts a list by using merge sort. Merge Sort Algorithm def merge_sort(arr, start, … Read more

advertisement

Python Program to Implement Insertion Sort

What is Insertion Sort? Insertion Sort in Python is basically the insertion of an element from a random set of numbers, to its correct position where it should actually be, by shifting the other elements if required. Problem Description Write a Python program to sort a list by using insertion sort. Insertion Sort Algorithm function … Read more

advertisement

Python Program to Implement Selection Sort

What is Selection Sort? Selection Sort in Python is a sorting algorithm that iterates through a list, finds the minimum element, and swaps it with the current position. This process is repeated until the list is sorted. Problem Description Write a program that sorts a list by implementing selection sort. Selection Sort Algorithm def selection_sort(arr): … Read more

advertisement

Bubble Sort Program in Python

What is Bubble Sort? Bubble Sort in Python is a simple sorting algorithm that repeatedly swaps adjacent elements if they are in the wrong order, gradually moving larger elements towards the end of the list. Problem Description Write a Python program to implement bubble sort. Bubble Sort Algorithm using Python def bubble_sort(lst): n = len(lst) … Read more

advertisement

Python Program to Sort a List of Tuples in Increasing Order by the Last Element in Each Tuple

This is a Python Program to sort a list of tuples in increasing order by the last element in each tuple. Problem Description The program takes a list of tuples and sorts the list of tuples in increasing order by the last element in each tuple. Problem Solution 1. Take a list of tuples from … Read more

advertisement

Python Program to Find the Second Largest Number in a List using Bubble Sort

This is a Python Program to find the second largest number in a list using bubble sort. Problem Description The program takes a list and finds the second largest number in the list using bubble sort. Problem Solution 1. Take in the number of elements for the list and store it in a variable. 2. … Read more

advertisement

Python Program to Sort a List According to the Length of the Elements

This is a Python Program to sort a list according to the length of the elements. Problem Description The program takes a list and sorts the list according to the length of the elements. Problem Solution 1. Take in the number of elements for the first list and store it in a variable. 2. Take … 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.