SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
Standard Algorithms
Linear Search
 A linear search is a search through a list, comparing
 each item in the list with the search criteria

 A linear search returns the position of an item in a
 list, or an appropriate message if the item is not
 found.
Linear Search
Example 1:
Linear search for the number 6
Number 6 is in position 7

Example 2:
Linear search for the number 5
Number 5 is in position 2

Example 3:
Linear search for the number 10
Number 10 is not in the list
Linear Search
Algorithm:

Get search_item

REPEAT for all items in the list
  IF current_item = search_item THEN
        position = current_item_position
        EXIT LOOP
  END IF
END REPEAT

DISPLAY position
Counting Occurrences
Count occurrences of a particular item in a list

Example:
Count occurrences of the number 7
There are 3 occurrences
Counting Occurrences
Algorithm:

Get search_item
occurrences = 0

REPEAT for all items in the list
  IF current_item = search_item THEN
        occurrences = occurrences + 1
  END IF
END REPEAT

DISPLAY occurrences
Finding Maximum / Minimum
Find maximum or minimum number in a list

Example:
Find maximum number
The maximum is 13

Example:
Find minimum number
The minimum is 2
Finding Maximum / Minimum
Algorithm (Maximum)

maximum = 0

REPEAT for all items in the list
  IF current_item > maximum THEN
        maximum = current_item
  END IF
END REPEAT

DISPLAY maximum
Finding Maximum / Minimum
Algorithm (Minimum)

minimum = 999

REPEAT for all items in the list
  IF current_item < minimum THEN
         minimum = current_item
  END IF
END REPEAT

DISPLAY minimum

Contenu connexe

Tendances (20)

V19 join method-c
V19 join method-cV19 join method-c
V19 join method-c
 
Introduction to lists
Introduction to listsIntroduction to lists
Introduction to lists
 
Binary search algorithm
Binary search algorithmBinary search algorithm
Binary search algorithm
 
Python lists
Python listsPython lists
Python lists
 
Dictionaries
DictionariesDictionaries
Dictionaries
 
poornima.coseq
poornima.coseqpoornima.coseq
poornima.coseq
 
Searching linear &amp; binary search
Searching linear &amp; binary searchSearching linear &amp; binary search
Searching linear &amp; binary search
 
Data structure
Data structureData structure
Data structure
 
Rahat &amp; juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhith
 
Standard algorithms
Standard algorithmsStandard algorithms
Standard algorithms
 
Binary search Algorithm
Binary search AlgorithmBinary search Algorithm
Binary search Algorithm
 
computer notes - Data Structures - 37
computer notes - Data Structures - 37computer notes - Data Structures - 37
computer notes - Data Structures - 37
 
list procedures
list procedureslist procedures
list procedures
 
How to use Hlookup find an exact match
How to use Hlookup find an exact match How to use Hlookup find an exact match
How to use Hlookup find an exact match
 
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)
 
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
LINEAR SEARCHLINEAR SEARCH
LINEAR SEARCH
 
Ms excel formulas
Ms excel formulasMs excel formulas
Ms excel formulas
 
MS excel - match function
MS excel - match functionMS excel - match function
MS excel - match function
 
Html web designing using lists
Html web designing using listsHtml web designing using lists
Html web designing using lists
 

Similaire à Standard Algorithms (20)

Searching in c language
Searching in c languageSearching in c language
Searching in c language
 
Chap10
Chap10Chap10
Chap10
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Searching
SearchingSearching
Searching
 
Searching Sorting
Searching SortingSearching Sorting
Searching Sorting
 
MODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingMODULE 5-Searching and-sorting
MODULE 5-Searching and-sorting
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
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
 
Unit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTINGUnit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTING
 
1 class linear and Binary search (3).ppt
1 class linear and Binary search (3).ppt1 class linear and Binary search (3).ppt
1 class linear and Binary search (3).ppt
 
Unit v data structure-converted
Unit  v data structure-convertedUnit  v data structure-converted
Unit v data structure-converted
 
Searching and sorting by B kirron Reddi
Searching and sorting by B kirron ReddiSearching and sorting by B kirron Reddi
Searching and sorting by B kirron Reddi
 
Searching and sorting
Searching  and sortingSearching  and sorting
Searching and sorting
 
Searching techniques
Searching techniquesSearching techniques
Searching techniques
 
Chapter3.pptx
Chapter3.pptxChapter3.pptx
Chapter3.pptx
 
Linear and binary search
Linear and binary searchLinear and binary search
Linear and binary search
 
PROGRAMMING HOMEWORK HELP
PROGRAMMING HOMEWORK HELPPROGRAMMING HOMEWORK HELP
PROGRAMMING HOMEWORK HELP
 
Standard Algorithms
Standard AlgorithmsStandard Algorithms
Standard Algorithms
 
Searching_Sorting.pptx
Searching_Sorting.pptxSearching_Sorting.pptx
Searching_Sorting.pptx
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 

Plus de Forrester High School (20)

Program Design
Program DesignProgram Design
Program Design
 
Database Evaluation
Database EvaluationDatabase Evaluation
Database Evaluation
 
Testing SQL
Testing SQLTesting SQL
Testing SQL
 
SQL
SQLSQL
SQL
 
Database Query Design
Database Query DesignDatabase Query Design
Database Query Design
 
Data Dictionary
Data DictionaryData Dictionary
Data Dictionary
 
Compound Keys
Compound KeysCompound Keys
Compound Keys
 
Entity Occurrence Diagrams
Entity Occurrence DiagramsEntity Occurrence Diagrams
Entity Occurrence Diagrams
 
Entity Relationship Diagrams
Entity Relationship DiagramsEntity Relationship Diagrams
Entity Relationship Diagrams
 
Database Analysis
Database AnalysisDatabase Analysis
Database Analysis
 
Software Evaluation
Software EvaluationSoftware Evaluation
Software Evaluation
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
File Handling
File HandlingFile Handling
File Handling
 
Python Predefined Functions
Python Predefined FunctionsPython Predefined Functions
Python Predefined Functions
 
Python Substrings
Python SubstringsPython Substrings
Python Substrings
 
Variable Scope
Variable ScopeVariable Scope
Variable Scope
 
Sub-programs
Sub-programsSub-programs
Sub-programs
 
Records in Python
Records in PythonRecords in Python
Records in Python
 
Parallel arrays in python
Parallel arrays in pythonParallel arrays in python
Parallel arrays in python
 
SDD Predefined Functions
SDD Predefined FunctionsSDD Predefined Functions
SDD Predefined Functions
 

Dernier

Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Dernier (20)

Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Standard Algorithms

  • 2. Linear Search  A linear search is a search through a list, comparing each item in the list with the search criteria  A linear search returns the position of an item in a list, or an appropriate message if the item is not found.
  • 3. Linear Search Example 1: Linear search for the number 6 Number 6 is in position 7 Example 2: Linear search for the number 5 Number 5 is in position 2 Example 3: Linear search for the number 10 Number 10 is not in the list
  • 4. Linear Search Algorithm: Get search_item REPEAT for all items in the list IF current_item = search_item THEN position = current_item_position EXIT LOOP END IF END REPEAT DISPLAY position
  • 5. Counting Occurrences Count occurrences of a particular item in a list Example: Count occurrences of the number 7 There are 3 occurrences
  • 6. Counting Occurrences Algorithm: Get search_item occurrences = 0 REPEAT for all items in the list IF current_item = search_item THEN occurrences = occurrences + 1 END IF END REPEAT DISPLAY occurrences
  • 7. Finding Maximum / Minimum Find maximum or minimum number in a list Example: Find maximum number The maximum is 13 Example: Find minimum number The minimum is 2
  • 8. Finding Maximum / Minimum Algorithm (Maximum) maximum = 0 REPEAT for all items in the list IF current_item > maximum THEN maximum = current_item END IF END REPEAT DISPLAY maximum
  • 9. Finding Maximum / Minimum Algorithm (Minimum) minimum = 999 REPEAT for all items in the list IF current_item < minimum THEN minimum = current_item END IF END REPEAT DISPLAY minimum