SlideShare a Scribd company logo
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

More Related Content

What's hot (20)

PPTX
Merge sort algorithm
Shubham Dwivedi
 
PPT
Searching algorithms
Trupti Agrawal
 
PPTX
Binary Tree in Data Structure
Meghaj Mallick
 
PDF
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
PPT
Recursion tree method
Rajendran
 
PPTX
Longest Common Subsequence
Swati Swati
 
PPTX
Quick sort
Afaq Mansoor Khan
 
PPTX
Balanced Tree (AVL Tree & Red-Black Tree)
United International University
 
PPT
Merge sort
Vidushi Pathak
 
PPTX
Insertion Sorting
FarihaHabib123
 
PPTX
Sequential & binary, linear search
montazur420
 
PPTX
Insertion sort
almaqboli
 
PPTX
Linear Search Presentation
Markajul Hasnain Alif
 
PPT
17. Trees and Graphs
Intro C# Book
 
PPTX
Np hard
jesal_joshi
 
PPTX
Linked list
KalaivaniKS1
 
PPTX
Insertion sort
MYER301
 
PPTX
Searching techniques in Data Structure And Algorithm
03446940736
 
PPTX
Recursion
Abdur Rehman
 
Merge sort algorithm
Shubham Dwivedi
 
Searching algorithms
Trupti Agrawal
 
Binary Tree in Data Structure
Meghaj Mallick
 
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
Recursion tree method
Rajendran
 
Longest Common Subsequence
Swati Swati
 
Quick sort
Afaq Mansoor Khan
 
Balanced Tree (AVL Tree & Red-Black Tree)
United International University
 
Merge sort
Vidushi Pathak
 
Insertion Sorting
FarihaHabib123
 
Sequential & binary, linear search
montazur420
 
Insertion sort
almaqboli
 
Linear Search Presentation
Markajul Hasnain Alif
 
17. Trees and Graphs
Intro C# Book
 
Np hard
jesal_joshi
 
Linked list
KalaivaniKS1
 
Insertion sort
MYER301
 
Searching techniques in Data Structure And Algorithm
03446940736
 
Recursion
Abdur Rehman
 

Viewers also liked (20)

PDF
Algorithm and Programming (Branching Structure)
Adam Mukharil Bachtiar
 
PDF
Algorithm and Programming (Sequential Structure)
Adam Mukharil Bachtiar
 
PDF
Data Management (Data Mining Klasifikasi)
Adam Mukharil Bachtiar
 
PDF
Algorithm and Programming (Record)
Adam Mukharil Bachtiar
 
PPSX
Algorithm and Programming (Sorting)
Adam Mukharil Bachtiar
 
PDF
Algorithm and Programming (Array)
Adam Mukharil Bachtiar
 
PDF
Algorithm and Programming (Introduction of Algorithms)
Adam Mukharil Bachtiar
 
PPT
Ibm quantum computing
Francisco J. Gálvez Ramírez
 
PDF
Algorithm and Programming (Looping Structure)
Adam Mukharil Bachtiar
 
PPTX
Präsentation linkedin
Dieter Stempel
 
PPTX
Destrucció hàbitats - 1r ESO LS Manlleu 2016
Annapujolo
 
PPTX
Presentationryanair 140224071313-phpapp02
Magda Elswesy
 
PDF
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Adam Mukharil Bachtiar
 
PPTX
El llop 1r ESO La Salle Manlleu 2016
Annapujolo
 
PPTX
L'afebliment de la capa d'ozó - 1r ESO LS Manlleu 2016
Annapujolo
 
PDF
Repayment Advisor I - Phoenix, AZ
Angelene Green
 
PPT
Introduction to Quantum Computing & Quantum Information Theory
Rahul Mee
 
PPTX
Migrating IBM Cloud Orchestrator environment from v2.4.0.2 to v2.5.0.1
Paulraj Pappaiah
 
PPSX
ĐÁ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
Luanvanyhoc.com-Zalo 0927.007.596
 
PPSX
Data Structure (Double Linked List)
Adam Mukharil Bachtiar
 
Algorithm and Programming (Branching Structure)
Adam Mukharil Bachtiar
 
Algorithm and Programming (Sequential Structure)
Adam Mukharil Bachtiar
 
Data Management (Data Mining Klasifikasi)
Adam Mukharil Bachtiar
 
Algorithm and Programming (Record)
Adam Mukharil Bachtiar
 
Algorithm and Programming (Sorting)
Adam Mukharil Bachtiar
 
Algorithm and Programming (Array)
Adam Mukharil Bachtiar
 
Algorithm and Programming (Introduction of Algorithms)
Adam Mukharil Bachtiar
 
Ibm quantum computing
Francisco J. Gálvez Ramírez
 
Algorithm and Programming (Looping Structure)
Adam Mukharil Bachtiar
 
Präsentation linkedin
Dieter Stempel
 
Destrucció hàbitats - 1r ESO LS Manlleu 2016
Annapujolo
 
Presentationryanair 140224071313-phpapp02
Magda Elswesy
 
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Adam Mukharil Bachtiar
 
El llop 1r ESO La Salle Manlleu 2016
Annapujolo
 
L'afebliment de la capa d'ozó - 1r ESO LS Manlleu 2016
Annapujolo
 
Repayment Advisor I - Phoenix, AZ
Angelene Green
 
Introduction to Quantum Computing & Quantum Information Theory
Rahul Mee
 
Migrating IBM Cloud Orchestrator environment from v2.4.0.2 to v2.5.0.1
Paulraj 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
Luanvanyhoc.com-Zalo 0927.007.596
 
Data Structure (Double Linked List)
Adam Mukharil Bachtiar
 
Ad

Similar to Algorithm and Programming (Searching) (20)

PPTX
Sorting and searching arrays binary search algorithm
David Burks-Courses
 
PPTX
Searching linear &amp; binary search
nikunjandy
 
PPT
4.1 sequentioal search
Krish_ver2
 
PPT
Searching
Shaista Qadir
 
PPTX
Lecture_Oct26.pptx
SylrizcinMarieManzo3
 
PPTX
Searching Algorithms - Foundations of Algorithms
ssusere05275
 
PPTX
Dsa – data structure and algorithms searching
sajinis3
 
PPTX
Searching Techniques and Analysis
AkashBorse2
 
PPTX
Introduction to Searching Algorithm for beginners
JoshuaEddyson1
 
PPTX
3.Problem Solving Techniques and Data Structures.pptx
Ganesh Bhosale
 
PDF
dsa pdf.pdf
DewashishDwivedi
 
PPTX
apa itu pencarian linier atau sequential search.pptx
FahrudinAlfianurHida
 
PDF
searching
A. S. M. Shafi
 
PPT
arrays1.ppt python programme arrays insertion
bushraashraf639
 
DOCX
PPS 5.5.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.), BASI...
Sitamarhi Institute of Technology
 
PPTX
Unit 2 Searching and Sorting Technique.pptx
Vaibhav Parjane
 
PPSX
Searching in Arrays
Dhiviya Rose
 
PPTX
Linear and Binary search .pptx
p83629918
 
PPTX
Lecture 4_Linear & Binary search from data structure and algorithm
ArifatunNesa
 
PPTX
7 searching injava-binary
irdginfo
 
Sorting and searching arrays binary search algorithm
David Burks-Courses
 
Searching linear &amp; binary search
nikunjandy
 
4.1 sequentioal search
Krish_ver2
 
Searching
Shaista Qadir
 
Lecture_Oct26.pptx
SylrizcinMarieManzo3
 
Searching Algorithms - Foundations of Algorithms
ssusere05275
 
Dsa – data structure and algorithms searching
sajinis3
 
Searching Techniques and Analysis
AkashBorse2
 
Introduction to Searching Algorithm for beginners
JoshuaEddyson1
 
3.Problem Solving Techniques and Data Structures.pptx
Ganesh Bhosale
 
dsa pdf.pdf
DewashishDwivedi
 
apa itu pencarian linier atau sequential search.pptx
FahrudinAlfianurHida
 
searching
A. S. M. Shafi
 
arrays1.ppt python programme arrays insertion
bushraashraf639
 
PPS 5.5.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.), BASI...
Sitamarhi Institute of Technology
 
Unit 2 Searching and Sorting Technique.pptx
Vaibhav Parjane
 
Searching in Arrays
Dhiviya Rose
 
Linear and Binary search .pptx
p83629918
 
Lecture 4_Linear & Binary search from data structure and algorithm
ArifatunNesa
 
7 searching injava-binary
irdginfo
 
Ad

More from Adam Mukharil Bachtiar (20)

PDF
Materi 8 - Data Mining Association Rule.pdf
Adam Mukharil Bachtiar
 
PDF
Clean Code - Formatting Code
Adam Mukharil Bachtiar
 
PDF
Clean Code - Clean Comments
Adam Mukharil Bachtiar
 
PDF
Clean Method
Adam Mukharil Bachtiar
 
PDF
Clean Code and Design Pattern - Meaningful Names
Adam Mukharil Bachtiar
 
PDF
Model Driven Software Development
Adam Mukharil Bachtiar
 
PDF
Scrum: How to Implement
Adam Mukharil Bachtiar
 
PDF
Pengujian Perangkat Lunak
Adam Mukharil Bachtiar
 
PDF
Data Mining Clustering
Adam Mukharil Bachtiar
 
PPTX
Data Mining Klasifikasi (Updated 30 Desember 2020)
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Strategi Algoritma Dynamic Programming
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Strategi Algoritma Divide and Conquer
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Strategi Algoritma Greedy
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Penerapan Strategi Algoritma Brute Force
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Strategi Algoritma Brute Force
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Kelas-kelas Dasar Efisiensi Algoritma
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Teorema Notasi Asimptotik
Adam Mukharil Bachtiar
 
PDF
Analisis Algoritma - Notasi Asimptotik
Adam Mukharil Bachtiar
 
PDF
Activity Diagram
Adam Mukharil Bachtiar
 
PDF
UML dan Use Case View
Adam Mukharil Bachtiar
 
Materi 8 - Data Mining Association Rule.pdf
Adam Mukharil Bachtiar
 
Clean Code - Formatting Code
Adam Mukharil Bachtiar
 
Clean Code - Clean Comments
Adam Mukharil Bachtiar
 
Clean Code and Design Pattern - Meaningful Names
Adam Mukharil Bachtiar
 
Model Driven Software Development
Adam Mukharil Bachtiar
 
Scrum: How to Implement
Adam Mukharil Bachtiar
 
Pengujian Perangkat Lunak
Adam Mukharil Bachtiar
 
Data Mining Clustering
Adam Mukharil Bachtiar
 
Data Mining Klasifikasi (Updated 30 Desember 2020)
Adam Mukharil Bachtiar
 
Analisis Algoritma - Strategi Algoritma Dynamic Programming
Adam Mukharil Bachtiar
 
Analisis Algoritma - Strategi Algoritma Divide and Conquer
Adam Mukharil Bachtiar
 
Analisis Algoritma - Strategi Algoritma Greedy
Adam Mukharil Bachtiar
 
Analisis Algoritma - Penerapan Strategi Algoritma Brute Force
Adam Mukharil Bachtiar
 
Analisis Algoritma - Strategi Algoritma Brute Force
Adam Mukharil Bachtiar
 
Analisis Algoritma - Kelas-kelas Dasar Efisiensi Algoritma
Adam Mukharil Bachtiar
 
Analisis Algoritma - Teorema Notasi Asimptotik
Adam Mukharil Bachtiar
 
Analisis Algoritma - Notasi Asimptotik
Adam Mukharil Bachtiar
 
Activity Diagram
Adam Mukharil Bachtiar
 
UML dan Use Case View
Adam Mukharil Bachtiar
 

Recently uploaded (20)

PPTX
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
PDF
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
PPTX
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 

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: [email protected] Blog: http://adfbipotter.wordpress.com Copyright © Adam Mukharil Bachtiar 2011