SlideShare a Scribd company logo
Quick sort
•Internal sorting technique
•It is also called partitioning sort which
uses divide and conquer technique
Working principle
• The quick sort works by partitioning the array
A[1],A[2],…A[n] by picking some value in the
array as a pivot element.
• Pivot element is used to rearrange the
elements in the array
• Pivot can be the first element of an array and
the rest of the elements are moved so that the
elements on left side of the pivot are lesser
than the pivot
• Whereas those on the right side are greater
than the pivot
• Now the pivot element is placed in its correct
position
• Now the quick sort procedure is applied for
left array and right array in a recursive
manner.
Steps to implement quick sort
• The value of i is incremented till a[i]<= Pivot
• The value of j is decremented till a[j]> Pivot
• This process is repeated until i<j
If a[i]> pivot and a[j]<pivot and also if i<j then
swap a[i] and a[j]
If i>j then swap a[j] and a[pivot]
#include<stdio.h>
void quicksort(int number[25],int first,int last)
{
int i, j, pivot, temp;
if(first<last)
{
pivot=first;
i=first;
j=last;
while(i<j)
{
while(number[i]<=number[pivot]&&i<last)
i++;
while(number[j]>number[pivot])
j--;
if(i<j)
{
temp=number[i];
number[i]=number[j];
number[j]=temp;
}
}
temp=number[pivot];
number[pivot]=number[j];
number[j]=temp;
quicksort(number,first,j-1);
quicksort(number,j+1,last);
}
}
void main()
{
int i, count, number[25];
printf("How many elements are u going to
enter?: ");
scanf("%d",&count);
printf("Enter %d elements: ", count);
for(i=0;i<count;i++)
scanf("%d",&number[i]);
quicksort(number,0,count-1);
printf("Order of Sorted elements: ");
for(i=0;i<count;i++)
printf(" %d",number[i]);
}
example
Sort the following values using Quick Sort and
estimate its time and space complexity:
65 70 75 80 85 60 55 50 45
Analysis of quick sort
• Worst case analysis = O[N2 ]
• Best case analysis = O[N log N]
• Average case analysis = O[N log N]
advantages
• Faster than other O(N log N)
• Better cache performance & high speed
DS - Quick Sort
disadvantages
• Requires more memory space

More Related Content

PPTX
Quick sort
ODP
Quick sort
DOCX
MODULE 5-Searching and-sorting
PPTX
Modal & Harmonic Response Analysis
PDF
Quick sort
PPTX
Sorting elements increasing order
PPTX
Analysis of algorithm
PPTX
Work Measurment
Quick sort
Quick sort
MODULE 5-Searching and-sorting
Modal & Harmonic Response Analysis
Quick sort
Sorting elements increasing order
Analysis of algorithm
Work Measurment

Similar to DS - Quick Sort (20)

PPTX
Unit 2 - Quick Sort.pptx
PPT
quicksort (1).ppt
PPT
quick_sort_with_explanationandImplmentation.ppt
PPTX
Quick Sort algorithm for sorting an array of elements
PPTX
quick sort by deepak.pptx
DOCX
Quick sort
PPTX
Quick sort
PPTX
Quick sort by Sania Nisar
PPT
s4_quick_sort.ppt
PPTX
Quick sort.pptx
PPTX
Sorting
DOCX
Quick sort
PDF
Heap, quick and merge sort
PPTX
PPTX
CSE680-07QuickSort.pptx
PDF
Sorting Algorithms and their implementations
PPTX
Quick sort
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
PPTX
jyothi(22D21A0547)DAA.pptx in DAA computer
Unit 2 - Quick Sort.pptx
quicksort (1).ppt
quick_sort_with_explanationandImplmentation.ppt
Quick Sort algorithm for sorting an array of elements
quick sort by deepak.pptx
Quick sort
Quick sort
Quick sort by Sania Nisar
s4_quick_sort.ppt
Quick sort.pptx
Sorting
Quick sort
Heap, quick and merge sort
CSE680-07QuickSort.pptx
Sorting Algorithms and their implementations
Quick sort
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
jyothi(22D21A0547)DAA.pptx in DAA computer
Ad

More from MythiliMurugan3 (9)

PPTX
DS - Graph Traversal
PPTX
DS- Stack ADT
PPTX
DS - BST
PPTX
DS - Application of List
PPTX
DBMS - Relational Algebra
PPTX
DBMS - Distributed Databases
PPTX
DBMS - RAID
PPTX
DBMS - Transactions
PPTX
DBMS - ER Model
DS - Graph Traversal
DS- Stack ADT
DS - BST
DS - Application of List
DBMS - Relational Algebra
DBMS - Distributed Databases
DBMS - RAID
DBMS - Transactions
DBMS - ER Model
Ad

Recently uploaded (20)

PPTX
communication and presentation skills 01
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
PPT on Performance Review to get promotions
PDF
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
737-MAX_SRG.pdf student reference guides
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PDF
Visual Aids for Exploratory Data Analysis.pdf
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Artificial Intelligence
PPTX
UNIT 4 Total Quality Management .pptx
communication and presentation skills 01
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
Fundamentals of safety and accident prevention -final (1).pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PPT on Performance Review to get promotions
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
Fundamentals of Mechanical Engineering.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
737-MAX_SRG.pdf student reference guides
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Visual Aids for Exploratory Data Analysis.pdf
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Artificial Intelligence
UNIT 4 Total Quality Management .pptx

DS - Quick Sort