0% found this document useful (0 votes)
1 views14 pages

Sorting Algorithm

The document provides an overview of sorting algorithms and their types, including Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort, and Heap Sort. It explains the concept of arrays and the process of sorting elements in ascending or descending order. Each sorting algorithm is briefly described with examples illustrating their operation.

Uploaded by

Krishna Aggarwal
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)
1 views14 pages

Sorting Algorithm

The document provides an overview of sorting algorithms and their types, including Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort, and Heap Sort. It explains the concept of arrays and the process of sorting elements in ascending or descending order. Each sorting algorithm is briefly described with examples illustrating their operation.

Uploaded by

Krishna Aggarwal
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/ 14

Sorting

Algorithm
PRESENTED
BY Krishna
Garg
Array
• An array is a collection of similar data items stored
together in one place. .

9 3 8 1

• It stores multiple values of the same type (like


numbers or characters), and each item can be
accessed using its position number, called an index.
Introduction of Sorting
• Sorting is the method to arrange an elements of array
in a particular order either ascending or descending
index : 0 1 order
2 . 3
--
9 3 8 1 Unsorted List

Sorted List
1 3 8 9
Accending
Order
Types of Sorting

Algorithm:-
Bubble Sort

• Selection Sort

• Insertion Sort

• Merge Sort

• Quick Sort

• Heap Sort
Bubble Sort :-
• Bubble Sort is a technique in which we compare two

adjacent elements and swap them if they are in the

wrong order. 0 1 2 3
9 3 8 1

• This process continues in multiple rounds until the list

is sorted.
9 3 8 1

PASS Number Of Passes =


3
Max – 1 = 4 – 1 =

1
Step 9 3 8 O 1, 1
1
Step 3 9 8 1 1, 2
2
Step 3 8 9 2 1, 3
3
3 8 1 9
PASS
no need to
2 :-
Step swap O 9, 1
3 8 1
1
Step 3 8 1 1 9, 2
2
3 1 8 9
PASS
3 :-
Step 3 1 8 O 9, 1
1

1 3 8 9 Sorted list
Selection Sort
• This sorting algorithm is an in-place comparison-based
algorithm.

• In which the list is divided into two parts, the sorted


part at the left end and the unsorted part at the right
end.

• Initially, the sorted part is empty and the unsorted


part is the entire list.
0 1 2 3 4
ORIGINAL
4 1 5 2 3
ARRAY
PASS 4 1 5 2 Min
3 = Swap 1 with
1 1 4
unsorted
array
PASS 1 4 5 2 Min
3 = Swap 2 with
2 unsorted 2 4
array
PASS 1 2 5 4 Min
3 = Swap 3 with
3 5
3 unsorted
array
PASS Min = ( Already Correct
1 2 3 4 5
4 )
4 unsorted
array
1 2 3 4 5Sorted list
Insertion Sort
• Insertion Sort is a simple sorting technique. It works just
like how you arrange playing cards in your hand – picking
one card at a time and placing it in the correct position.
ORIGINAL 23 1 10 5 2
ARRAY
PASS 23 1 10 5 2 1 23 10 5 2
1

PASS 2 1 23 10 5 2 1 10 23 5 2

1 10 23 5 2 1 10 5 23 2
PASS 3

1 5 10 23 2

PASS 4 1 5 10 23 2 1 5 10 2 23

1 5 2 10 23 1 2 5 10 23

Sorte
Merge Sort
• Merge Sort is a divide and
conquer algorithm.

• It divides the array into halves,


sorts them, and then merges the
sorted halves.

You might also like