Dr APJ Abdul Kalam UIT Jhabua
Topic :-Sorting Techniques
Submitted by:
Prof. Philip Bhabhore sir
Submitted to:
Hemendra parmar
What is Sorting Techniques
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
What is Bubble Sort
 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.
How Bubble Sort Works?
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
In this case value 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
Next we compare 33 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
We swap these values 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
Notice that after each iteration, at least last one value
moves at the end.
Final Sorted array
14 10 27 33 35
10 14 27 33 35
What is insertion Sort
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²).
How Insertion Sort Works?
Unsorted array
Step 1: Compare 8 and 3
Sorted part: 3 8
8 3 5 2 9 1 4
3 8 5 2 9 1 4
Step 2: Compare 8 and 5
Sorted part: 3 5 8
 Step 3: Compare 8 and 2
Compare 5 and 2
8 3 5 2 9 1 4
3 5 8 2 9 1 4
8 3 5 2 9 1 4
3 5 2 8 9 1 4
8 3 5 2 9 1 4
3 2 5 8 9 1 4
Compare 3 and 2
Sorted part: 2 3 5 8
 Step 4: Compare 8 and 9
Sorted part: 2 3 5 8 9
8 3 5 2 9 1 4
2 3 5 8 9 1 4
8 3 5 2 9 1 4
2 3 5 8 9 1 4
Step 5: Compare 9 and 1
Compare 8 and 1
Compare 5 and 1
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
2 3 5 1 8 9 4
8 3 5 2 9 1 4
2 3 1 5 8 9 4
Compare 3 and 1
Compare 2 and 1
Sorted part: 1 2 3 5 8 9 4
Step 6: Compare 9 and 4
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
2 3 5 1 8 9 4
8 3 5 2 9 1 4
2 1 3 5 8 9 4
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
1 2 3 5 8 9 4
8 3 5 2 9 1 4
2 3 5 1 8 9 4
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
1 2 3 5 8 4 9
Compare 8 and 4
Compare 5 and 4
Final Sorted Array :
1 2 3 4 5 8 9
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
2 3 5 1 8 9 4
8 3 5 2 9 1 4
2 1 3 5 8 9 4
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
1 2 3 4 5 8 9
8 3 5 2 9 1 4
2 3 5 1 8 9 4
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
1 2 3 5 4 8 9
What is Selection Sort
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.
How Selection Sort Works?
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
Step 2: find smallest element from all
Smallest is 1, swap 3 and 2
Sorted part: 1 2
Step 3: find smallest element from all
Smallest is 3, swap 5 and 3
Sorted part: 1 2 3
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
2 1 3 5 8 9 4
8 3 5 2 9 1 4
2 3 5 1 8 9 4
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
1 2 5 3 9 8 4
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
2 1 3 5 8 9 4
8 3 5 2 9 1 4
2 3 5 1 8 9 4
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
1 2 3 5 9 8 4
Step 4: find smallest element from all
Smallest is 4, swap 5 and 4
Sorted part: 1 2 3 4
Step 5: find smallest element from all
Smallest is 5, swap 9 and 5
Final Sorted part: 1 2 3 4 5 8 9
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
2 1 3 5 8 9 4
8 3 5 2 9 1 4
2 3 5 1 8 9 4
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
1 2 3 4 9 8 5
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
2 1 3 5 8 9 4
8 3 5 2 9 1 4
2 3 5 1 8 9 4
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
1 2 3 5 9 8 4
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
2 1 3 5 8 9 4
8 3 5 2 9 1 4
2 3 5 1 8 9 4
8 3 5 2 9 1 4
2 3 5 8 1 9 4
8 3 5 2 9 1 4
1 2 3 4 5 8 9
Thanks you

DSA.PPasdf sdm,fndsm,fnsdfnsdkmfasT.pptx

  • 1.
    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²).
  • 10.
    How Insertion SortWorks? Unsorted array Step 1: Compare 8 and 3 Sorted part: 3 8 8 3 5 2 9 1 4 3 8 5 2 9 1 4
  • 11.
    Step 2: Compare8 and 5 Sorted part: 3 5 8  Step 3: Compare 8 and 2 Compare 5 and 2 8 3 5 2 9 1 4 3 5 8 2 9 1 4 8 3 5 2 9 1 4 3 5 2 8 9 1 4 8 3 5 2 9 1 4 3 2 5 8 9 1 4
  • 12.
    Compare 3 and2 Sorted part: 2 3 5 8  Step 4: Compare 8 and 9 Sorted part: 2 3 5 8 9 8 3 5 2 9 1 4 2 3 5 8 9 1 4 8 3 5 2 9 1 4 2 3 5 8 9 1 4
  • 13.
    Step 5: Compare9 and 1 Compare 8 and 1 Compare 5 and 1 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 2 3 5 1 8 9 4 8 3 5 2 9 1 4 2 3 1 5 8 9 4
  • 14.
    Compare 3 and1 Compare 2 and 1 Sorted part: 1 2 3 5 8 9 4 Step 6: Compare 9 and 4 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 2 3 5 1 8 9 4 8 3 5 2 9 1 4 2 1 3 5 8 9 4 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 1 2 3 5 8 9 4 8 3 5 2 9 1 4 2 3 5 1 8 9 4 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 1 2 3 5 8 4 9
  • 15.
    Compare 8 and4 Compare 5 and 4 Final Sorted Array : 1 2 3 4 5 8 9 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 2 3 5 1 8 9 4 8 3 5 2 9 1 4 2 1 3 5 8 9 4 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 1 2 3 4 5 8 9 8 3 5 2 9 1 4 2 3 5 1 8 9 4 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 1 2 3 5 4 8 9
  • 16.
    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
  • 18.
    Step 2: findsmallest element from all Smallest is 1, swap 3 and 2 Sorted part: 1 2 Step 3: find smallest element from all Smallest is 3, swap 5 and 3 Sorted part: 1 2 3 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 2 1 3 5 8 9 4 8 3 5 2 9 1 4 2 3 5 1 8 9 4 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 1 2 5 3 9 8 4 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 2 1 3 5 8 9 4 8 3 5 2 9 1 4 2 3 5 1 8 9 4 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 1 2 3 5 9 8 4
  • 19.
    Step 4: findsmallest element from all Smallest is 4, swap 5 and 4 Sorted part: 1 2 3 4 Step 5: find smallest element from all Smallest is 5, swap 9 and 5 Final Sorted part: 1 2 3 4 5 8 9 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 2 1 3 5 8 9 4 8 3 5 2 9 1 4 2 3 5 1 8 9 4 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 1 2 3 4 9 8 5 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 2 1 3 5 8 9 4 8 3 5 2 9 1 4 2 3 5 1 8 9 4 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 1 2 3 5 9 8 4 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 2 1 3 5 8 9 4 8 3 5 2 9 1 4 2 3 5 1 8 9 4 8 3 5 2 9 1 4 2 3 5 8 1 9 4 8 3 5 2 9 1 4 1 2 3 4 5 8 9
  • 20.