# Sorting

Two elements of complex data types are not directly comparable. Consider the student structure defined as below struct Student { int rollNo; char name[25]; char grade; }; Student arr[MAX_NUM_STUDENTS]; Objects of Student type are not directly comparable. To sort array arr, we need to specify how one student compares with another student. If there are […]

We discussed Insertion sort in detail earlier. This post shows the recursive implementation of Insertion Sort.

Given a number N given in the form of array, with each index storing one digit of the number. Write code to change the number to the greatest number less than N, such that digits of that number are in non-decreasing order. For example: INPUT ARRAY: {1, 4, 3} (representing number 143) OUTPUT : 139 […]

This video describes Bubble Sort Algorithm and its optimizations.

This video describes selection sort algorithm:

Selection sort is an in-place, comparison sorting algorithm. Like bubble sortÂ it also divides the given array in two sub arrays sorted and unsorted, divided by an imaginary wall. Initially all the elements will be in the unsorted list. Each pass will pick the smallest element from the unsorted list and add it at the end […]

What is Bubble Sort. Write algorithm of mention the Time & Space complexity of the Algorithm. Also suggest improvements which will improve the best case running time of Algorithm to O(n). Solution: Bubble Sort is a sorting algorithm which compares two adjacent elements and swap them if they are not in the right order. To […]

Which sorting algorithm makes minimum number of memory write ?

Which sorting algorithm will you use to sort 1 billion numbers.

Given a linked list, with all the nodes in sorted order. Write a function that inserts a new integer in the sorted manner. i.e If the list is as given below: 3 -> 6 -> 9 -> 10 -> 15 And if you want to insert 8 in this list, it should be inserted as […]