SlideShare a Scribd company logo
Algorithm and
Data Structure
Andi Nurkholis, S.Kom, M.Kom
Study Program of Informatics
Faculty of Engineering and Computer Science
SY. 2020-2021
May 03, 2021
2
6 Searching
3
What is Searching?
Searching for data stored in different data structures
is a crucial part of pretty much every single
application.
There are many different algorithms available to
utilize when searching, and each have different
implementations and rely on different data
structures to get the job done.
4
Searching
Algorithm
1) Linear Search
2) Binary Search
Being able to choose a specific algorithm
for a given task is a key skill for
developers and can mean the difference
between a fast, reliable and stable
application and an application that
crumbles from a simple request.
5
6.1 Linear Search
6
Linear Search
Linear search is a very basic and simple search algorithm. In Linear
search, we search an element or value in a given array by
traversing the array from the starting, till the desired element or
value is found. Linear search also known as sequential search
Steps of Linear Search
1. Traverse the array using a for loop
2. In every iteration, compare the target value with
the current value of the array.
• If the values match, return the current index of
the array.
• If the values do not match, move on to the next
array element.
3. If no match is found, return -1
7
Example
8
data_1 = {3, 8, 6, 1, 9, 5, 7, 0, 2, 4}
1) Find value 7 in array data_1
data_2 = {8, 0, 1, 9, 2, 4, 3, 7, 5, 3}
2) Find value 3 in array data_2
data_3 = {7, 6, 1, 9, 3, 8, 5, 0, 1, 2}
3) Find value 4 in array data_3
Answer 1
9
Step 1
3 8 6 1 9 5 7 0 2 4
Value searched for 7
Value in 0-index array is 3
Is value 7 = 3?
FALSE
Then Algorithm is CONTINUE
Answer 1 (cont.)
10
3 8 6 1 9 5 7 0 2 4
Step 2
Value searched for 7
Value in 1-index array is 8
Is value 7 = 8?
FALSE
Then Algorithm is CONTINUE
Answer 1 (cont.)
11
3 8 6 1 9 5 7 0 2 4
Step 3
Value searched for 7
Value in 2-index array is 6
Is value 7 = 6?
FALSE
Then Algorithm is CONTINUE
Answer 1 (cont.)
12
3 8 6 1 9 5 7 0 2 4
Step 4
Value searched for 7
Value in 3-index array is 1
Is value 7 = 1?
FALSE
Then Algorithm is CONTINUE
Answer 1 (cont.)
13
3 8 6 1 9 5 7 0 2 4
Step 5
Value searched for 7
Value in 4-index array is 9
Is value 7 = 9?
FALSE
Then Algorithm is CONTINUE
Answer 1 (cont.)
14
3 8 6 1 9 5 7 0 2 4
Step 6
Value searched for 7
Value in 5-index array is 5
Is value 7 = 5?
FALSE
Then Algorithm is CONTINUE
Answer 1 (cont.)
15
3 8 6 1 9 5 7 0 2 4
Step 7
Value searched for 7
Value in 6-index array is 7
Is value 7 = 7?
TRUE
Then Algorithm is STOP
16
Final Result
Value searched for 7 is FOUND
in step 7
Answer 2
17
Step 1
8 0 1 9 2 4 3 7 5 3
Value searched for 3
Value in 0-index array is 8
Is value 3 = 8?
FALSE
Then Algorithm is CONTINUE
Answer 2 (cont.)
18
8 0 1 9 2 4 3 7 5 3
Step 2
Value searched for 3
Value in 1-index array is 0
Is value 3 = 0?
FALSE
Then Algorithm is CONTINUE
Answer 2 (cont.)
19
8 0 1 9 2 4 3 7 5 3
Step 3
Value searched for 3
Value in 2-index array is 1
Is value 3 = 1?
FALSE
Then Algorithm is CONTINUE
Answer 2 (cont.)
20
8 0 1 9 2 4 3 7 5 3
Step 4
Value searched for 3
Value in 3-index array is 9
Is value 3 = 9?
FALSE
Then Algorithm is CONTINUE
Answer 2 (cont.)
21
8 0 1 9 2 4 3 7 5 3
Step 5
Value searched for 3
Value in 4-index array is 2
Is value 3 = 2?
FALSE
Then Algorithm is CONTINUE
Answer 2 (cont.)
22
8 0 1 9 2 4 3 7 5 3
Step 6
Value searched for 3
Value in 5-index array is 4
Is value 3 = 4?
FALSE
Then Algorithm is CONTINUE
Answer 2 (cont.)
23
8 0 1 9 2 4 3 7 5 3
Step 7
Value searched for 3
Value in 6-index array is 3
Is value 3 = 3?
TRUE
Then Algorithm is STOP
24
Final Result
Value searched for 3 is FOUND
in step 7,
although as can be seen in the array there is
other 3 value on the 9-index
Answer 3
25
Step 1
7 6 1 9 3 8 5 0 1 2
Value searched for 4
Value in 0-index array is 7
Is value 4 = 8?
FALSE
Then Algorithm is CONTINUE
Answer 3 (cont.)
26
7 6 1 9 3 8 5 0 1 2
Step 2
Value searched for 4
Value in 1-index array is 6
Is value 4 = 6?
FALSE
Then Algorithm is CONTINUE
Answer 3 (cont.)
27
7 6 1 9 3 8 5 0 1 2
Step 3
Value searched for 4
Value in 2-index array is 1
Is value 4 = 1?
FALSE
Then Algorithm is CONTINUE
Answer 3 (cont.)
28
7 6 1 9 3 8 5 0 1 2
Step 4
Value searched for 4
Value in 3-index array is 9
Is value 4 = 9?
FALSE
Then Algorithm is CONTINUE
Answer 3 (cont.)
29
7 6 1 9 3 8 5 0 1 2
Step 5
Value searched for 4
Value in 4-index array is 3
Is value 4 = 3?
FALSE
Then Algorithm is CONTINUE
Answer 3 (cont.)
30
7 6 1 9 3 8 5 0 1 2
Step 6
Value searched for 4
Value in 5-index array is 8
Is value 4 = 8?
FALSE
Then Algorithm is CONTINUE
Answer 3 (cont.)
31
7 6 1 9 3 8 5 0 1 2
Step 7
Value searched for 4
Value in 6-index array is 5
Is value 4 = 5?
FALSE
Then Algorithm is CONTINUE
Answer 3 (cont.)
32
7 6 1 9 3 8 5 0 1 2
Step 8
Value searched for 4
Value in 7-index array is 0
Is value 4 = 0?
FALSE
Then Algorithm is CONTINUE
Answer 3 (cont.)
33
7 6 1 9 3 8 5 0 1 2
Step 9
Value searched for 4
Value in 8-index array is 1
Is value 4 = 1?
FALSE
Then Algorithm is CONTINUE
Answer 3 (cont.)
34
7 6 1 9 3 8 5 0 1 2
The Last Step
Value searched for 4
Value in 9-index array is 2
Is value 4 = 2?
FALSE
Then Algorithm is STOP
35
Final Result
Value searched for 4 is NOT FOUND,
even though it was done until the end of the
index array
Advantage of Linear Search
1. Will perform fast searches of small to medium array. With
today's powerful computers, small to medium arrays can be
searched relatively quickly.
2. The array value does not need to sorted. Unlike a binary
search, linear searching does not require an ordered list.
3. Not affected by insertions and deletions. As the linear search
does not require the list to be sorted, additional elements can
be added and deleted.
36
Disadvantage of Linear Search
1. Slow searching of large array. For example, when
searching through a database of everyone in the
Northern Ireland to find a particular name, it
might be necessary to search through 1.8 million
names before you found the one you wanted.
2. Inversely, when a key element matches the last
element in the array or a key element doesn't
matches any element then Linear search
algorithm is a worst case.
37
Thank You, Next …
Binary Search
May 03, 2021
Andi Nurkholis, S.Kom, M.Kom
Study Program of Informatics
Faculty of Engineering and Computer Science
SY. 2020-2021
Ad

Recommended

Algorithm and Data Structure - Binary Search
Algorithm and Data Structure - Binary Search
AndiNurkholis1
 
Unit 5 introduction systems of equations
Unit 5 introduction systems of equations
julienorman80065
 
Adding & Subtracting Fractions
Adding & Subtracting Fractions
LorenKnights
 
Interactive Reader + Foldable
Interactive Reader + Foldable
jmori1
 
Algebra ccp course outline 10 11
Algebra ccp course outline 10 11
sbroadhurst
 
Ocw chp6 2searchbinary
Ocw chp6 2searchbinary
Prashant Rai
 
Scope and sequence , Budget of work ,and Weekly Lesson Plan in Educ.11
Scope and sequence , Budget of work ,and Weekly Lesson Plan in Educ.11
Reymart Bargamento
 
Basic relation add math
Basic relation add math
Roiamah Basri
 
Interactive powerpoint - matrices; Budkie
Interactive powerpoint - matrices; Budkie
Elyse Budkie
 
EE235 Final Exam 2011
EE235 Final Exam 2011
PhanSteveDell
 
Outlier managment
Outlier managment
Siddhartha Harit
 
Topological sort
Topological sort
stella D
 
Eigenvalues for HIV-1 dynamic model with two delays
Eigenvalues for HIV-1 dynamic model with two delays
IOSR Journals
 
Object oriented programming15 control structures relational operators
Object oriented programming15 control structures relational operators
Vaibhav Khanna
 
Lesson 1 introduction
Lesson 1 introduction
MLG College of Learning, Inc
 
Solving linear equations in two
Solving linear equations in two
mstf mstf
 
11:00 ABE Math THUR 4/26
11:00 ABE Math THUR 4/26
Clark College ABE/GED Math
 
computer notes - Circular list
computer notes - Circular list
ecomputernotes
 
Math matrix
Math matrix
MahadiHasanRupom1
 
7.01
7.01
Damon Clarke
 
4) generating sequence_from_the_nth_term
4) generating sequence_from_the_nth_term
harlie90
 
Experimental Research
Experimental Research
smartandy
 
Fea unit 1
Fea unit 1
s Kumaravel
 
Topological sort
Topological sort
stella D
 
Linear search in ds
Linear search in ds
chauhankapil
 
(8) Lesson 3.2
(8) Lesson 3.2
wzuri
 
Real numbers and their properties
Real numbers and their properties
elearningunit2013
 
Unit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTING
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching Algorithms
IRJET Journal
 
Lecture-1-Algorithms.pptx
Lecture-1-Algorithms.pptx
xalahama3
 

More Related Content

What's hot (19)

Interactive powerpoint - matrices; Budkie
Interactive powerpoint - matrices; Budkie
Elyse Budkie
 
EE235 Final Exam 2011
EE235 Final Exam 2011
PhanSteveDell
 
Outlier managment
Outlier managment
Siddhartha Harit
 
Topological sort
Topological sort
stella D
 
Eigenvalues for HIV-1 dynamic model with two delays
Eigenvalues for HIV-1 dynamic model with two delays
IOSR Journals
 
Object oriented programming15 control structures relational operators
Object oriented programming15 control structures relational operators
Vaibhav Khanna
 
Lesson 1 introduction
Lesson 1 introduction
MLG College of Learning, Inc
 
Solving linear equations in two
Solving linear equations in two
mstf mstf
 
11:00 ABE Math THUR 4/26
11:00 ABE Math THUR 4/26
Clark College ABE/GED Math
 
computer notes - Circular list
computer notes - Circular list
ecomputernotes
 
Math matrix
Math matrix
MahadiHasanRupom1
 
7.01
7.01
Damon Clarke
 
4) generating sequence_from_the_nth_term
4) generating sequence_from_the_nth_term
harlie90
 
Experimental Research
Experimental Research
smartandy
 
Fea unit 1
Fea unit 1
s Kumaravel
 
Topological sort
Topological sort
stella D
 
Linear search in ds
Linear search in ds
chauhankapil
 
(8) Lesson 3.2
(8) Lesson 3.2
wzuri
 
Real numbers and their properties
Real numbers and their properties
elearningunit2013
 
Interactive powerpoint - matrices; Budkie
Interactive powerpoint - matrices; Budkie
Elyse Budkie
 
EE235 Final Exam 2011
EE235 Final Exam 2011
PhanSteveDell
 
Topological sort
Topological sort
stella D
 
Eigenvalues for HIV-1 dynamic model with two delays
Eigenvalues for HIV-1 dynamic model with two delays
IOSR Journals
 
Object oriented programming15 control structures relational operators
Object oriented programming15 control structures relational operators
Vaibhav Khanna
 
Solving linear equations in two
Solving linear equations in two
mstf mstf
 
computer notes - Circular list
computer notes - Circular list
ecomputernotes
 
4) generating sequence_from_the_nth_term
4) generating sequence_from_the_nth_term
harlie90
 
Experimental Research
Experimental Research
smartandy
 
Topological sort
Topological sort
stella D
 
Linear search in ds
Linear search in ds
chauhankapil
 
(8) Lesson 3.2
(8) Lesson 3.2
wzuri
 
Real numbers and their properties
Real numbers and their properties
elearningunit2013
 

Similar to Algorithm and Data Structure - Linear Search (20)

Unit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTING
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching Algorithms
IRJET Journal
 
Lecture-1-Algorithms.pptx
Lecture-1-Algorithms.pptx
xalahama3
 
Chapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structure
Mahmoud Alfarra
 
Search Algprithms
Search Algprithms
Shivam Singh
 
GRID SEARCHING Novel way of Searching 2D Array
GRID SEARCHING Novel way of Searching 2D Array
Editor IJCATR
 
Algorithm and Programming (Searching)
Algorithm and Programming (Searching)
Adam Mukharil Bachtiar
 
Chapter #3 (Searchinmmmg ALgorithm).pptx
Chapter #3 (Searchinmmmg ALgorithm).pptx
hekmatyarzahir44
 
Searching Sorting-SELECTION ,BUBBBLE.ppt
Searching Sorting-SELECTION ,BUBBBLE.ppt
kunalpatil5661
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
Chapter 1 - Introduction to Searching and Sorting Algorithms - Student.pdf
Chapter 1 - Introduction to Searching and Sorting Algorithms - Student.pdf
mylinhbangus
 
Data Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search Algorithms
Ferdin Joe John Joseph PhD
 
Algo PPT.pdf
Algo PPT.pdf
sheraz7288
 
Array ADT(Abstract Data Type)|Data Structure
Array ADT(Abstract Data Type)|Data Structure
Akash Gaur
 
Rahat & juhith
Rahat & juhith
Rj Juhith
 
Empirical Analysis of Quaternary and Binary Search.pdf
Empirical Analysis of Quaternary and Binary Search.pdf
MMA
 
advanced searching and sorting.pdf
advanced searching and sorting.pdf
haramaya university
 
ODD EVEN BASED BINARY SEARCH
ODD EVEN BASED BINARY SEARCH
IAEME Publication
 
DSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdf
MustafaJutt4
 
Searching
Searching
A. S. M. Shafi
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching Algorithms
IRJET Journal
 
Lecture-1-Algorithms.pptx
Lecture-1-Algorithms.pptx
xalahama3
 
Chapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structure
Mahmoud Alfarra
 
GRID SEARCHING Novel way of Searching 2D Array
GRID SEARCHING Novel way of Searching 2D Array
Editor IJCATR
 
Chapter #3 (Searchinmmmg ALgorithm).pptx
Chapter #3 (Searchinmmmg ALgorithm).pptx
hekmatyarzahir44
 
Searching Sorting-SELECTION ,BUBBBLE.ppt
Searching Sorting-SELECTION ,BUBBBLE.ppt
kunalpatil5661
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
Chapter 1 - Introduction to Searching and Sorting Algorithms - Student.pdf
Chapter 1 - Introduction to Searching and Sorting Algorithms - Student.pdf
mylinhbangus
 
Data Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search Algorithms
Ferdin Joe John Joseph PhD
 
Array ADT(Abstract Data Type)|Data Structure
Array ADT(Abstract Data Type)|Data Structure
Akash Gaur
 
Rahat & juhith
Rahat & juhith
Rj Juhith
 
Empirical Analysis of Quaternary and Binary Search.pdf
Empirical Analysis of Quaternary and Binary Search.pdf
MMA
 
advanced searching and sorting.pdf
advanced searching and sorting.pdf
haramaya university
 
ODD EVEN BASED BINARY SEARCH
ODD EVEN BASED BINARY SEARCH
IAEME Publication
 
DSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdf
MustafaJutt4
 
Ad

More from AndiNurkholis1 (20)

Technopreneurship - 9 Analisis Biaya dan Keuangan
Technopreneurship - 9 Analisis Biaya dan Keuangan
AndiNurkholis1
 
Pengantar Bisnis - 14 Manajemen Keuangan
Pengantar Bisnis - 14 Manajemen Keuangan
AndiNurkholis1
 
Pengantar Bisnis - 13 Manajemen Operasi
Pengantar Bisnis - 13 Manajemen Operasi
AndiNurkholis1
 
Pengantar Bisnis - 12 Kebijakan Harga
Pengantar Bisnis - 12 Kebijakan Harga
AndiNurkholis1
 
Pengantar Bisnis - 11 Kebijakan Distribusi
Pengantar Bisnis - 11 Kebijakan Distribusi
AndiNurkholis1
 
Technopreneurship - 8 Manajemen Sumber Daya Manusia
Technopreneurship - 8 Manajemen Sumber Daya Manusia
AndiNurkholis1
 
Pengantar Bisnis - 10 Kebijakan Produk
Pengantar Bisnis - 10 Kebijakan Produk
AndiNurkholis1
 
Technopreneurship - 7 Manajemen Pemasaran dan Operasional Bisnis
Technopreneurship - 7 Manajemen Pemasaran dan Operasional Bisnis
AndiNurkholis1
 
Pengantar Bisnis - 9 Manajemen Pemasaran
Pengantar Bisnis - 9 Manajemen Pemasaran
AndiNurkholis1
 
Technopreneurship - 6 Business Plan
Technopreneurship - 6 Business Plan
AndiNurkholis1
 
Pengantar Bisnis - 8 Kepemimpinan
Pengantar Bisnis - 8 Kepemimpinan
AndiNurkholis1
 
Technopreneurship - 5 Model Bisnis
Technopreneurship - 5 Model Bisnis
AndiNurkholis1
 
Technopreneurship - 4 Studi Kelayakan Usaha
Technopreneurship - 4 Studi Kelayakan Usaha
AndiNurkholis1
 
Pengantar Bisnis - 7 Motivasi Kerja
Pengantar Bisnis - 7 Motivasi Kerja
AndiNurkholis1
 
Pengantar Bisnis - 6 Manajemen Sumber Daya Manusia
Pengantar Bisnis - 6 Manajemen Sumber Daya Manusia
AndiNurkholis1
 
Pengantar Bisnis - 5 Pengelolaan & Pengorganisasian Bisnis
Pengantar Bisnis - 5 Pengelolaan & Pengorganisasian Bisnis
AndiNurkholis1
 
Technopreneurship - 3 Ide dan Prinsip Bisnis
Technopreneurship - 3 Ide dan Prinsip Bisnis
AndiNurkholis1
 
Pengantar Bisnis - 4 Bentuk Organisasi Bisnis
Pengantar Bisnis - 4 Bentuk Organisasi Bisnis
AndiNurkholis1
 
Technopreneurship - 2 Pengantar Technopreneurship
Technopreneurship - 2 Pengantar Technopreneurship
AndiNurkholis1
 
Pengantar Bisnis - 3 Globalisasi Ekonomi & Bisnis Internasional
Pengantar Bisnis - 3 Globalisasi Ekonomi & Bisnis Internasional
AndiNurkholis1
 
Technopreneurship - 9 Analisis Biaya dan Keuangan
Technopreneurship - 9 Analisis Biaya dan Keuangan
AndiNurkholis1
 
Pengantar Bisnis - 14 Manajemen Keuangan
Pengantar Bisnis - 14 Manajemen Keuangan
AndiNurkholis1
 
Pengantar Bisnis - 13 Manajemen Operasi
Pengantar Bisnis - 13 Manajemen Operasi
AndiNurkholis1
 
Pengantar Bisnis - 12 Kebijakan Harga
Pengantar Bisnis - 12 Kebijakan Harga
AndiNurkholis1
 
Pengantar Bisnis - 11 Kebijakan Distribusi
Pengantar Bisnis - 11 Kebijakan Distribusi
AndiNurkholis1
 
Technopreneurship - 8 Manajemen Sumber Daya Manusia
Technopreneurship - 8 Manajemen Sumber Daya Manusia
AndiNurkholis1
 
Pengantar Bisnis - 10 Kebijakan Produk
Pengantar Bisnis - 10 Kebijakan Produk
AndiNurkholis1
 
Technopreneurship - 7 Manajemen Pemasaran dan Operasional Bisnis
Technopreneurship - 7 Manajemen Pemasaran dan Operasional Bisnis
AndiNurkholis1
 
Pengantar Bisnis - 9 Manajemen Pemasaran
Pengantar Bisnis - 9 Manajemen Pemasaran
AndiNurkholis1
 
Technopreneurship - 6 Business Plan
Technopreneurship - 6 Business Plan
AndiNurkholis1
 
Pengantar Bisnis - 8 Kepemimpinan
Pengantar Bisnis - 8 Kepemimpinan
AndiNurkholis1
 
Technopreneurship - 5 Model Bisnis
Technopreneurship - 5 Model Bisnis
AndiNurkholis1
 
Technopreneurship - 4 Studi Kelayakan Usaha
Technopreneurship - 4 Studi Kelayakan Usaha
AndiNurkholis1
 
Pengantar Bisnis - 7 Motivasi Kerja
Pengantar Bisnis - 7 Motivasi Kerja
AndiNurkholis1
 
Pengantar Bisnis - 6 Manajemen Sumber Daya Manusia
Pengantar Bisnis - 6 Manajemen Sumber Daya Manusia
AndiNurkholis1
 
Pengantar Bisnis - 5 Pengelolaan & Pengorganisasian Bisnis
Pengantar Bisnis - 5 Pengelolaan & Pengorganisasian Bisnis
AndiNurkholis1
 
Technopreneurship - 3 Ide dan Prinsip Bisnis
Technopreneurship - 3 Ide dan Prinsip Bisnis
AndiNurkholis1
 
Pengantar Bisnis - 4 Bentuk Organisasi Bisnis
Pengantar Bisnis - 4 Bentuk Organisasi Bisnis
AndiNurkholis1
 
Technopreneurship - 2 Pengantar Technopreneurship
Technopreneurship - 2 Pengantar Technopreneurship
AndiNurkholis1
 
Pengantar Bisnis - 3 Globalisasi Ekonomi & Bisnis Internasional
Pengantar Bisnis - 3 Globalisasi Ekonomi & Bisnis Internasional
AndiNurkholis1
 
Ad

Recently uploaded (20)

Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 

Algorithm and Data Structure - Linear Search

  • 1. Algorithm and Data Structure Andi Nurkholis, S.Kom, M.Kom Study Program of Informatics Faculty of Engineering and Computer Science SY. 2020-2021 May 03, 2021
  • 3. 3 What is Searching? Searching for data stored in different data structures is a crucial part of pretty much every single application. There are many different algorithms available to utilize when searching, and each have different implementations and rely on different data structures to get the job done.
  • 4. 4 Searching Algorithm 1) Linear Search 2) Binary Search Being able to choose a specific algorithm for a given task is a key skill for developers and can mean the difference between a fast, reliable and stable application and an application that crumbles from a simple request.
  • 6. 6 Linear Search Linear search is a very basic and simple search algorithm. In Linear search, we search an element or value in a given array by traversing the array from the starting, till the desired element or value is found. Linear search also known as sequential search
  • 7. Steps of Linear Search 1. Traverse the array using a for loop 2. In every iteration, compare the target value with the current value of the array. • If the values match, return the current index of the array. • If the values do not match, move on to the next array element. 3. If no match is found, return -1 7
  • 8. Example 8 data_1 = {3, 8, 6, 1, 9, 5, 7, 0, 2, 4} 1) Find value 7 in array data_1 data_2 = {8, 0, 1, 9, 2, 4, 3, 7, 5, 3} 2) Find value 3 in array data_2 data_3 = {7, 6, 1, 9, 3, 8, 5, 0, 1, 2} 3) Find value 4 in array data_3
  • 9. Answer 1 9 Step 1 3 8 6 1 9 5 7 0 2 4 Value searched for 7 Value in 0-index array is 3 Is value 7 = 3? FALSE Then Algorithm is CONTINUE
  • 10. Answer 1 (cont.) 10 3 8 6 1 9 5 7 0 2 4 Step 2 Value searched for 7 Value in 1-index array is 8 Is value 7 = 8? FALSE Then Algorithm is CONTINUE
  • 11. Answer 1 (cont.) 11 3 8 6 1 9 5 7 0 2 4 Step 3 Value searched for 7 Value in 2-index array is 6 Is value 7 = 6? FALSE Then Algorithm is CONTINUE
  • 12. Answer 1 (cont.) 12 3 8 6 1 9 5 7 0 2 4 Step 4 Value searched for 7 Value in 3-index array is 1 Is value 7 = 1? FALSE Then Algorithm is CONTINUE
  • 13. Answer 1 (cont.) 13 3 8 6 1 9 5 7 0 2 4 Step 5 Value searched for 7 Value in 4-index array is 9 Is value 7 = 9? FALSE Then Algorithm is CONTINUE
  • 14. Answer 1 (cont.) 14 3 8 6 1 9 5 7 0 2 4 Step 6 Value searched for 7 Value in 5-index array is 5 Is value 7 = 5? FALSE Then Algorithm is CONTINUE
  • 15. Answer 1 (cont.) 15 3 8 6 1 9 5 7 0 2 4 Step 7 Value searched for 7 Value in 6-index array is 7 Is value 7 = 7? TRUE Then Algorithm is STOP
  • 16. 16 Final Result Value searched for 7 is FOUND in step 7
  • 17. Answer 2 17 Step 1 8 0 1 9 2 4 3 7 5 3 Value searched for 3 Value in 0-index array is 8 Is value 3 = 8? FALSE Then Algorithm is CONTINUE
  • 18. Answer 2 (cont.) 18 8 0 1 9 2 4 3 7 5 3 Step 2 Value searched for 3 Value in 1-index array is 0 Is value 3 = 0? FALSE Then Algorithm is CONTINUE
  • 19. Answer 2 (cont.) 19 8 0 1 9 2 4 3 7 5 3 Step 3 Value searched for 3 Value in 2-index array is 1 Is value 3 = 1? FALSE Then Algorithm is CONTINUE
  • 20. Answer 2 (cont.) 20 8 0 1 9 2 4 3 7 5 3 Step 4 Value searched for 3 Value in 3-index array is 9 Is value 3 = 9? FALSE Then Algorithm is CONTINUE
  • 21. Answer 2 (cont.) 21 8 0 1 9 2 4 3 7 5 3 Step 5 Value searched for 3 Value in 4-index array is 2 Is value 3 = 2? FALSE Then Algorithm is CONTINUE
  • 22. Answer 2 (cont.) 22 8 0 1 9 2 4 3 7 5 3 Step 6 Value searched for 3 Value in 5-index array is 4 Is value 3 = 4? FALSE Then Algorithm is CONTINUE
  • 23. Answer 2 (cont.) 23 8 0 1 9 2 4 3 7 5 3 Step 7 Value searched for 3 Value in 6-index array is 3 Is value 3 = 3? TRUE Then Algorithm is STOP
  • 24. 24 Final Result Value searched for 3 is FOUND in step 7, although as can be seen in the array there is other 3 value on the 9-index
  • 25. Answer 3 25 Step 1 7 6 1 9 3 8 5 0 1 2 Value searched for 4 Value in 0-index array is 7 Is value 4 = 8? FALSE Then Algorithm is CONTINUE
  • 26. Answer 3 (cont.) 26 7 6 1 9 3 8 5 0 1 2 Step 2 Value searched for 4 Value in 1-index array is 6 Is value 4 = 6? FALSE Then Algorithm is CONTINUE
  • 27. Answer 3 (cont.) 27 7 6 1 9 3 8 5 0 1 2 Step 3 Value searched for 4 Value in 2-index array is 1 Is value 4 = 1? FALSE Then Algorithm is CONTINUE
  • 28. Answer 3 (cont.) 28 7 6 1 9 3 8 5 0 1 2 Step 4 Value searched for 4 Value in 3-index array is 9 Is value 4 = 9? FALSE Then Algorithm is CONTINUE
  • 29. Answer 3 (cont.) 29 7 6 1 9 3 8 5 0 1 2 Step 5 Value searched for 4 Value in 4-index array is 3 Is value 4 = 3? FALSE Then Algorithm is CONTINUE
  • 30. Answer 3 (cont.) 30 7 6 1 9 3 8 5 0 1 2 Step 6 Value searched for 4 Value in 5-index array is 8 Is value 4 = 8? FALSE Then Algorithm is CONTINUE
  • 31. Answer 3 (cont.) 31 7 6 1 9 3 8 5 0 1 2 Step 7 Value searched for 4 Value in 6-index array is 5 Is value 4 = 5? FALSE Then Algorithm is CONTINUE
  • 32. Answer 3 (cont.) 32 7 6 1 9 3 8 5 0 1 2 Step 8 Value searched for 4 Value in 7-index array is 0 Is value 4 = 0? FALSE Then Algorithm is CONTINUE
  • 33. Answer 3 (cont.) 33 7 6 1 9 3 8 5 0 1 2 Step 9 Value searched for 4 Value in 8-index array is 1 Is value 4 = 1? FALSE Then Algorithm is CONTINUE
  • 34. Answer 3 (cont.) 34 7 6 1 9 3 8 5 0 1 2 The Last Step Value searched for 4 Value in 9-index array is 2 Is value 4 = 2? FALSE Then Algorithm is STOP
  • 35. 35 Final Result Value searched for 4 is NOT FOUND, even though it was done until the end of the index array
  • 36. Advantage of Linear Search 1. Will perform fast searches of small to medium array. With today's powerful computers, small to medium arrays can be searched relatively quickly. 2. The array value does not need to sorted. Unlike a binary search, linear searching does not require an ordered list. 3. Not affected by insertions and deletions. As the linear search does not require the list to be sorted, additional elements can be added and deleted. 36
  • 37. Disadvantage of Linear Search 1. Slow searching of large array. For example, when searching through a database of everyone in the Northern Ireland to find a particular name, it might be necessary to search through 1.8 million names before you found the one you wanted. 2. Inversely, when a key element matches the last element in the array or a key element doesn't matches any element then Linear search algorithm is a worst case. 37
  • 38. Thank You, Next … Binary Search May 03, 2021 Andi Nurkholis, S.Kom, M.Kom Study Program of Informatics Faculty of Engineering and Computer Science SY. 2020-2021