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

Sorting Algorithms2

Uploaded by

adi4eu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Sorting Algorithms2

Uploaded by

adi4eu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

SORTING

ALGORITHM
S
What is Sorting Algorithm?
SORTING ALGORITHMS
is used to rearrange a given array or
list of elements according to a
comparison operator on the
elements. The comparison operator
is used to decide the new order of
elements in the respective data
structure.
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 up to the surface,
each element of the array move to the
end in each iteration.
6305
First
Pass:
6305 –> 36
0 5
3 605 –> 30
6 5
3 065 –> 30
5 6
3056
Second
Pass:3 0 5 6 –> 03
56
0356 –> 03
56
0356
Third
Pass:0 3 5 6 –> 03
56
SELECTION
SORT
SELECTION SORT
is a sorting algorithm that selects
the smallest or largest element from
an unsorted list in each iteration
and places that element at the
beginning of the unsorted list.
64 25 12 22 11
First
Pass:
64 25 12 22 11 –> 11 25
12 22 64
Second
Pass:
11 25 12 22 64 –> 11 12
25 22 64
Third
Pass:
11 12 25 22 64 –> 11 12
22 25 64
Fourth
Pass:
11 12 22 25 64 –> 11 12
22 25 64
Fifth
Pass:
11 12 22 25 64 –> 11 12
22 25 64
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.

We assume that the first card is already


sorted then, we select an unsorted card.
12 11 13 5 6
First
Pass:
12 11 13 5 6 –> 11 12 13
5 6
Second
Pass:
11 12 13 5 6 –> 11 12 13
5 6
Third
Pass:
11 12 13 5 6 –> 11 12 5
13 6
11 12 5 13 6 –> 11 5 12
13 6
11 5 12 13 6 –> 5 11 12
13 6
Fourth Pass:
5 11 12 13 6 –> 5 11
12 6 13
5 11 12 6 13 –> 5 11
6 12 13
5 11 6 12 13 –> 5 6
11 12 13
5 6 11 12 13 –> 5 6
11 12 13
QUICK SORT
QUICK SORT
is a sorting algorithm based on the
divide and conquer approach.

An array is divided into subarrays by


selecting a pivot element (element
selected from the array).
MERGE
SORT
MERGE SORT
a sorting algorithm that works by
dividing an array into smaller
subarrays, sorting each subarray,
and then merging the sorted
subarrays back together to form the
final sorted array.
It can sort large arrays relatively
quickly.

Merge sort is a popular choice for


sorting large datasets because it is
relatively efficient and easy to
implement.
SHELL SORT
SHELL SORT
is an in-place comparison sort that is
also known as Shell.

is mainly a variation of Insertion Sort.


In insertion sort, we move elements
only one position ahead. When an
element has to be moved far ahead,
many movements are involved.
HEAP SORT
HEAP SORT
is a comparison-based sorting
technique based on Binary Heap
data structure. It is similar to the
selection sort where we first find the
minimum element and place the
minimum element at the beginning.

You might also like