Dr APJ AbdulKalam UIT Jhabua
Topic :-Sorting Techniques
Submitted by:
Prof. Philip Bhabhore sir
Submitted to:
Hemendra parmar
2.
What is SortingTechniques
Sorting techniques are methods used to arrange data
elements in a particular order, such as ascending or
descending.
These techniques help organize data systematically.
Types :- Bubble,
Selection
Insertion Sort
3.
What is BubbleSort
Bubble sort is a simple sorting algorithm.
This sorting algorithm is comparison-based
algorithm in which each pair of adjacent elements
is compared and the elements are swapped if they
are not in order.
This algorithm is not suitable for large data sets as
its average and worst case complexity are of O(n²).
where n is the number of Items.
4.
How Bubble SortWorks?
We take an unsorted array for our example. Bubble sort
takes O(n²). time so we're keeping it short and precise
Bubble sort starts with very first two elements,
comparing them to check which one is greater
14 33 27 35 10
14 33 27 35 10
5.
In this casevalue 33 is greater than 14, so it is already
in sorted locations. next we compare 33 with 27.
We find that 27 is smaller than 33 and these two values
must be swapped.
The new array should look like this-
14 33 27 35 10
14 27 33 35 10
6.
Next we compare33 and 35 we find that both are in
already sorted positions.
Then we move to the next values 35 and 10.
We know that 10 is smaller than 35, hence they are not
sorted.
14 27 33 35 10
14 27 33 35 10
14 27 33 35 10
7.
We swap thesevalues we find that we have reached the
end after one iteration, the array should look like this-
To be precise we are now showing how an array should
look like after each iteration, after the second iteration ,
it should look like this -
14 27 33 10 35
14 27 10 33 35
8.
Notice that aftereach iteration, at least last one value
moves at the end.
Final Sorted array
14 10 27 33 35
10 14 27 33 35
9.
What is insertionSort
Insertion sort is an in-place, comparison-based
sorting algorithm that maintains a sorted sub-list.
Each new element from the unsorted part is inserted
into its correct position in the sorted part of the same
array.
It is simple but not suitable for large data sets
because its average and worst-case time complexity
is O(n²).
What is SelectionSort
Selection Sort is a simple sorting technique that divides
the list into sorted and unsorted parts. In each step, the
smallest element from the unsorted part is selected and
swapped with the first unsorted element, expanding the
sorted part by one.
This process continues until the entire list is sorted. Its
average and worst-case time complexity is O(n²), so it is
not suitable for large datasets.
17.
How Selection SortWorks?
Unsorted array
Step 1: Find smallest element from all
Smallest is 1 , swap 8 and 1
Sorted part: 1
8 3 5 2 9 1 4
1 3 5 2 9 8 4