SlideShare a Scribd company logo
QUICK-SORT
ALGORITHM
By Subhranjali Behera
(MCA, Utkal University)
• Basic Fundamentals
• Introduction to Quick Sort
• Steps to perform Quick Sort
• Algorithm and pseudocode for Quick Sort
• Analysis of Quick Sort
COURSE OUTLINE
• Array is a data structure where all elements are arranged sequentially.
Array
• It is a collection of elements of same data type.
• The base value is index 0
• To access elemnts :
variable_name[ index of element ]
Recursio
n
• The process in which a function calls itself is called recursion.
• Through Recursion, we can reduce the length of our code and make it easier to rea
and write.
• For example factorial of a number.
Suppose 5! = 5*4*3*2*1 which is same as 5*4!
int fact(int n)
{
if (n < = 1) // base case(solution to base case
is provided)
return 1;
else
return n*fact(n-1);
}
INTRODUCTION TO
SORTING
• Sorting is the process of arranging elements of an array in non increasing or
non decreasing order.
• Example of Sorting:
Consider an array of numbers:
A={5, 2, 8, 1, 3}
After sorting in non increasing order:
A={1, 2, 3, 5, 8}
After sorting in non decreasing order:
A={8, 5, 3, 2, 1}
INTRODUCTION TO QUICK SORT ALGORITHM
• QuickSort is fastest sorting algorithm
• It is a divide-and-conquer algorithm that makes it easier to
solve problems.
• It is efficient on large data sets.
DIVIDE AND CONQUER
Consists of the Following 3 Steps:
• Divide: Dividing the Problem Into Smaller Sub-Problems.
• Conquer: Solve Sub-Problems by Calling Recursively.
• Combine: Combine the Sub-Problems to Get the Final Solution of the Whole
Problem.
Steps To perform Quicksort:
Choose a Pivot
• There are no such rules for
choosing a pivot.
Place the pivot in its correct
position.
Partition the elements into two
sections
• Elements <= pivot in left side
• Elements > pivot in right side
Recursively Quicksort the two
halves until down to one element
STEPS OF QUICK SORT
ALGORITHM
ALGORITHM
QuickSort ( arr, low, high )
{
If ( low < high )
{
pivotindex = Partition ( arr, low, high )
QuickSort ( arr, low, pivotindex-1 )
QuickSort ( arr, pivotindex+1, high)
}
}
ALGORITHM
QuickSort ( arr, low, high )
{
If ( low < high )
{
pivotindex = Partition ( arr, low, high )
QuickSort ( arr, low, pivotindex-1 )
QuickSort ( arr, pivotindex+1, high)
}
}
Partition ( arr, low, high )
{
pivot = arr[0];
i = low;
j = high;
while ( i < j )
{
while (arr[ i ] <= pivot && i <= high-1)
{
i++;
}
while (arr[ j ] > pivot && i >= low+1)
{
j--;
}
If (i<j)
swap (arr[ i ], arr[ j ] );
}
swap (arr[ low ], arr[ j ]);
return(j);
}
Case
Time
Complexity
Space
Complexity
Best Case O(n log n) O(log n)
Average Case O(n log n) O(log n)
Worst Case O(n²) O(n)
ANALYSIS OF QUICK SORT ALGORITHM
Thank
You

More Related Content

Similar to Quick-Sort Algorithm and pivot selection (20)

PPTX
Searching searching in in arrays arrays.pptx
Sahar160629
 
PPTX
sorting-160810203705.pptx
VarchasvaTiwari2
 
PPTX
Quick sort
Afaq Mansoor Khan
 
PPT
Searching Sorting-SELECTION ,BUBBBLE.ppt
kunalpatil5661
 
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
kncetaruna
 
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
VISWANATHAN R V
 
PPTX
Algorithms and Data Structures - Parahyangan Catholic University Credit Lionov
Pratik Parmar
 
PPTX
Queues
nidhisatija1
 
PPT
03_sorting123456789454545454545444543.ppt
ssuser7b9bda1
 
PPT
03_sorting and it's types with example .ppt
vanshii9976
 
PPTX
Algorithms and Data Structures for Sorting Numerical Data
Pratik Parmar
 
PDF
Data Structure - Lecture 2 - Recursion Stack Queue.pdf
donotreply20
 
PPT
Presentation on binary search, quick sort, merge sort and problems
Sumita Das
 
PPTX
Parallel Sorting Algorithms. Quicksort. Merge sort. List Ranking
SukhrobAtoev2
 
PPTX
Quick Sort
Shweta Sahu
 
PPT
Designing Algorithms using Divide and Conquer Approach
Zain Ul Abiden
 
PPTX
Algorithm analysis (All in one)
jehan1987
 
PPTX
DS - Quick Sort
MythiliMurugan3
 
PPTX
CS8391-Data Structures Unit 5
SIMONTHOMAS S
 
Searching searching in in arrays arrays.pptx
Sahar160629
 
sorting-160810203705.pptx
VarchasvaTiwari2
 
Quick sort
Afaq Mansoor Khan
 
Searching Sorting-SELECTION ,BUBBBLE.ppt
kunalpatil5661
 
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
kncetaruna
 
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
VISWANATHAN R V
 
Algorithms and Data Structures - Parahyangan Catholic University Credit Lionov
Pratik Parmar
 
Queues
nidhisatija1
 
03_sorting123456789454545454545444543.ppt
ssuser7b9bda1
 
03_sorting and it's types with example .ppt
vanshii9976
 
Algorithms and Data Structures for Sorting Numerical Data
Pratik Parmar
 
Data Structure - Lecture 2 - Recursion Stack Queue.pdf
donotreply20
 
Presentation on binary search, quick sort, merge sort and problems
Sumita Das
 
Parallel Sorting Algorithms. Quicksort. Merge sort. List Ranking
SukhrobAtoev2
 
Quick Sort
Shweta Sahu
 
Designing Algorithms using Divide and Conquer Approach
Zain Ul Abiden
 
Algorithm analysis (All in one)
jehan1987
 
DS - Quick Sort
MythiliMurugan3
 
CS8391-Data Structures Unit 5
SIMONTHOMAS S
 

Recently uploaded (20)

PPTX
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
PPTX
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
PDF
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
PPTX
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
 
PDF
>Wondershare Filmora Crack Free Download 2025
utfefguu
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
PDF
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
PPTX
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
PDF
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
 
PDF
Rewards and Recognition (2).pdf
ethan Talor
 
PPTX
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
PPTX
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
 
PPTX
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
 
>Wondershare Filmora Crack Free Download 2025
utfefguu
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
 
Rewards and Recognition (2).pdf
ethan Talor
 
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
 
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
Ad

Quick-Sort Algorithm and pivot selection

  • 2. • Basic Fundamentals • Introduction to Quick Sort • Steps to perform Quick Sort • Algorithm and pseudocode for Quick Sort • Analysis of Quick Sort COURSE OUTLINE
  • 3. • Array is a data structure where all elements are arranged sequentially. Array • It is a collection of elements of same data type. • The base value is index 0 • To access elemnts : variable_name[ index of element ]
  • 4. Recursio n • The process in which a function calls itself is called recursion. • Through Recursion, we can reduce the length of our code and make it easier to rea and write. • For example factorial of a number. Suppose 5! = 5*4*3*2*1 which is same as 5*4! int fact(int n) { if (n < = 1) // base case(solution to base case is provided) return 1; else return n*fact(n-1); }
  • 5. INTRODUCTION TO SORTING • Sorting is the process of arranging elements of an array in non increasing or non decreasing order. • Example of Sorting: Consider an array of numbers: A={5, 2, 8, 1, 3} After sorting in non increasing order: A={1, 2, 3, 5, 8} After sorting in non decreasing order: A={8, 5, 3, 2, 1}
  • 6. INTRODUCTION TO QUICK SORT ALGORITHM • QuickSort is fastest sorting algorithm • It is a divide-and-conquer algorithm that makes it easier to solve problems. • It is efficient on large data sets.
  • 7. DIVIDE AND CONQUER Consists of the Following 3 Steps: • Divide: Dividing the Problem Into Smaller Sub-Problems. • Conquer: Solve Sub-Problems by Calling Recursively. • Combine: Combine the Sub-Problems to Get the Final Solution of the Whole Problem.
  • 8. Steps To perform Quicksort: Choose a Pivot • There are no such rules for choosing a pivot. Place the pivot in its correct position. Partition the elements into two sections • Elements <= pivot in left side • Elements > pivot in right side Recursively Quicksort the two halves until down to one element STEPS OF QUICK SORT ALGORITHM
  • 9. ALGORITHM QuickSort ( arr, low, high ) { If ( low < high ) { pivotindex = Partition ( arr, low, high ) QuickSort ( arr, low, pivotindex-1 ) QuickSort ( arr, pivotindex+1, high) } }
  • 10. ALGORITHM QuickSort ( arr, low, high ) { If ( low < high ) { pivotindex = Partition ( arr, low, high ) QuickSort ( arr, low, pivotindex-1 ) QuickSort ( arr, pivotindex+1, high) } } Partition ( arr, low, high ) { pivot = arr[0]; i = low; j = high; while ( i < j ) { while (arr[ i ] <= pivot && i <= high-1) { i++; } while (arr[ j ] > pivot && i >= low+1) { j--; } If (i<j) swap (arr[ i ], arr[ j ] ); } swap (arr[ low ], arr[ j ]); return(j); }
  • 11. Case Time Complexity Space Complexity Best Case O(n log n) O(log n) Average Case O(n log n) O(log n) Worst Case O(n²) O(n) ANALYSIS OF QUICK SORT ALGORITHM