SlideShare une entreprise Scribd logo
1  sur  57
QUICK SORT
Algoritma Pengurutan
SIMULASI QUICKSORT
RESULT
SIMULASI ALGORITMA QUICKSORT
QuickSORT(Array, indexawal, indexakhir)
indexawal

indexakhir
data

QuickSORT(data, 1,5)
QuickSORT(data, 1, 5)
indexawal

indexakhir
data

STEP 1

IF(indexawal < indexakhir)
See Code
Indexhigher
pivot

While index lower < index higher
Indexlower

Cek Lower
Cek Higher
If(indexlower < index higher)
Swap

Swap
QuickSORT(data,
indexawal,
indexhigher-1)
QuickSORT(data,
indexawal,
indexhigher+1)
Indexhigher
pivot

Indexlower

While index lower < index higher
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Higher
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Higher
Indexhigher
pivot

Indexlower

While index lower < index higher

If(indexlower < index higher)
Swap
Indexhigher
pivot

Indexlower

While index lower < index higher

If(indexlower < index higher)
Swap
Indexhigher
pivot

Indexlower

While index lower < index higher
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Higher
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Higher
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Higher
Indexhigher
pivot

Indexlower

While index lower < index higher

Cek Higher
Indexhigher
pivot

Indexlower

While index lower < index higher

If(indexlower < index higher)
Swap
Indexhigher
pivot

Indexlower

Swap
Indexhigher
pivot

Indexlower

Swap
Indexhigher
pivot

Indexlower

Quicksorting(1,2)

Quicksorting(4,5)
Indexhigher
pivot

Indexlower

Quicksorting(1,2)
While index lower < index higher
Indexhigher
pivot

Indexlower

Quicksorting(1,2)
While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

Quicksorting(1,2)
While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

Quicksorting(1,2)
While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

Quicksorting(1,2)
While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

Quicksorting(1,2)
While index lower < index higher

Cek Higher
Indexhigher
pivot

Indexlower

Quicksorting(1,2)
While index lower < index higher

Cek Higher
Indexhigher
pivot

Indexlower

Quicksorting(1,2)
While index lower < index higher

Cek Higher
Indexhigher
pivot

Indexlower

Quicksorting(1,2)
If(indexlower < index higher)
While index lower < index higher

Swap
Indexhigher

pivot

Indexlower

Quicksorting(1,2)
Swap
pivot

Indexhigher

Indexlower

Quicksorting(1,2)
Quicksorting(1,0)

Quicksorting(2,2)
Indexhigher
pivot

Indexlower

Quicksorting(4,5)
While index lower < index higher
Indexhigher
pivot

Indexlower

Quicksorting(4,5)
While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

Quicksorting(4,5)
While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

Quicksorting(4,5)
While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

Quicksorting(4,5)
While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

Quicksorting(4,5)
While index lower < index higher

Cek Lower
Indexhigher
pivot

Indexlower

Quicksorting(4,5)
While index lower < index higher

Cek Higher
Indexhigher
pivot

Indexlower

Quicksorting(1,2)
While index lower < index higher

Cek Higher
Indexhigher
pivot

Indexlower

Quicksorting(4,5)
If(indexlower < index higher)
While index lower < index higher

Swap
Indexhigher

pivot

Indexlower

Quicksorting(1,2)
Swap
Indexhigher

pivot

Indexlower

Quicksorting(4,5)
Quicksorting(4,4)

Quicksorting(6,5)
RESULT
TERIMAKASIH
C Code for QuickSORT
void quicksort(int arr[max],int arrawal,int arrakhir){
int pivot,indexhigher,temp,indexlower;
if(arrawal<arrakhir){
pivot = arrawal;
indexlower = arrawal;
indexhigher = arrakhir;
while(indexlower<indexhigher){
while((arr[indexlower]<=arr[pivot])&&(indexlower<arrakhir)){
indexlower++;
}
while(arr[indexhigher]>arr[pivot]&&(indexhigher>arrawal)){
indexhigher--;
}
if(indexlower<indexhigher){
swap(arr,indexlower,indexhigher);
}
}
swap(arr,pivot,indexhigher);
quicksort(arr,arrawal,indexhigher-1);
quicksort(arr,indexhigher+1,arrakhir);
}
}//end
Swap code
void swap (int a[max], int left, int right){
int temp;
temp=a[left];
a[left]=a[right];
a[right]=temp;
}//end swap
Cek Lower

If(data[indexlower] <= data[pivot] && indexlower < indexakhir )
Indexlower = indexlower + 1
Cek Higher

If(data[indexhigher] > data[pivot])
Indexhigher = indexhigher + 1

Contenu connexe

Plus de amalianuryamin (8)

Arkom : DDR 3
Arkom : DDR 3Arkom : DDR 3
Arkom : DDR 3
 
Catatan Islam : cloning
Catatan Islam :  cloningCatatan Islam :  cloning
Catatan Islam : cloning
 
DDP : Menampilkan Output Tanggal Hari Besok Berdasarkan Input Tanggal Hari Ini
DDP : Menampilkan Output Tanggal Hari Besok Berdasarkan Input Tanggal Hari IniDDP : Menampilkan Output Tanggal Hari Besok Berdasarkan Input Tanggal Hari Ini
DDP : Menampilkan Output Tanggal Hari Besok Berdasarkan Input Tanggal Hari Ini
 
Pengenalan Sistem Informasi : Dinas kesehatan provinsi
Pengenalan Sistem Informasi : Dinas kesehatan provinsiPengenalan Sistem Informasi : Dinas kesehatan provinsi
Pengenalan Sistem Informasi : Dinas kesehatan provinsi
 
Pengenalan sistem informasi : Sistem Informasi Perdagangan
Pengenalan sistem informasi : Sistem Informasi PerdaganganPengenalan sistem informasi : Sistem Informasi Perdagangan
Pengenalan sistem informasi : Sistem Informasi Perdagangan
 
RPL : Incremental model
RPL : Incremental modelRPL : Incremental model
RPL : Incremental model
 
Basis Data : Pemodelan Erd
Basis Data : Pemodelan ErdBasis Data : Pemodelan Erd
Basis Data : Pemodelan Erd
 
Hanoi tower
Hanoi towerHanoi tower
Hanoi tower
 

Dernier

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Dernier (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

Alpro : Quick sort