Professional Documents
Culture Documents
Internal Sorting Techniques & Their Time Complexities
Internal Sorting Techniques & Their Time Complexities
TECHNIQUES &
THEIR6.53TIME
COMPLEXITIES
Aayushi Chowla | A1049519020
INTERNAL SORTING
Any sorting algorithm that uses the main memory
exclusively during the sort is known as an internal
sorting algorithm. The internal sorting technique is
used when data items are less than enough to be held
in the main memory (RAM).
2
TIME COMPLEXITY
Time Complexity is the execution time of an algorithm
which depends on the size of its input.
3
TYPES OF TIME COMPLEXITIES
4
6.53
BUBBLE SORT
Bubble sort is a sorting algorithm that compares two adjacent elements
and swaps them until they are in the intended order.
Just like the movement of air bubbles in the water that rise to the surface,
each element of the array move to the end in each iteration. Therefore, it
is called a bubble sort.
6
Bubble Sort Code in C
7
WORKING OF BUBBLE SORT
Sorted Array
8
BUBBLE SORT COMPLEXITY
10
Selection Sort Code in C
11
WORKING OF SELECTION SORT
12
SELECTION SORT COMPLEXITY
13
INSERTION SORT
Insertion sort is a sorting algorithm that places an unsorted element at its
suitable place in each iteration. Insertion sort works similarly as we sort cards in
our hand in a card game.
14
Insertion Sort Code in C
15
WORKING OF INSERTION SORT
16
INSERTION SORT COMPLEXITY
While dividing the array, the pivot element should be positioned in such a way that elements less
than pivot are kept on the left side and elements greater than pivot are on the right side of the pivot.
• The left and right subarrays are also divided using the same approach. This process continues
until each subarray contains a single element.
• At this point, elements are already sorted. Finally, elements are combined to form a sorted array.
18
QUICK SORT
ALGORITHM
19
Quick Sort Code in C
20
WORKING OF QUICKSORT ALGORITHM
21
WORKING OF QUICKSORT ALGORITHM
Select the pivot element in each half and put it in the correct place using recursion.
22
QUICK SORT COMPLEXITY
24
WORKING OF HEAP SORT
1.Since the tree satisfies Max-Heap property, then the largest item is stored at
the root node.
2.Swap : Remove the root element and put at the end of the array (nth
position) Put the last item of the tree (heap) at the vacant place.
5.The process is repeated until all the items of the list are sorted.
25
Heap Sort Code in C
26
WORKING OF HEAP SORT
WORKING OF HEAP SORT
HEAP SORT COMPLEXITY
29
THANK YOU
30