0% found this document useful (0 votes)
17 views

Sorting Algorithms: Farrukh Zeshan Ahmad

The document discusses four sorting algorithms: insertion sort, merge sort, selection sort, and heap sort. It provides pseudocode for insertion sort, which sorts elements in place by comparing adjacent elements and swapping them if out of order. Merge sort is also described as having a time complexity of O(n log n) and being fast for large data sets due to its sequential data access. The algorithms are compared in a table noting their time complexities and best use cases.

Uploaded by

AliImran
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Sorting Algorithms: Farrukh Zeshan Ahmad

The document discusses four sorting algorithms: insertion sort, merge sort, selection sort, and heap sort. It provides pseudocode for insertion sort, which sorts elements in place by comparing adjacent elements and swapping them if out of order. Merge sort is also described as having a time complexity of O(n log n) and being fast for large data sets due to its sequential data access. The algorithms are compared in a table noting their time complexities and best use cases.

Uploaded by

AliImran
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Sorting Algorithms

Farrukh Zeshan Ahmad

Insertion Sort

Insertion Sort
void insertion_sort (int arr[], int length)
{
int j, temp;
for (int i = i; i < length; i++)
{
j = i;
while (j > 0 && arr[j] < arr[j-1])
{
temp = arr[j];
arr[j] = arr[j-1];
arr[j-1] = temp; j--;
}
}
}
Insertion sort sorts the elements in place

Merg Sort

FIGURE 10-32 Mergesort algorithm

Merg Sort

Merg Sort

Algorithm
selection-sort
insertion-sort
heap-sort
merge-sort

Time

Notes

O(n2)

slow
in-place
for small data sets (< 1K)

O(n2)

slow
in-place
for small data sets (< 1K)

O(n log n)

fast
in-place
for large data sets (1K 1M)

O(n log n)

fast
sequential data access
for huge data sets (> 1M)

You might also like