SlideShare a Scribd company logo
Quick sort
Introduction to Quick sort
Definition:
Quick Sort is a divide-and-conquer sorting algorithm that rearranges elements in
a list based on a pivot.
Popular for its efficiency in average-case scenarios.
History:
Invented by Tony Hoare in 1960.
 Based on the idea of partitioning and recursion
Why Quick sort
Advantages:
Efficient: Performs faster than many other sorting algorithms for large datasets.
In-Place: Requires minimal extra memory.
Adaptability: Works well with arrays and linked lists.
Applications:
 Used in system libraries like Python’s sorted() and Java’s Arrays.sort() for
primitives.
Key features
Partitioning: Divides the array into smaller segments around a pivot.
Recursion: Solves smaller subproblems until the array is sorted.
 Dynamic: Adaptable to random datasets but relies on good pivot selection.
How to Quick sort work
Choose a Pivot: Select an element (e.g., first, last, random, or median).
Partition: Rearrange the array:
All elements smaller than pivot Left.
→
All elements larger than pivot Right.
→
 Recursively Sort: Apply Quick Sort to the left and right partitions.
Example step by step
Input Array: [10, 80, 30, 90, 40, 50, 70]
Choose Pivot: 50.
Partition: Rearrange elements around pivot.
Result: [10, 30, 40, 50, 90, 80, 70].
 Recursive Steps: Repeat for subarrays [10, 30, 40] and [90, 80, 70].
Pivot selection techniques
First Element: Simple but risks poor performance for sorted arrays.
Last Element: Similar risk to the first element.
Random Element: Reduces chances of worst-case scenarios.
 Median-of-Three: Selects the median of the first, middle, and last elements
for better balance.
Time complexity analysis
Case Explanation Time Complexity
Best Case Balanced partitions Recursive depth log(n).
→ O(n log n)
Average Case Random data, balanced partitions on average. O(n log n)
Worst Case Pivot divides array into 1 and (n-1).O(n²)
 Key Insight: Good pivot selection minimizes chances of worst-case
performance.
Space complexity
Recursive Stack:
Depth of recursion depends on partitioning.
Best case: O(log n) (balanced recursion).
Worst case: O(n) (unbalanced recursion).
In-Place Sorting: No additional memory required beyond recursion stack.
Advantages and Disadvantages
Advantages:
Faster than other O(n log n) algorithms like merge sort for small datasets.
Minimal memory overhead.
Highly efficient for randomly distributed data.
Disadvantages:
Poor pivot selection can lead to O(n²) performance.
 Recursion may cause stack overflow for large datasets.
Conclusion
Key Takeaways:
Quick Sort is a powerful sorting algorithm combining speed and simplicity.
Pivot selection is critical for efficiency.
Ideal for general-purpose use but consider alternatives for specialized cases.
Closing Thought:
 Mastering Quick Sort provides a foundation for understanding more complex
algorithms.
Thank you
 P
.Jyothi
 22D21A0547
 CSE-A

More Related Content

PPT
s4_quick_sort.ppt
PPTX
Quick sort
PDF
Class13_Quicksort_Algorithm.pdf
PPTX
Quick sort.pptx
PPT
quicksort (1).ppt
PPT
quick_sort_with_explanationandImplmentation.ppt
PPTX
Quicksort Algorithm..simply defined through animations..!!
PPTX
09 QUICK SORT Design and Analysis of algorithms
s4_quick_sort.ppt
Quick sort
Class13_Quicksort_Algorithm.pdf
Quick sort.pptx
quicksort (1).ppt
quick_sort_with_explanationandImplmentation.ppt
Quicksort Algorithm..simply defined through animations..!!
09 QUICK SORT Design and Analysis of algorithms

Similar to jyothi(22D21A0547)DAA.pptx in DAA computer (20)

PPTX
Quick-Sort Algorithm and pivot selection
PPT
Quick sort Algorithm Discussion And Analysis
PPT
Quick Sort
PPTX
Complexity of algorithms
PPTX
quick sort by deepak.pptx
PPTX
Quick sort
PPTX
Divide-and-conquer
PPTX
CSE680-07QuickSort.pptx
PPTX
Quick sort by Sania Nisar
PDF
Quick Sort By Prof Lili Saghafi
PPTX
QUICK SORT_DAA.pptx
PPTX
quick and merge.pptx
PPTX
Sorting Algorithm
PPT
QuickSort.pptdfsjdfhjkhfjkhjkhjkhjkhjkhjkhjkhjkhjkjk
DOCX
Quick sort
PPTX
Sorting
PPT
PPS
Quick sort
PPTX
Quick sort
PPTX
Quick sort algorithm
Quick-Sort Algorithm and pivot selection
Quick sort Algorithm Discussion And Analysis
Quick Sort
Complexity of algorithms
quick sort by deepak.pptx
Quick sort
Divide-and-conquer
CSE680-07QuickSort.pptx
Quick sort by Sania Nisar
Quick Sort By Prof Lili Saghafi
QUICK SORT_DAA.pptx
quick and merge.pptx
Sorting Algorithm
QuickSort.pptdfsjdfhjkhfjkhjkhjkhjkhjkhjkhjkhjkhjkjk
Quick sort
Sorting
Quick sort
Quick sort
Quick sort algorithm
Ad

Recently uploaded (20)

PDF
Design Guidelines and solutions for Plastics parts
PPTX
communication and presentation skills 01
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
737-MAX_SRG.pdf student reference guides
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
Feature types and data preprocessing steps
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PPT
Occupational Health and Safety Management System
PPTX
Module 8- Technological and Communication Skills.pptx
PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPTX
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
Abrasive, erosive and cavitation wear.pdf
PPT
Total quality management ppt for engineering students
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Design Guidelines and solutions for Plastics parts
communication and presentation skills 01
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
737-MAX_SRG.pdf student reference guides
III.4.1.2_The_Space_Environment.p pdffdf
Fundamentals of Mechanical Engineering.pptx
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Feature types and data preprocessing steps
Categorization of Factors Affecting Classification Algorithms Selection
Occupational Health and Safety Management System
Module 8- Technological and Communication Skills.pptx
"Array and Linked List in Data Structures with Types, Operations, Implementat...
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
Abrasive, erosive and cavitation wear.pdf
Total quality management ppt for engineering students
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Ad

jyothi(22D21A0547)DAA.pptx in DAA computer

  • 2. Introduction to Quick sort Definition: Quick Sort is a divide-and-conquer sorting algorithm that rearranges elements in a list based on a pivot. Popular for its efficiency in average-case scenarios. History: Invented by Tony Hoare in 1960.  Based on the idea of partitioning and recursion
  • 3. Why Quick sort Advantages: Efficient: Performs faster than many other sorting algorithms for large datasets. In-Place: Requires minimal extra memory. Adaptability: Works well with arrays and linked lists. Applications:  Used in system libraries like Python’s sorted() and Java’s Arrays.sort() for primitives.
  • 4. Key features Partitioning: Divides the array into smaller segments around a pivot. Recursion: Solves smaller subproblems until the array is sorted.  Dynamic: Adaptable to random datasets but relies on good pivot selection.
  • 5. How to Quick sort work Choose a Pivot: Select an element (e.g., first, last, random, or median). Partition: Rearrange the array: All elements smaller than pivot Left. → All elements larger than pivot Right. →  Recursively Sort: Apply Quick Sort to the left and right partitions.
  • 6. Example step by step Input Array: [10, 80, 30, 90, 40, 50, 70] Choose Pivot: 50. Partition: Rearrange elements around pivot. Result: [10, 30, 40, 50, 90, 80, 70].  Recursive Steps: Repeat for subarrays [10, 30, 40] and [90, 80, 70].
  • 7. Pivot selection techniques First Element: Simple but risks poor performance for sorted arrays. Last Element: Similar risk to the first element. Random Element: Reduces chances of worst-case scenarios.  Median-of-Three: Selects the median of the first, middle, and last elements for better balance.
  • 8. Time complexity analysis Case Explanation Time Complexity Best Case Balanced partitions Recursive depth log(n). → O(n log n) Average Case Random data, balanced partitions on average. O(n log n) Worst Case Pivot divides array into 1 and (n-1).O(n²)  Key Insight: Good pivot selection minimizes chances of worst-case performance.
  • 9. Space complexity Recursive Stack: Depth of recursion depends on partitioning. Best case: O(log n) (balanced recursion). Worst case: O(n) (unbalanced recursion). In-Place Sorting: No additional memory required beyond recursion stack.
  • 10. Advantages and Disadvantages Advantages: Faster than other O(n log n) algorithms like merge sort for small datasets. Minimal memory overhead. Highly efficient for randomly distributed data. Disadvantages: Poor pivot selection can lead to O(n²) performance.  Recursion may cause stack overflow for large datasets.
  • 11. Conclusion Key Takeaways: Quick Sort is a powerful sorting algorithm combining speed and simplicity. Pivot selection is critical for efficiency. Ideal for general-purpose use but consider alternatives for specialized cases. Closing Thought:  Mastering Quick Sort provides a foundation for understanding more complex algorithms.
  • 12. Thank you  P .Jyothi  22D21A0547  CSE-A