SlideShare une entreprise Scribd logo
1  sur  26
Adam Mukharil Bachtiar
English Class
Informatics Engineering 2011
Algorithms and Programming
Searching
Steps of the Day
Let’s Start
Definition of
Searching
Sequential
Search
Binary
Search
Definition of Searching
All About Searching
WhatisSearching
Process that search the value in group of data.
This process can produce FOUND or NOT
FOUND value.
AlgorithmsofSorting
• Sequential search / Linear search
• Binary search
Sequential Search
Definition and Structures of Sequential Search
WhatisSequentialSearch
• Trace group of data one by one.
• Start the process from the first data.
• If the data was found in group then stop
the searching but if not, search until the
last data in grup.
MethodsinSequentialSearch
• Without boolean
 Without sentinel
 Use sentinel
• Use boolean
Ilustration of Seq. Search Without Sentinel
Given an array to be processed:
Number
Data that want to be sought : 9
• Number[1] = 9?
• Number[2] = 9?
• Number[3] = 9?
Result: 9 is found in number[3]
5 1 9 4 2
[1] [2] [3] [4] [5]
i  i + 1
i  i + 1
i (STOP SEARCH)
Sequential Search Without Sentinel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Procedure SeqSearchTanpaSentinel (Input nama_array:tipe_array)
{I.S. : elemen array [1..maks_array] sudah terdefinisi}
{F.S. : menampilkan hasil pencarian (ditemukan/tidak)}
Kamus:
i : integer
data_cari : tipedata
Algoritma:
input(data_cari)
i  1
while(nama_array [i] ≠ data_cari) and (i < maks_array) do
i  i + 1
endwhile
if (nama_array[i] = data_cari)
then
output(data_cari,’ ditemukan pada indeks ke-’,i)
else
output(data_cari,’ tidak ditemukan’)
endif
EndProcedure
SequentialSearchUseSentinel
• Place the data that want to be sought in
sentinel.
• Sentinel is additional index that was placed in
max array + 1.
• If the data is found in sentinel that means the
result is data is not found and vice versa.
Ilustration of Seq. Search Use Sentinel
Data that was sought: 9
Number
Result: Data was found in Number[3]
Data that was sought: 10
Number
Result: Data was not found
5 1 9 4 2 9
[1] [2] [3] [4] [5] [6]
sentinel
5 1 9 4 2 10
[1] [2] [3] [4] [5] [6]
sentinel
Sequential Search Use Sentinel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Procedure SeqSearchSentinel (Input nama_array:tipe_array)
{I.S. : elemen array [1..maks_array] sudah terdefinisi}
{F.S. : menampilkan hasil pencarian (ditemukan/tidak)}
Kamus:
i : integer
data_cari : tipedata
Algoritma:
input(data_cari)
i  1
nama_array(maks_array + 1)  data_cari
while (nama_array [i] ≠ data_cari) do
i  i + 1
endwhile
if (i < maks_array+1)
then
output(data_cari,’ ditemukan pada indeks ke-’,i)
else
output(data_cari,’ tidak ditemukan’)
endif
EndProcedure
SequentialSearchUseBoolean
• Its searching process is similar with another
sequential search method.
• Involves one boolean variable.
Ilustration of Seq. Search Use Boolean
Given an array to be processed:
Number
Data that want to be sought : 9
• Number[1] = 9?
• Number[2] = 9?
• Number[3] = 9?
Result: 9 is found in number[3]
5 1 9 4 2
[1] [2] [3] [4] [5]
FOUND  FALSE
FOUND  FALSE
FOUND  TRUE (STOP SEARCH)
Sequential Search Use Sentinel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Procedure SeqSearchBoolean (Input nama_array:tipe_array)
{I.S. : elemen array [1..maks_array] sudah terdefinisi}
{F.S. : menampilkan data yg dicari ditemukan atau tidak ditemukan}
Kamus:
i : integer
ketemu : boolean
data_cari : tipedata
Algoritma:
input(data_cari)
i  1
ketemu  false
while (not ketemu) and (i ≤ maks_array) do
if(nama_var_array(i) = data_cari)
then
ketemu  true
else
i  i + 1
endif
endwhile
if (ketemu)
then
output(data_cari,’ ditemukan pada indeks ke-’,i)
else
output(data_cari,’ tidak ditemukan’)
endif
EndProcedure
Binary Search
Definition and Structures of Binary Search
WhatisBinarySearch
• Searching algorithm that divide group of data into
two parts (left and right).
• First, check data in the middle. If same with the
data that was sought then data is found. If not then
continue searching process to left or right (based
on condition).
• Group of data must be sorted before the searching
process.
Data that was sought: 7
Number
Result: ?
CaseExampleofBinarySearch
3 7 12 15 29
[1] [2] [3] [4] [5]
Case Example of Binary Search
Data that was sought: 7
Number
Result: ?
3 7 12 15 29
[1] [2] [3] [4] [5]
Case Example of Binary Search
Step 1 : Divide array into 2 parts. Count the middle
position (k) of array to start searching
k = (Ia + Ib) div 2
= (1 + 5) div 2
= 3
la : lower bound (for index)
lb : upper bound (for index)
3 7 12 15 29
[1] [2] [3] [4] [5]
Ia k Ib
Left Side Right Side
Case Example of Binary Search
Step 2 :
• check data in k. If it’s same with data that was sought then
stop search and data is found.
• If it’s not then check whether data was bigger or smaller than
data in k.
• If it’s bigger one then continue searching to right side and la
= k+1. if it’s smaller one then continue searching to the left
side and lb = k-1 (data wa sorted in ascending way).
3 7
1 2
Ia Ib
Case Example of Binary Search
Step 3 : repeat step 1 until step 2 until data is found or until
la>lb then stop searching.
Result : 7 is found in Number[2] and in the third looping.
3 7
1 2
Ia Ib
k
Left Side Right Side
Binary Search
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Procedure BinarySearch (Input nama_array : tipe_array)
{I.S. : elemen array yang terurut secara ascending sudah terdefinisi}
{F.S. : menampilkan data yg dicari ditemukan atau tidak ditemukan}
Kamus:
Ia, Ib, k : integer
ketemu : boolean
data_cari : tipedata
Algoritma:
input(data_cari)
Ia  1
Ib  maks_array
ketemu  false
while (not ketemu) and (Ia ≤ Ib) do
k  (Ia + Ib) div 2
if (nama_var_array[k] = data_cari)
then
ketemu  true
else
if (nama_var_array[k] < data_cari)
then
Ia  k + 1
else
Ib  k – 1
endif
endif
endwhile
Binary Search
27
28
29
30
31
32
33
if (ketemu)
then
output(data_cari,’ ditemukan pada indeks ke-’,k)
else
output(data_cari,’ tidak ditemukan’)
endif
EndProcedure
Contact Person:
Adam Mukharil Bachtiar
Informatics Engineering UNIKOM
Jalan Dipati Ukur Nomor. 112-114 Bandung 40132
Email: adfbipotter@gmail.com
Blog: http://adfbipotter.wordpress.com
Copyright © Adam Mukharil Bachtiar 2011

Contenu connexe

Tendances

Binary Search pada Java
Binary Search pada JavaBinary Search pada Java
Binary Search pada JavaPutra Andry
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
Context Free Grammar (CFG) Bagian 2 - Materi 7 - TBO
Context Free Grammar (CFG) Bagian 2 - Materi 7 - TBOContext Free Grammar (CFG) Bagian 2 - Materi 7 - TBO
Context Free Grammar (CFG) Bagian 2 - Materi 7 - TBOahmad haidaroh
 
Binary search in ds
Binary search in dsBinary search in ds
Binary search in dschauhankapil
 
Analisis Algoritma - Pengantar Analisis Algoritma
Analisis Algoritma - Pengantar Analisis AlgoritmaAnalisis Algoritma - Pengantar Analisis Algoritma
Analisis Algoritma - Pengantar Analisis AlgoritmaAdam Mukharil Bachtiar
 
Demonstrate interpolation search
Demonstrate interpolation searchDemonstrate interpolation search
Demonstrate interpolation searchmanojmanoj218596
 
B+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletionB+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletionHAMID-50
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear searchmontazur420
 
Rahat &amp; juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhithRj Juhith
 
Modul praktikum 11 hashing table
Modul praktikum 11 hashing tableModul praktikum 11 hashing table
Modul praktikum 11 hashing tablerahmi wahyuni
 
CFG dan PARSING - P 5 - Teknik Kompilasi
CFG dan PARSING - P 5 - Teknik KompilasiCFG dan PARSING - P 5 - Teknik Kompilasi
CFG dan PARSING - P 5 - Teknik Kompilasiahmad haidaroh
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IMohamed Loey
 
Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]Muhammad Hammad Waseem
 
Analisis Algoritma - Kelas-kelas Dasar Efisiensi Algoritma
Analisis Algoritma - Kelas-kelas Dasar Efisiensi AlgoritmaAnalisis Algoritma - Kelas-kelas Dasar Efisiensi Algoritma
Analisis Algoritma - Kelas-kelas Dasar Efisiensi AlgoritmaAdam Mukharil Bachtiar
 
5. Doubly Linked List (Struktur Data)
5. Doubly Linked List (Struktur Data)5. Doubly Linked List (Struktur Data)
5. Doubly Linked List (Struktur Data)Kelinci Coklat
 

Tendances (20)

Binary Search pada Java
Binary Search pada JavaBinary Search pada Java
Binary Search pada Java
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Context Free Grammar (CFG) Bagian 2 - Materi 7 - TBO
Context Free Grammar (CFG) Bagian 2 - Materi 7 - TBOContext Free Grammar (CFG) Bagian 2 - Materi 7 - TBO
Context Free Grammar (CFG) Bagian 2 - Materi 7 - TBO
 
Binary search in ds
Binary search in dsBinary search in ds
Binary search in ds
 
Analisis Algoritma - Pengantar Analisis Algoritma
Analisis Algoritma - Pengantar Analisis AlgoritmaAnalisis Algoritma - Pengantar Analisis Algoritma
Analisis Algoritma - Pengantar Analisis Algoritma
 
Demonstrate interpolation search
Demonstrate interpolation searchDemonstrate interpolation search
Demonstrate interpolation search
 
B+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletionB+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletion
 
Shell sort
Shell sortShell sort
Shell sort
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
 
Quick Sort
Quick SortQuick Sort
Quick Sort
 
Rahat &amp; juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhith
 
Modul praktikum 11 hashing table
Modul praktikum 11 hashing tableModul praktikum 11 hashing table
Modul praktikum 11 hashing table
 
CFG dan PARSING - P 5 - Teknik Kompilasi
CFG dan PARSING - P 5 - Teknik KompilasiCFG dan PARSING - P 5 - Teknik Kompilasi
CFG dan PARSING - P 5 - Teknik Kompilasi
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
 
String operation
String operationString operation
String operation
 
Heapsort ppt
Heapsort pptHeapsort ppt
Heapsort ppt
 
AVL Tree Data Structure
AVL Tree Data StructureAVL Tree Data Structure
AVL Tree Data Structure
 
Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]
 
Analisis Algoritma - Kelas-kelas Dasar Efisiensi Algoritma
Analisis Algoritma - Kelas-kelas Dasar Efisiensi AlgoritmaAnalisis Algoritma - Kelas-kelas Dasar Efisiensi Algoritma
Analisis Algoritma - Kelas-kelas Dasar Efisiensi Algoritma
 
5. Doubly Linked List (Struktur Data)
5. Doubly Linked List (Struktur Data)5. Doubly Linked List (Struktur Data)
5. Doubly Linked List (Struktur Data)
 

En vedette

Algorithm and Programming (Branching Structure)
Algorithm and Programming (Branching Structure)Algorithm and Programming (Branching Structure)
Algorithm and Programming (Branching Structure)Adam Mukharil Bachtiar
 
Algorithm and Programming (Sequential Structure)
Algorithm and Programming (Sequential Structure)Algorithm and Programming (Sequential Structure)
Algorithm and Programming (Sequential Structure)Adam Mukharil Bachtiar
 
Data Management (Data Mining Klasifikasi)
Data Management (Data Mining Klasifikasi)Data Management (Data Mining Klasifikasi)
Data Management (Data Mining Klasifikasi)Adam Mukharil Bachtiar
 
Algorithm and Programming (Introduction of Algorithms)
Algorithm and Programming (Introduction of Algorithms)Algorithm and Programming (Introduction of Algorithms)
Algorithm and Programming (Introduction of Algorithms)Adam Mukharil Bachtiar
 
Algorithm and Programming (Looping Structure)
Algorithm and Programming (Looping Structure)Algorithm and Programming (Looping Structure)
Algorithm and Programming (Looping Structure)Adam Mukharil Bachtiar
 
Präsentation linkedin
Präsentation linkedinPräsentation linkedin
Präsentation linkedinDieter Stempel
 
Destrucció hàbitats - 1r ESO LS Manlleu 2016
Destrucció hàbitats - 1r ESO LS Manlleu 2016Destrucció hàbitats - 1r ESO LS Manlleu 2016
Destrucció hàbitats - 1r ESO LS Manlleu 2016Annapujolo
 
Presentationryanair 140224071313-phpapp02
Presentationryanair 140224071313-phpapp02Presentationryanair 140224071313-phpapp02
Presentationryanair 140224071313-phpapp02Magda Elswesy
 
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...Adam Mukharil Bachtiar
 
El llop 1r ESO La Salle Manlleu 2016
El llop 1r ESO La Salle Manlleu 2016El llop 1r ESO La Salle Manlleu 2016
El llop 1r ESO La Salle Manlleu 2016Annapujolo
 
L'afebliment de la capa d'ozó - 1r ESO LS Manlleu 2016
L'afebliment de la capa d'ozó - 1r ESO LS Manlleu 2016L'afebliment de la capa d'ozó - 1r ESO LS Manlleu 2016
L'afebliment de la capa d'ozó - 1r ESO LS Manlleu 2016Annapujolo
 
Repayment Advisor I - Phoenix, AZ
Repayment Advisor I - Phoenix, AZRepayment Advisor I - Phoenix, AZ
Repayment Advisor I - Phoenix, AZAngelene Green
 
Introduction to Quantum Computing & Quantum Information Theory
Introduction to Quantum Computing & Quantum Information TheoryIntroduction to Quantum Computing & Quantum Information Theory
Introduction to Quantum Computing & Quantum Information TheoryRahul Mee
 
Migrating IBM Cloud Orchestrator environment from v2.4.0.2 to v2.5.0.1
Migrating IBM Cloud Orchestrator environment from v2.4.0.2 to v2.5.0.1Migrating IBM Cloud Orchestrator environment from v2.4.0.2 to v2.5.0.1
Migrating IBM Cloud Orchestrator environment from v2.4.0.2 to v2.5.0.1Paulraj Pappaiah
 
ĐÁNH GIÁ KẾT QUẢ VÁ NHĨ BẰNG KỸ THUẬT ĐẶT MẢNH GHÉP TRÊN-DƯỚI LỚP SỢI
ĐÁNH GIÁ KẾT QUẢ VÁ NHĨ BẰNG KỸ THUẬT ĐẶT MẢNH GHÉP TRÊN-DƯỚI LỚP SỢIĐÁNH GIÁ KẾT QUẢ VÁ NHĨ BẰNG KỸ THUẬT ĐẶT MẢNH GHÉP TRÊN-DƯỚI LỚP SỢI
ĐÁNH GIÁ KẾT QUẢ VÁ NHĨ BẰNG KỸ THUẬT ĐẶT MẢNH GHÉP TRÊN-DƯỚI LỚP SỢILuanvanyhoc.com-Zalo 0927.007.596
 

En vedette (20)

Algorithm and Programming (Branching Structure)
Algorithm and Programming (Branching Structure)Algorithm and Programming (Branching Structure)
Algorithm and Programming (Branching Structure)
 
Algorithm and Programming (Sequential Structure)
Algorithm and Programming (Sequential Structure)Algorithm and Programming (Sequential Structure)
Algorithm and Programming (Sequential Structure)
 
Data Management (Data Mining Klasifikasi)
Data Management (Data Mining Klasifikasi)Data Management (Data Mining Klasifikasi)
Data Management (Data Mining Klasifikasi)
 
Algorithm and Programming (Record)
Algorithm and Programming (Record)Algorithm and Programming (Record)
Algorithm and Programming (Record)
 
Algorithm and Programming (Sorting)
Algorithm and Programming (Sorting)Algorithm and Programming (Sorting)
Algorithm and Programming (Sorting)
 
Algorithm and Programming (Array)
Algorithm and Programming (Array)Algorithm and Programming (Array)
Algorithm and Programming (Array)
 
Algorithm and Programming (Introduction of Algorithms)
Algorithm and Programming (Introduction of Algorithms)Algorithm and Programming (Introduction of Algorithms)
Algorithm and Programming (Introduction of Algorithms)
 
Ibm quantum computing
Ibm quantum computingIbm quantum computing
Ibm quantum computing
 
Algorithm and Programming (Looping Structure)
Algorithm and Programming (Looping Structure)Algorithm and Programming (Looping Structure)
Algorithm and Programming (Looping Structure)
 
Präsentation linkedin
Präsentation linkedinPräsentation linkedin
Präsentation linkedin
 
Destrucció hàbitats - 1r ESO LS Manlleu 2016
Destrucció hàbitats - 1r ESO LS Manlleu 2016Destrucció hàbitats - 1r ESO LS Manlleu 2016
Destrucció hàbitats - 1r ESO LS Manlleu 2016
 
Presentationryanair 140224071313-phpapp02
Presentationryanair 140224071313-phpapp02Presentationryanair 140224071313-phpapp02
Presentationryanair 140224071313-phpapp02
 
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
 
El llop 1r ESO La Salle Manlleu 2016
El llop 1r ESO La Salle Manlleu 2016El llop 1r ESO La Salle Manlleu 2016
El llop 1r ESO La Salle Manlleu 2016
 
L'afebliment de la capa d'ozó - 1r ESO LS Manlleu 2016
L'afebliment de la capa d'ozó - 1r ESO LS Manlleu 2016L'afebliment de la capa d'ozó - 1r ESO LS Manlleu 2016
L'afebliment de la capa d'ozó - 1r ESO LS Manlleu 2016
 
Repayment Advisor I - Phoenix, AZ
Repayment Advisor I - Phoenix, AZRepayment Advisor I - Phoenix, AZ
Repayment Advisor I - Phoenix, AZ
 
Introduction to Quantum Computing & Quantum Information Theory
Introduction to Quantum Computing & Quantum Information TheoryIntroduction to Quantum Computing & Quantum Information Theory
Introduction to Quantum Computing & Quantum Information Theory
 
Migrating IBM Cloud Orchestrator environment from v2.4.0.2 to v2.5.0.1
Migrating IBM Cloud Orchestrator environment from v2.4.0.2 to v2.5.0.1Migrating IBM Cloud Orchestrator environment from v2.4.0.2 to v2.5.0.1
Migrating IBM Cloud Orchestrator environment from v2.4.0.2 to v2.5.0.1
 
ĐÁNH GIÁ KẾT QUẢ VÁ NHĨ BẰNG KỸ THUẬT ĐẶT MẢNH GHÉP TRÊN-DƯỚI LỚP SỢI
ĐÁNH GIÁ KẾT QUẢ VÁ NHĨ BẰNG KỸ THUẬT ĐẶT MẢNH GHÉP TRÊN-DƯỚI LỚP SỢIĐÁNH GIÁ KẾT QUẢ VÁ NHĨ BẰNG KỸ THUẬT ĐẶT MẢNH GHÉP TRÊN-DƯỚI LỚP SỢI
ĐÁNH GIÁ KẾT QUẢ VÁ NHĨ BẰNG KỸ THUẬT ĐẶT MẢNH GHÉP TRÊN-DƯỚI LỚP SỢI
 
Data Structure (Double Linked List)
Data Structure (Double Linked List)Data Structure (Double Linked List)
Data Structure (Double Linked List)
 

Similaire à Algorithm and Programming (Searching)

Similaire à Algorithm and Programming (Searching) (20)

Chapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structureChapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structure
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
Unit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTINGUnit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTING
 
Ocw chp6 2searchbinary
Ocw chp6 2searchbinaryOcw chp6 2searchbinary
Ocw chp6 2searchbinary
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
searching
searchingsearching
searching
 
Searching
SearchingSearching
Searching
 
Binary search Algorithm
Binary search AlgorithmBinary search Algorithm
Binary search Algorithm
 
searching in data structure.pptx
searching in data structure.pptxsearching in data structure.pptx
searching in data structure.pptx
 
Lecture_Oct26.pptx
Lecture_Oct26.pptxLecture_Oct26.pptx
Lecture_Oct26.pptx
 
Algorithm and Data Structure - Linear Search
Algorithm and Data Structure - Linear SearchAlgorithm and Data Structure - Linear Search
Algorithm and Data Structure - Linear Search
 
Searching.ppt
Searching.pptSearching.ppt
Searching.ppt
 
Searching linear &amp; binary search
Searching linear &amp; binary searchSearching linear &amp; binary search
Searching linear &amp; binary search
 
Data Structures 8
Data Structures 8Data Structures 8
Data Structures 8
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
 
Chapter 11 ds
Chapter 11 dsChapter 11 ds
Chapter 11 ds
 
Unit 8 searching and hashing
Unit   8 searching and hashingUnit   8 searching and hashing
Unit 8 searching and hashing
 
arrays in c
arrays in carrays in c
arrays in c
 
seaching internal 2 ppt.pptx
seaching internal 2 ppt.pptxseaching internal 2 ppt.pptx
seaching internal 2 ppt.pptx
 
MODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingMODULE 5-Searching and-sorting
MODULE 5-Searching and-sorting
 

Plus de Adam Mukharil Bachtiar

Materi 8 - Data Mining Association Rule.pdf
Materi 8 - Data Mining Association Rule.pdfMateri 8 - Data Mining Association Rule.pdf
Materi 8 - Data Mining Association Rule.pdfAdam Mukharil Bachtiar
 
Clean Code and Design Pattern - Meaningful Names
Clean Code and Design Pattern - Meaningful NamesClean Code and Design Pattern - Meaningful Names
Clean Code and Design Pattern - Meaningful NamesAdam Mukharil Bachtiar
 
Data Mining Klasifikasi (Updated 30 Desember 2020)
Data Mining Klasifikasi (Updated 30 Desember 2020)Data Mining Klasifikasi (Updated 30 Desember 2020)
Data Mining Klasifikasi (Updated 30 Desember 2020)Adam Mukharil Bachtiar
 
Analisis Algoritma - Strategi Algoritma Dynamic Programming
Analisis Algoritma - Strategi Algoritma Dynamic ProgrammingAnalisis Algoritma - Strategi Algoritma Dynamic Programming
Analisis Algoritma - Strategi Algoritma Dynamic ProgrammingAdam Mukharil Bachtiar
 
Analisis Algoritma - Strategi Algoritma Divide and Conquer
Analisis Algoritma - Strategi Algoritma Divide and ConquerAnalisis Algoritma - Strategi Algoritma Divide and Conquer
Analisis Algoritma - Strategi Algoritma Divide and ConquerAdam Mukharil Bachtiar
 
Analisis Algoritma - Strategi Algoritma Greedy
Analisis Algoritma - Strategi Algoritma GreedyAnalisis Algoritma - Strategi Algoritma Greedy
Analisis Algoritma - Strategi Algoritma GreedyAdam Mukharil Bachtiar
 
Analisis Algoritma - Penerapan Strategi Algoritma Brute Force
Analisis Algoritma - Penerapan Strategi Algoritma Brute ForceAnalisis Algoritma - Penerapan Strategi Algoritma Brute Force
Analisis Algoritma - Penerapan Strategi Algoritma Brute ForceAdam Mukharil Bachtiar
 
Analisis Algoritma - Strategi Algoritma Brute Force
Analisis Algoritma - Strategi Algoritma Brute ForceAnalisis Algoritma - Strategi Algoritma Brute Force
Analisis Algoritma - Strategi Algoritma Brute ForceAdam Mukharil Bachtiar
 
Analisis Algoritma - Teorema Notasi Asimptotik
Analisis Algoritma - Teorema Notasi AsimptotikAnalisis Algoritma - Teorema Notasi Asimptotik
Analisis Algoritma - Teorema Notasi AsimptotikAdam Mukharil Bachtiar
 
Analisis Algoritma - Notasi Asimptotik
Analisis Algoritma - Notasi AsimptotikAnalisis Algoritma - Notasi Asimptotik
Analisis Algoritma - Notasi AsimptotikAdam Mukharil Bachtiar
 
Analisis Algoritma - Langkah Desain Algoritma
Analisis Algoritma - Langkah Desain AlgoritmaAnalisis Algoritma - Langkah Desain Algoritma
Analisis Algoritma - Langkah Desain AlgoritmaAdam Mukharil Bachtiar
 

Plus de Adam Mukharil Bachtiar (20)

Materi 8 - Data Mining Association Rule.pdf
Materi 8 - Data Mining Association Rule.pdfMateri 8 - Data Mining Association Rule.pdf
Materi 8 - Data Mining Association Rule.pdf
 
Clean Code - Formatting Code
Clean Code - Formatting CodeClean Code - Formatting Code
Clean Code - Formatting Code
 
Clean Code - Clean Comments
Clean Code - Clean CommentsClean Code - Clean Comments
Clean Code - Clean Comments
 
Clean Method
Clean MethodClean Method
Clean Method
 
Clean Code and Design Pattern - Meaningful Names
Clean Code and Design Pattern - Meaningful NamesClean Code and Design Pattern - Meaningful Names
Clean Code and Design Pattern - Meaningful Names
 
Model Driven Software Development
Model Driven Software DevelopmentModel Driven Software Development
Model Driven Software Development
 
Scrum: How to Implement
Scrum: How to ImplementScrum: How to Implement
Scrum: How to Implement
 
Pengujian Perangkat Lunak
Pengujian Perangkat LunakPengujian Perangkat Lunak
Pengujian Perangkat Lunak
 
Data Mining Clustering
Data Mining ClusteringData Mining Clustering
Data Mining Clustering
 
Data Mining Klasifikasi (Updated 30 Desember 2020)
Data Mining Klasifikasi (Updated 30 Desember 2020)Data Mining Klasifikasi (Updated 30 Desember 2020)
Data Mining Klasifikasi (Updated 30 Desember 2020)
 
Analisis Algoritma - Strategi Algoritma Dynamic Programming
Analisis Algoritma - Strategi Algoritma Dynamic ProgrammingAnalisis Algoritma - Strategi Algoritma Dynamic Programming
Analisis Algoritma - Strategi Algoritma Dynamic Programming
 
Analisis Algoritma - Strategi Algoritma Divide and Conquer
Analisis Algoritma - Strategi Algoritma Divide and ConquerAnalisis Algoritma - Strategi Algoritma Divide and Conquer
Analisis Algoritma - Strategi Algoritma Divide and Conquer
 
Analisis Algoritma - Strategi Algoritma Greedy
Analisis Algoritma - Strategi Algoritma GreedyAnalisis Algoritma - Strategi Algoritma Greedy
Analisis Algoritma - Strategi Algoritma Greedy
 
Analisis Algoritma - Penerapan Strategi Algoritma Brute Force
Analisis Algoritma - Penerapan Strategi Algoritma Brute ForceAnalisis Algoritma - Penerapan Strategi Algoritma Brute Force
Analisis Algoritma - Penerapan Strategi Algoritma Brute Force
 
Analisis Algoritma - Strategi Algoritma Brute Force
Analisis Algoritma - Strategi Algoritma Brute ForceAnalisis Algoritma - Strategi Algoritma Brute Force
Analisis Algoritma - Strategi Algoritma Brute Force
 
Analisis Algoritma - Teorema Notasi Asimptotik
Analisis Algoritma - Teorema Notasi AsimptotikAnalisis Algoritma - Teorema Notasi Asimptotik
Analisis Algoritma - Teorema Notasi Asimptotik
 
Analisis Algoritma - Notasi Asimptotik
Analisis Algoritma - Notasi AsimptotikAnalisis Algoritma - Notasi Asimptotik
Analisis Algoritma - Notasi Asimptotik
 
Activity Diagram
Activity DiagramActivity Diagram
Activity Diagram
 
UML dan Use Case View
UML dan Use Case ViewUML dan Use Case View
UML dan Use Case View
 
Analisis Algoritma - Langkah Desain Algoritma
Analisis Algoritma - Langkah Desain AlgoritmaAnalisis Algoritma - Langkah Desain Algoritma
Analisis Algoritma - Langkah Desain Algoritma
 

Dernier

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 

Dernier (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 

Algorithm and Programming (Searching)

  • 1. Adam Mukharil Bachtiar English Class Informatics Engineering 2011 Algorithms and Programming Searching
  • 2. Steps of the Day Let’s Start Definition of Searching Sequential Search Binary Search
  • 3. Definition of Searching All About Searching
  • 4. WhatisSearching Process that search the value in group of data. This process can produce FOUND or NOT FOUND value.
  • 5. AlgorithmsofSorting • Sequential search / Linear search • Binary search
  • 6. Sequential Search Definition and Structures of Sequential Search
  • 7. WhatisSequentialSearch • Trace group of data one by one. • Start the process from the first data. • If the data was found in group then stop the searching but if not, search until the last data in grup.
  • 8. MethodsinSequentialSearch • Without boolean  Without sentinel  Use sentinel • Use boolean
  • 9. Ilustration of Seq. Search Without Sentinel Given an array to be processed: Number Data that want to be sought : 9 • Number[1] = 9? • Number[2] = 9? • Number[3] = 9? Result: 9 is found in number[3] 5 1 9 4 2 [1] [2] [3] [4] [5] i  i + 1 i  i + 1 i (STOP SEARCH)
  • 10. Sequential Search Without Sentinel 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Procedure SeqSearchTanpaSentinel (Input nama_array:tipe_array) {I.S. : elemen array [1..maks_array] sudah terdefinisi} {F.S. : menampilkan hasil pencarian (ditemukan/tidak)} Kamus: i : integer data_cari : tipedata Algoritma: input(data_cari) i  1 while(nama_array [i] ≠ data_cari) and (i < maks_array) do i  i + 1 endwhile if (nama_array[i] = data_cari) then output(data_cari,’ ditemukan pada indeks ke-’,i) else output(data_cari,’ tidak ditemukan’) endif EndProcedure
  • 11. SequentialSearchUseSentinel • Place the data that want to be sought in sentinel. • Sentinel is additional index that was placed in max array + 1. • If the data is found in sentinel that means the result is data is not found and vice versa.
  • 12. Ilustration of Seq. Search Use Sentinel Data that was sought: 9 Number Result: Data was found in Number[3] Data that was sought: 10 Number Result: Data was not found 5 1 9 4 2 9 [1] [2] [3] [4] [5] [6] sentinel 5 1 9 4 2 10 [1] [2] [3] [4] [5] [6] sentinel
  • 13. Sequential Search Use Sentinel 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Procedure SeqSearchSentinel (Input nama_array:tipe_array) {I.S. : elemen array [1..maks_array] sudah terdefinisi} {F.S. : menampilkan hasil pencarian (ditemukan/tidak)} Kamus: i : integer data_cari : tipedata Algoritma: input(data_cari) i  1 nama_array(maks_array + 1)  data_cari while (nama_array [i] ≠ data_cari) do i  i + 1 endwhile if (i < maks_array+1) then output(data_cari,’ ditemukan pada indeks ke-’,i) else output(data_cari,’ tidak ditemukan’) endif EndProcedure
  • 14. SequentialSearchUseBoolean • Its searching process is similar with another sequential search method. • Involves one boolean variable.
  • 15. Ilustration of Seq. Search Use Boolean Given an array to be processed: Number Data that want to be sought : 9 • Number[1] = 9? • Number[2] = 9? • Number[3] = 9? Result: 9 is found in number[3] 5 1 9 4 2 [1] [2] [3] [4] [5] FOUND  FALSE FOUND  FALSE FOUND  TRUE (STOP SEARCH)
  • 16. Sequential Search Use Sentinel 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Procedure SeqSearchBoolean (Input nama_array:tipe_array) {I.S. : elemen array [1..maks_array] sudah terdefinisi} {F.S. : menampilkan data yg dicari ditemukan atau tidak ditemukan} Kamus: i : integer ketemu : boolean data_cari : tipedata Algoritma: input(data_cari) i  1 ketemu  false while (not ketemu) and (i ≤ maks_array) do if(nama_var_array(i) = data_cari) then ketemu  true else i  i + 1 endif endwhile if (ketemu) then output(data_cari,’ ditemukan pada indeks ke-’,i) else output(data_cari,’ tidak ditemukan’) endif EndProcedure
  • 17. Binary Search Definition and Structures of Binary Search
  • 18. WhatisBinarySearch • Searching algorithm that divide group of data into two parts (left and right). • First, check data in the middle. If same with the data that was sought then data is found. If not then continue searching process to left or right (based on condition). • Group of data must be sorted before the searching process.
  • 19. Data that was sought: 7 Number Result: ? CaseExampleofBinarySearch 3 7 12 15 29 [1] [2] [3] [4] [5]
  • 20. Case Example of Binary Search Data that was sought: 7 Number Result: ? 3 7 12 15 29 [1] [2] [3] [4] [5]
  • 21. Case Example of Binary Search Step 1 : Divide array into 2 parts. Count the middle position (k) of array to start searching k = (Ia + Ib) div 2 = (1 + 5) div 2 = 3 la : lower bound (for index) lb : upper bound (for index) 3 7 12 15 29 [1] [2] [3] [4] [5] Ia k Ib Left Side Right Side
  • 22. Case Example of Binary Search Step 2 : • check data in k. If it’s same with data that was sought then stop search and data is found. • If it’s not then check whether data was bigger or smaller than data in k. • If it’s bigger one then continue searching to right side and la = k+1. if it’s smaller one then continue searching to the left side and lb = k-1 (data wa sorted in ascending way). 3 7 1 2 Ia Ib
  • 23. Case Example of Binary Search Step 3 : repeat step 1 until step 2 until data is found or until la>lb then stop searching. Result : 7 is found in Number[2] and in the third looping. 3 7 1 2 Ia Ib k Left Side Right Side
  • 24. Binary Search 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Procedure BinarySearch (Input nama_array : tipe_array) {I.S. : elemen array yang terurut secara ascending sudah terdefinisi} {F.S. : menampilkan data yg dicari ditemukan atau tidak ditemukan} Kamus: Ia, Ib, k : integer ketemu : boolean data_cari : tipedata Algoritma: input(data_cari) Ia  1 Ib  maks_array ketemu  false while (not ketemu) and (Ia ≤ Ib) do k  (Ia + Ib) div 2 if (nama_var_array[k] = data_cari) then ketemu  true else if (nama_var_array[k] < data_cari) then Ia  k + 1 else Ib  k – 1 endif endif endwhile
  • 25. Binary Search 27 28 29 30 31 32 33 if (ketemu) then output(data_cari,’ ditemukan pada indeks ke-’,k) else output(data_cari,’ tidak ditemukan’) endif EndProcedure
  • 26. Contact Person: Adam Mukharil Bachtiar Informatics Engineering UNIKOM Jalan Dipati Ukur Nomor. 112-114 Bandung 40132 Email: adfbipotter@gmail.com Blog: http://adfbipotter.wordpress.com Copyright © Adam Mukharil Bachtiar 2011