SlideShare a Scribd company logo
DATA STRUCTURE
LINEAR SEARCH
M.RAMYA
III-MCA
HCC
Trichy
Searching: Finding the location of item or
printing some message when item is not
found.
SEARCH
LINEAR BINARY
• Linear search: Traversing data sequentially to
locate item is called linear search.
• Ex: Searching an item for operation in array.
• Binary search: Data in array which is sorted in
increasing numerical order or alphabetically.
• Ex: Searching name in telephone directory,
searching words in dictionary.
LINEAR SEARCH
• It test whether the ITEM in DATA is present or
not.
• It test the data in sequential manner.
• It searches the data one by one fully and
returns the ITEM as the result.
• Otherwise, it returns the value 0.
• We see this by ALGORITHM.
Alg:LINEAR(DATA,N,ITEM,LOC)
• Items explanation:
1. DATA --Linear array
2. N --Number of elements
3. ITEM --Elements to find
4. LOC --Location of the item
STEPS:
1. [Insert ITEM at the end] Set DATA[N+1]:=ITEM.
2. [Initialize counter] Set LOC:=1.
3. [Search for ITEM]
Repeat while DATA[LOC]= ITEM:
Set LOC:=LOC+1.
[End if loop]
4. [Successful?]If LOC:=N+1, then ;
Set LOC:=0
5. Exit
EXECUTION WITH EXAMPLE
PARTICULARS:
1. DATA [6] =
2. ITEM=G
Cell
name
A B C D E F
Loc 1 2 3 4 5 6
• To find the item we are first inserting the item
to the end of the list.
• Step 1: DATA[N+1]=ITEM.
Exp:
N=6
DATA[6]=F
DATA[6+1]=G
• So the item is added at LOC[7]
A B C D E F G
1 2 3 4 5 6 7
• Step 2:
Initializing the counter to start the search.
Therefore, LOC=1.
It starts the search from LOC=1{i.e. from
DATA[1]=A}
• Step 3:
WHILE loop is executed till DATA[LOC]=ITEM
From the step 2, LOC=1
A B C D E F G
A B C D E F G
A B C D E F G
A B C D E F G
S
E
A
R
C
H
I
N
G
DATA[LOC] =ITEM
LOC=LOC+1
DATA[LOC] =ITEM, LOC=LOC+1
DATA[LOC] =ITEM
LOC=LOC+1
LOC=1
LOC=2
LOC=3
A B C D E F G
DATA[LOC] =ITEM,
LOC=LOC+1
S
E
A
R
C
H
I
N
G
A B C D E F G
DATA[LOC] =ITEM,
LOC=LOC+1
A B C D E F G
DATA[LOC]
=ITEM,
LOC=LOC+1
LOC=4
LOC=5
LOC=6
Here the item is found
The item ‘G’ is located
So the loop executes until this condition
A B C D E F G
DATA[LOC] =ITEM
LOC=7
• STEP 4:
Originally the location is 6. We added the
item at the end.
So the item is located in 7.
LOC=N+1
We reached the condition then
LOC=0
• STEP 5:
Searching is finished and the algorithm exits.
COMPLEXITY
• Worst Case: The maximum value to search.
• Complexity is measured by f(n).f(n)=n+1
• The average case is measured by probability.
• Here,
• pk – probability that ITEM appears in DATA[K].
• q – probability that ITEM does not appears in
DATA[K].
• Algorithm uses k comparisons when ITEM
appears in DATA[K].
• f(n)=1 . p1 + 2 . p2 + … +n . pn + (n+1) . q
• Suppose, q is very small and ITEm appears in
equal probability, then
q=o and pi=1/n
f(n)=1 . 1/n + 2 . 1/n + … +n . 1/n + (n+1).0
=(1+2+…+n) .1/n
=n(n+1)/2.(1/n)
f(n)=(n+1)/2

More Related Content

What's hot

Sorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithmSorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithm
David Burks-Courses
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
Binary search Algorithm
Binary search AlgorithmBinary search Algorithm
Binary search Algorithm
FazalRehman79
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
sajinis3
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
Zia Ush Shamszaman
 
Python list functions
Python list functionsPython list functions
Python list functions
Mokhtar Ebrahim
 
Searching Sorting
Searching SortingSearching Sorting
Searching Sortingguest2cb109
 
Self-balancing Trees and Skip Lists
Self-balancing Trees and Skip ListsSelf-balancing Trees and Skip Lists
Self-balancing Trees and Skip Lists
Benjamin Sach
 
Binary search
Binary searchBinary search
Binary search
sana younas
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
montazur420
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
Trupti Agrawal
 
Unit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTINGUnit 6 dsa SEARCHING AND SORTING
Data structure unit I part B
Data structure unit I part BData structure unit I part B
Data structure unit I part B
SSN College of Engineering, Kalavakkam
 
Ocw chp6 2searchbinary
Ocw chp6 2searchbinaryOcw chp6 2searchbinary
Ocw chp6 2searchbinary
Prashant Rai
 
Sorting
SortingSorting
searching
searchingsearching
searching
A. S. M. Shafi
 
366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)
Neil Soliven
 
Binary Search
Binary SearchBinary Search
Binary Search
kunj desai
 

What's hot (20)

Sorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithmSorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithm
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Binary search Algorithm
Binary search AlgorithmBinary search Algorithm
Binary search Algorithm
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 
Python list functions
Python list functionsPython list functions
Python list functions
 
Searching Sorting
Searching SortingSearching Sorting
Searching Sorting
 
Self-balancing Trees and Skip Lists
Self-balancing Trees and Skip ListsSelf-balancing Trees and Skip Lists
Self-balancing Trees and Skip Lists
 
Binary search
Binary searchBinary search
Binary search
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
 
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
 
L10 sorting-searching
L10 sorting-searchingL10 sorting-searching
L10 sorting-searching
 
Data structure unit I part B
Data structure unit I part BData structure unit I part B
Data structure unit I part B
 
Ocw chp6 2searchbinary
Ocw chp6 2searchbinaryOcw chp6 2searchbinary
Ocw chp6 2searchbinary
 
Sorting
SortingSorting
Sorting
 
searching
searchingsearching
searching
 
366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Binary Search
Binary SearchBinary Search
Binary Search
 

Viewers also liked

Binary search
Binary searchBinary search
Binary search
ronit gaikwad
 
Linear Search Presentation
Linear Search PresentationLinear Search Presentation
Linear Search Presentation
Markajul Hasnain Alif
 
Linear and Bianry search
Linear and Bianry searchLinear and Bianry search
Linear and Bianry search
Daffodil International University
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
widespreadpromotion
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
NeoClassical
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data Structure
Talha Shaikh
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Mohammed Hussein
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
Kaushal Shah
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 

Viewers also liked (10)

Binary search
Binary searchBinary search
Binary search
 
Linear Search Presentation
Linear Search PresentationLinear Search Presentation
Linear Search Presentation
 
Linear and Bianry search
Linear and Bianry searchLinear and Bianry search
Linear and Bianry search
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data Structure
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
 

Similar to Data structure

arrays
arraysarrays
Linear and binary search
Linear and binary searchLinear and binary search
Linear and binary search
JeoJoyA
 
search_sort.ppt
search_sort.pptsearch_sort.ppt
search_sort.ppt
SwatiHans10
 
COMPUTER PROGRAMMING UNIT 1 Lecture 6
COMPUTER PROGRAMMING UNIT 1 Lecture 6COMPUTER PROGRAMMING UNIT 1 Lecture 6
COMPUTER PROGRAMMING UNIT 1 Lecture 6
Vishal Patil
 
searching in data structure.pptx
searching in data structure.pptxsearching in data structure.pptx
searching in data structure.pptx
chouguleamruta24
 
seaching internal 2 ppt.pptx
seaching internal 2 ppt.pptxseaching internal 2 ppt.pptx
seaching internal 2 ppt.pptx
SubhrasisBiswal1
 
Array operations
Array operationsArray operations
Array operations
Razzaaa
 
Algorithm and Programming (Searching)
Algorithm and Programming (Searching)Algorithm and Programming (Searching)
Algorithm and Programming (Searching)
Adam Mukharil Bachtiar
 
Unit 2 - Quick Sort.pptx
Unit 2 - Quick Sort.pptxUnit 2 - Quick Sort.pptx
Unit 2 - Quick Sort.pptx
CO1IShwetaKidile
 
4- searching.ppt
4- searching.ppt4- searching.ppt
4- searching.ppt
zabihniazai1
 
Data structure lecture 4
Data structure lecture 4Data structure lecture 4
Data structure lecture 4Kumar
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
smruti sarangi
 
search_sort Search sortSearch sortSearch sortSearch sort
search_sort Search sortSearch sortSearch sortSearch sortsearch_sort Search sortSearch sortSearch sortSearch sort
search_sort Search sortSearch sortSearch sortSearch sort
Shanmuganathan C
 
Updated Lab3.docx
Updated Lab3.docxUpdated Lab3.docx
Updated Lab3.docx
AleezaAnjum
 
Array 2
Array 2Array 2
Array 2
Abbott
 
DSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdfDSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdf
MustafaJutt4
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
ssuserd602fd
 
PPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structuresPPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structures
midtushar
 

Similar to Data structure (20)

arrays
arraysarrays
arrays
 
Linear and binary search
Linear and binary searchLinear and binary search
Linear and binary search
 
search_sort.ppt
search_sort.pptsearch_sort.ppt
search_sort.ppt
 
COMPUTER PROGRAMMING UNIT 1 Lecture 6
COMPUTER PROGRAMMING UNIT 1 Lecture 6COMPUTER PROGRAMMING UNIT 1 Lecture 6
COMPUTER PROGRAMMING UNIT 1 Lecture 6
 
searching in data structure.pptx
searching in data structure.pptxsearching in data structure.pptx
searching in data structure.pptx
 
seaching internal 2 ppt.pptx
seaching internal 2 ppt.pptxseaching internal 2 ppt.pptx
seaching internal 2 ppt.pptx
 
Array operations
Array operationsArray operations
Array operations
 
Algorithm and Programming (Searching)
Algorithm and Programming (Searching)Algorithm and Programming (Searching)
Algorithm and Programming (Searching)
 
Unit 2 - Quick Sort.pptx
Unit 2 - Quick Sort.pptxUnit 2 - Quick Sort.pptx
Unit 2 - Quick Sort.pptx
 
4- searching.ppt
4- searching.ppt4- searching.ppt
4- searching.ppt
 
Data structure lecture 4
Data structure lecture 4Data structure lecture 4
Data structure lecture 4
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
 
search_sort Search sortSearch sortSearch sortSearch sort
search_sort Search sortSearch sortSearch sortSearch sortsearch_sort Search sortSearch sortSearch sortSearch sort
search_sort Search sortSearch sortSearch sortSearch sort
 
Data structures
Data structuresData structures
Data structures
 
Array
ArrayArray
Array
 
Updated Lab3.docx
Updated Lab3.docxUpdated Lab3.docx
Updated Lab3.docx
 
Array 2
Array 2Array 2
Array 2
 
DSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdfDSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdf
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
 
PPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structuresPPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structures
 

Recently uploaded

The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 

Recently uploaded (20)

The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 

Data structure

  • 2. Searching: Finding the location of item or printing some message when item is not found. SEARCH LINEAR BINARY
  • 3. • Linear search: Traversing data sequentially to locate item is called linear search. • Ex: Searching an item for operation in array. • Binary search: Data in array which is sorted in increasing numerical order or alphabetically. • Ex: Searching name in telephone directory, searching words in dictionary.
  • 4. LINEAR SEARCH • It test whether the ITEM in DATA is present or not. • It test the data in sequential manner. • It searches the data one by one fully and returns the ITEM as the result. • Otherwise, it returns the value 0. • We see this by ALGORITHM.
  • 5. Alg:LINEAR(DATA,N,ITEM,LOC) • Items explanation: 1. DATA --Linear array 2. N --Number of elements 3. ITEM --Elements to find 4. LOC --Location of the item
  • 6. STEPS: 1. [Insert ITEM at the end] Set DATA[N+1]:=ITEM. 2. [Initialize counter] Set LOC:=1. 3. [Search for ITEM] Repeat while DATA[LOC]= ITEM: Set LOC:=LOC+1. [End if loop] 4. [Successful?]If LOC:=N+1, then ; Set LOC:=0 5. Exit
  • 7. EXECUTION WITH EXAMPLE PARTICULARS: 1. DATA [6] = 2. ITEM=G Cell name A B C D E F Loc 1 2 3 4 5 6
  • 8. • To find the item we are first inserting the item to the end of the list. • Step 1: DATA[N+1]=ITEM. Exp: N=6 DATA[6]=F DATA[6+1]=G • So the item is added at LOC[7] A B C D E F G 1 2 3 4 5 6 7
  • 9. • Step 2: Initializing the counter to start the search. Therefore, LOC=1. It starts the search from LOC=1{i.e. from DATA[1]=A} • Step 3: WHILE loop is executed till DATA[LOC]=ITEM From the step 2, LOC=1
  • 10. A B C D E F G A B C D E F G A B C D E F G A B C D E F G S E A R C H I N G DATA[LOC] =ITEM LOC=LOC+1 DATA[LOC] =ITEM, LOC=LOC+1 DATA[LOC] =ITEM LOC=LOC+1 LOC=1 LOC=2 LOC=3
  • 11. A B C D E F G DATA[LOC] =ITEM, LOC=LOC+1 S E A R C H I N G A B C D E F G DATA[LOC] =ITEM, LOC=LOC+1 A B C D E F G DATA[LOC] =ITEM, LOC=LOC+1 LOC=4 LOC=5 LOC=6
  • 12. Here the item is found The item ‘G’ is located So the loop executes until this condition A B C D E F G DATA[LOC] =ITEM LOC=7
  • 13. • STEP 4: Originally the location is 6. We added the item at the end. So the item is located in 7. LOC=N+1 We reached the condition then LOC=0 • STEP 5: Searching is finished and the algorithm exits.
  • 14. COMPLEXITY • Worst Case: The maximum value to search. • Complexity is measured by f(n).f(n)=n+1 • The average case is measured by probability. • Here, • pk – probability that ITEM appears in DATA[K]. • q – probability that ITEM does not appears in DATA[K]. • Algorithm uses k comparisons when ITEM appears in DATA[K].
  • 15. • f(n)=1 . p1 + 2 . p2 + … +n . pn + (n+1) . q • Suppose, q is very small and ITEm appears in equal probability, then q=o and pi=1/n f(n)=1 . 1/n + 2 . 1/n + … +n . 1/n + (n+1).0 =(1+2+…+n) .1/n =n(n+1)/2.(1/n) f(n)=(n+1)/2