Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 30

INTERNAL SORTING

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.​

The efficiency of an algorithm also depends upon


the nature and size of the input.

3
TYPES OF TIME COMPLEXITIES

Best Time Complexity: Average Time Worst Time


 Define the input for Complexity: Complexity: Define the
which algorithm takes In the average case take input for which
less time or minimum all random inputs and algorithm takes a long
time. In the best case we calculate the time or maximum time.
calculate the lower computation time for all In the worst case we
bound of an algorithm. inputs. calculate the upper
And then we divide it by bound of an algorithm.
the total number of
inputs.

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.

BUBBLE SORT ALGORITHM

6
Bubble Sort Code in C

7
WORKING OF BUBBLE SORT​

Sorted Array

Compare the Adjacent


Elements
Put the Largest Element at
the end
Compare the Adjacent
Elements

8
BUBBLE SORT COMPLEXITY

Pitch deck title 9


SELECTION SORT
Selection sort is a sorting algorithm that selects the smallest element from an
unsorted list in each iteration and places that element at the beginning of the
unsorted list.

SELECTION SORT ALGORITHM

10
Selection Sort Code in C

11
WORKING OF SELECTION SORT

The fourth Iteration

The Third Iteration

The second iteration

The first Iteration​

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.

INSERTION SORT ALGORITHM

14
Insertion Sort Code in C

15
WORKING OF INSERTION SORT

If the first element is


greater than key, then
key is placed in front Place 1 at the Place 4 behind 1
of the first element. beginning
Place 3 behind 1 and
the array is sorted

16
INSERTION SORT COMPLEXITY

Pitch deck title 17


QUICK SORT 
Quicksort is a sorting algorithm based on the divide and conquer approach were
• An array is divided into subarrays by selecting a pivot element (element selected from the array).

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

Select a pivot element

Put all the smaller elements on the left


and greater on the right of pivot element

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

Pitch deck title 23


HEAP SORT ALGORITHM
•Heap Sort is a popular and efficient sorting algorithm in
computer programming. Learning how to write the heap sort
algorithm requires knowledge of two types of data structures
- arrays and trees.

•The initial set of numbers that we want to sort is stored in


an array e.g. [10, 3, 76, 34, 23, 32] and after sorting, we get a
sorted array [3,10,23,32,34,76].

•Heap sort works by visualizing the elements of the array as


a special kind of complete binary tree called a heap.

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.

3.Remove : Reduce the size of the heap by 1.

4.Heapify : Heapify the root element again so that we have the highest


element at the root.

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

You might also like