SlideShare a Scribd company logo
Quick Sort
Jimenez, Jake
Rojas, Davis Jacob
Miguel, Flynce
Quick Sort
 Quicksort uses divide-and-conquer, and so it's a recursive algorithm. The
way that quicksort uses divide-and-conquer is a little different from how
merge sort does. In merge sort, the divide step does hardly anything, and
all the real work happens in the combine step.
 Quicksort is the opposite: all the real work happens in the divide step. In
fact, the combine step in quicksort does absolutely nothing.
Quick Sort
 Here is how quicksort uses divide-and-conquer: think of sorting a sub
array[p…r], Where initially the sub array is array[0…n-1].
We take this set of array as an example:
40 20 10 80 60 50 7 30 100
0 1 2 3 4 5 6 7 8
Quick Sort
 Divide
1. Choose any element in the sub array [p…r] call this element Pivot.
We now have our Pivot which is 40 at array 0
40 20 10 80 60 50 7 30 100
0 1 2 3 4 5 6 7 8
Quick Sort
 Given a pivot, re-arrange the elements of the array such that the resulting array
consists of:
 One sub-array that contains elements >= pivot
 Another sub-array that contains elements < pivot
We call this procedure Partitioning.
Quick Sort
 Given again the array
40 20 10 80 60 50 7 30 100
0 1 2 3 4 5 6 7 8
7 20 10 30 40 50 80 60 100
<= Data [pivot] > Data [pivot]
Quick Sort
 Conquer
After dividing recursively sort each sub array
<= Data [pivot]
7 20 10 30
7 20 10 30
7 20 10 30
7 10 20 30
7 20 10 30
7 10 20 30
7 10 20 30
Quick Sort
 Conquer
After dividing recursively sort each sub array
 > Data [pivot]
50 60 80 100
50 80 60 100
50 80 60 100
50 80 60 100
50 60 80 100
50 80 60 100
50 60 80 100
50 60 80 100
Quick Sort
 Combine
 Once the conquer step recursively sorts, we are done. Why? All elements
to the left of the pivot, in array are less than or equal to the pivot and are
sorted, and all elements to the right of the pivot, in are greater than the
pivot and are sorted.
 The elements can't help but be sorted! So we combine the Left sub array +
Pivot + Right sub array.
 Output of the sorted array:
7 10 20 30 40 50 60 80 100
Quick Sort
 Quick sort Analysis
Scenarios Sorting Algorithm
Worst-Case O(n2)
Best-Case O(n log n)/O(n)
Average-CaseA O(n log n)
Quick Sort
Advantage of Quicksort:
 Efficient average case compared to any sort algorithm
 The elegant recursive definition
 The popularity due to its high efficiency
Quick Sort
Disadvantage of Quicksort
 The difficulty of implementing the partitioning algorithm
 The average efficiency for the worst case scenario, which is not offset by
the difficult implementation
Bubble Sort
Jimenez, Jake
Rojas, Davis Jacob
Miguel, Flynce
Bubble Sort
 The bubble sort makes multiple passes through a list. It compares adjacent items
and exchanges those that are out of order. Each pass through the list places the
next largest value in its proper place. In essence, each item “bubbles” up to the
location where it belongs.
Bubble Sort
 Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping
the adjacent elements if they are in wrong order.
First Pass:
( 5 1 4 2 8 ) –> ( 1 5 4 2 8 )
 Here, algorithm compares the first two elements, and swaps since 5 > 1.
( 1 5 4 2 8 ) –> ( 1 4 5 2 8 )
 Swap since 5 > 4
Bubble Sort
( 1 4 5 2 8 ) –> ( 1 4 2 5 8 )
 Swap since 5 > 2
( 1 4 2 5 8 ) –> ( 1 4 2 5 8 )
 Now, since these elements are already in order (8 > 5), algorithm does not swap
them.
Bubble Sort
 Second Pass:
( 1 4 2 5 8 ) –> ( 1 4 2 5 8 )
( 1 4 2 5 8 ) –> ( 1 2 4 5 8 ), Swap since 4 > 2
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
Bubble Sort
 Now, the array is already sorted, but our algorithm does not know if it is
completed. The algorithm needs one whole pass without any swap to know it is
sorted.
Third Pass:
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
Bubble Sort
 Now, the array is already sorted, but our algorithm does not know if it is
completed. The algorithm needs one whole pass without any swap to know it is
sorted.
Third Pass:
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
Bubble Sort
Advantages of Bubble sort:
 Easy to understand.
 Easy to implement.
 In-place, no external memory is needed.
 Performs greatly when the array is almost sorted.
Bubble Sort
Disadvantages Bubble sort:
 Very expensive, O(n2)O(n2)in worst case and average case.
 It does more element assignments than its counterpart, insertion sort.

More Related Content

PPT
Selection sort
PPTX
Quick sort
PPTX
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPTX
Quick sort
PPTX
heap Sort Algorithm
PPT
Algorithm: Quick-Sort
PPTX
Insertion sort
PPT
Red black tree
Selection sort
Quick sort
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
Quick sort
heap Sort Algorithm
Algorithm: Quick-Sort
Insertion sort
Red black tree

What's hot (20)

PPTX
Searching & Sorting Algorithms
PPTX
Presentation on the topic selection sort
PPTX
Sorting algorithms
PPTX
Ppt bubble sort
PPTX
Quick Sort
PPT
PDF
Singly linked list
PPT
Chapter 11 - Sorting and Searching
PDF
Quick sort algorithn
PPTX
Selection sort
PPTX
Queue
PPTX
deque and it applications
PDF
Binary search algorithm
PPT
Selection sort
PPT
SEARCHING AND SORTING ALGORITHMS
PPTX
Insertion sort
PPTX
Quick sort-Data Structure
PPTX
Quick sort
PPTX
Stacks IN DATA STRUCTURES
PPT
3.3 shell sort
Searching & Sorting Algorithms
Presentation on the topic selection sort
Sorting algorithms
Ppt bubble sort
Quick Sort
Singly linked list
Chapter 11 - Sorting and Searching
Quick sort algorithn
Selection sort
Queue
deque and it applications
Binary search algorithm
Selection sort
SEARCHING AND SORTING ALGORITHMS
Insertion sort
Quick sort-Data Structure
Quick sort
Stacks IN DATA STRUCTURES
3.3 shell sort
Ad

Similar to Analysis of Algorithm (Bubblesort and Quicksort) (20)

PPTX
Sorting Algorithms to arrange data in particular format
PPTX
Different Searching and Sorting Methods.pptx
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
PPTX
sorting algorithm graphical method
PPTX
Unit 5 dsuc
PDF
Sorting Algorithms
DOCX
Sorting
PPTX
Sorting Algorithms
PPTX
Sorting
PPTX
Sorting
PPTX
SORTING techniques.pptx
PPTX
2.Problem Solving Techniques and Data Structures.pptx
PPTX
Weak 11-12 Sorting update.pptxbhjiiuuuuu
PPT
Quicksort
PPTX
Dsa – data structure and algorithms sorting
PDF
Comparative Performance Analysis & Complexity of Different Sorting Algorithm
PPTX
All Searching and Sorting Techniques in Data Structures
PPTX
Sorting-Algorithms-A-Comprehensive-Guide.pptx
PPTX
Sorting types and Algorithms
Sorting Algorithms to arrange data in particular format
Different Searching and Sorting Methods.pptx
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
sorting algorithm graphical method
Unit 5 dsuc
Sorting Algorithms
Sorting
Sorting Algorithms
Sorting
Sorting
SORTING techniques.pptx
2.Problem Solving Techniques and Data Structures.pptx
Weak 11-12 Sorting update.pptxbhjiiuuuuu
Quicksort
Dsa – data structure and algorithms sorting
Comparative Performance Analysis & Complexity of Different Sorting Algorithm
All Searching and Sorting Techniques in Data Structures
Sorting-Algorithms-A-Comprehensive-Guide.pptx
Sorting types and Algorithms
Ad

Recently uploaded (20)

PDF
Complications of Minimal Access Surgery at WLH
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Trump Administration's workforce development strategy
PPTX
Pharma ospi slides which help in ospi learning
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Complications of Minimal Access Surgery at WLH
Final Presentation General Medicine 03-08-2024.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Microbial diseases, their pathogenesis and prophylaxis
Anesthesia in Laparoscopic Surgery in India
GDM (1) (1).pptx small presentation for students
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Trump Administration's workforce development strategy
Pharma ospi slides which help in ospi learning
Supply Chain Operations Speaking Notes -ICLT Program
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Microbial disease of the cardiovascular and lymphatic systems
2.FourierTransform-ShortQuestionswithAnswers.pdf
VCE English Exam - Section C Student Revision Booklet
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Computing-Curriculum for Schools in Ghana
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape

Analysis of Algorithm (Bubblesort and Quicksort)

  • 1. Quick Sort Jimenez, Jake Rojas, Davis Jacob Miguel, Flynce
  • 2. Quick Sort  Quicksort uses divide-and-conquer, and so it's a recursive algorithm. The way that quicksort uses divide-and-conquer is a little different from how merge sort does. In merge sort, the divide step does hardly anything, and all the real work happens in the combine step.  Quicksort is the opposite: all the real work happens in the divide step. In fact, the combine step in quicksort does absolutely nothing.
  • 3. Quick Sort  Here is how quicksort uses divide-and-conquer: think of sorting a sub array[p…r], Where initially the sub array is array[0…n-1]. We take this set of array as an example: 40 20 10 80 60 50 7 30 100 0 1 2 3 4 5 6 7 8
  • 4. Quick Sort  Divide 1. Choose any element in the sub array [p…r] call this element Pivot. We now have our Pivot which is 40 at array 0 40 20 10 80 60 50 7 30 100 0 1 2 3 4 5 6 7 8
  • 5. Quick Sort  Given a pivot, re-arrange the elements of the array such that the resulting array consists of:  One sub-array that contains elements >= pivot  Another sub-array that contains elements < pivot We call this procedure Partitioning.
  • 6. Quick Sort  Given again the array 40 20 10 80 60 50 7 30 100 0 1 2 3 4 5 6 7 8 7 20 10 30 40 50 80 60 100 <= Data [pivot] > Data [pivot]
  • 7. Quick Sort  Conquer After dividing recursively sort each sub array <= Data [pivot] 7 20 10 30 7 20 10 30 7 20 10 30 7 10 20 30 7 20 10 30 7 10 20 30 7 10 20 30
  • 8. Quick Sort  Conquer After dividing recursively sort each sub array  > Data [pivot] 50 60 80 100 50 80 60 100 50 80 60 100 50 80 60 100 50 60 80 100 50 80 60 100 50 60 80 100 50 60 80 100
  • 9. Quick Sort  Combine  Once the conquer step recursively sorts, we are done. Why? All elements to the left of the pivot, in array are less than or equal to the pivot and are sorted, and all elements to the right of the pivot, in are greater than the pivot and are sorted.  The elements can't help but be sorted! So we combine the Left sub array + Pivot + Right sub array.  Output of the sorted array: 7 10 20 30 40 50 60 80 100
  • 10. Quick Sort  Quick sort Analysis Scenarios Sorting Algorithm Worst-Case O(n2) Best-Case O(n log n)/O(n) Average-CaseA O(n log n)
  • 11. Quick Sort Advantage of Quicksort:  Efficient average case compared to any sort algorithm  The elegant recursive definition  The popularity due to its high efficiency
  • 12. Quick Sort Disadvantage of Quicksort  The difficulty of implementing the partitioning algorithm  The average efficiency for the worst case scenario, which is not offset by the difficult implementation
  • 13. Bubble Sort Jimenez, Jake Rojas, Davis Jacob Miguel, Flynce
  • 14. Bubble Sort  The bubble sort makes multiple passes through a list. It compares adjacent items and exchanges those that are out of order. Each pass through the list places the next largest value in its proper place. In essence, each item “bubbles” up to the location where it belongs.
  • 15. Bubble Sort  Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. First Pass: ( 5 1 4 2 8 ) –> ( 1 5 4 2 8 )  Here, algorithm compares the first two elements, and swaps since 5 > 1. ( 1 5 4 2 8 ) –> ( 1 4 5 2 8 )  Swap since 5 > 4
  • 16. Bubble Sort ( 1 4 5 2 8 ) –> ( 1 4 2 5 8 )  Swap since 5 > 2 ( 1 4 2 5 8 ) –> ( 1 4 2 5 8 )  Now, since these elements are already in order (8 > 5), algorithm does not swap them.
  • 17. Bubble Sort  Second Pass: ( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ) ( 1 4 2 5 8 ) –> ( 1 2 4 5 8 ), Swap since 4 > 2 ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
  • 18. Bubble Sort  Now, the array is already sorted, but our algorithm does not know if it is completed. The algorithm needs one whole pass without any swap to know it is sorted. Third Pass: ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
  • 19. Bubble Sort  Now, the array is already sorted, but our algorithm does not know if it is completed. The algorithm needs one whole pass without any swap to know it is sorted. Third Pass: ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
  • 20. Bubble Sort Advantages of Bubble sort:  Easy to understand.  Easy to implement.  In-place, no external memory is needed.  Performs greatly when the array is almost sorted.
  • 21. Bubble Sort Disadvantages Bubble sort:  Very expensive, O(n2)O(n2)in worst case and average case.  It does more element assignments than its counterpart, insertion sort.