SlideShare a Scribd company logo
1 of 15
STANDARD ALGORITHMS
Higher Computing Science
LINEAR SEARCH
• Linear search searches an array for a specific value
• If the value is found it will return its position in the array
• If the value is not found it will return a message to say so
LINEAR SEARCH: SIMPLE
Pseudocode:
INITIALISE colours array
ASK user FOR search_item
REPEAT with position FOR number of items in array
IF colours[position] = search_item THEN
DISPLAY “Search item found in position ” & position
LINEAR SEARCH: SIMPLE
Python:
LINEAR SEARCH: SIMPLE
Issues:
1. Continues through loop when item found (inefficient)
2. No message if item not found
3. Displays array position rather than actual position
1st item = position 0
2nd item = position 1
etc
4. Loop fixed - 6 times
LINEAR SEARCH: IMPROVED
INITIALISE colours array
SET found TO false
SET position TO 0
ASK user FOR search_item
WHILE position < array length AND found is false DO
IF colours[position] = search_item THEN
SET found TO true
ELSE
ADD 1 TO position
IF found is true THEN
DISPLAY ‘Colour found in position’ & position + 1
ELSE
DISPLAY ‘Colour not found’
LINEAR SEARCH: IMPROVED
COUNT OCCURRENCES
• Count occurrences will count the number of times a specific value
appears in an array
• For example:
[‘A’, ‘B’, ‘C’, ‘C’, ‘A’, ‘A’, ‘B’]
The letter A appears 3 times in the array
COUNT OCCURRENCES
Pseudocode:
INITIALISE colours array
SET occurrences to 0
ASK user FOR search_item
REPEAT WITH counter FOR array length
IF colours[counter] = search_item THEN
ADD 1 TO occurrences
DISPLAY occurrences
COUNT OCCURRENCES
Python:
FIND MAXIMUM / MINIMUM
• Find maximum will return the largest value in a list
• Find minimum will return the smallest value in a list
• Algorithms are almost identical, the main difference is in the IF
statement:
• > comparison (maximum)
• < comparison (minimum)
FIND MAXIMUM
Pseudocode:
INITIALISE heights array
SET maximum TO first array element
REPEAT WITH counter FOR array length
IF heights[counter] > maximum THEN
SET maximum TO heights[counter]
DISPLAY maximum
FIND MAXIMUM
Python:
FIND MINIMUM
Pseudocode:
INITIALISE heights array
SET minimum TO first array element
REPEAT WITH counter FOR array length
IF heights[counter] < minimum THEN
SET minimum TO heights[counter]
DISPLAY minimum
FIND MINIMUM
Python:

More Related Content

What's hot

Algorithm Design Technique
Algorithm Design Technique Algorithm Design Technique
Algorithm Design Technique
Bharat Bhushan
 

What's hot (20)

Arrays in c
Arrays in cArrays in c
Arrays in c
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Pre processor directives in c
Pre processor directives in cPre processor directives in c
Pre processor directives in c
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
 
Python list
Python listPython list
Python list
 
Algorithm Design Technique
Algorithm Design Technique Algorithm Design Technique
Algorithm Design Technique
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
 
Python
PythonPython
Python
 
Recursion
RecursionRecursion
Recursion
 
Rahat &amp; juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhith
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
Interpolation search
Interpolation searchInterpolation search
Interpolation search
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsing
 
Recursion with Python [Rev]
Recursion with Python [Rev]Recursion with Python [Rev]
Recursion with Python [Rev]
 

Similar to Standard Algorithms

Similar to Standard Algorithms (20)

SD & D Standard Algorithms
SD & D Standard AlgorithmsSD & D Standard Algorithms
SD & D Standard Algorithms
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
An Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List AlgorithmsAn Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List Algorithms
 
Chap10
Chap10Chap10
Chap10
 
Standard Algorithms
Standard AlgorithmsStandard Algorithms
Standard Algorithms
 
Standard algorithms
Standard algorithmsStandard algorithms
Standard algorithms
 
Array ppt
Array pptArray ppt
Array ppt
 
Array.pdf
Array.pdfArray.pdf
Array.pdf
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Arrays
ArraysArrays
Arrays
 
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
 
Linear and Binary search .pptx
Linear and Binary search .pptxLinear and Binary search .pptx
Linear and Binary search .pptx
 
Acm aleppo cpc training seventh session
Acm aleppo cpc training seventh sessionAcm aleppo cpc training seventh session
Acm aleppo cpc training seventh session
 
Lecture_Oct26.pptx
Lecture_Oct26.pptxLecture_Oct26.pptx
Lecture_Oct26.pptx
 
Searching techniques
Searching techniquesSearching techniques
Searching techniques
 
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
 
Lists in Python
Lists in PythonLists in Python
Lists in Python
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Data Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithmsData Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithms
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 

More from Forrester High School

More from Forrester High School (20)

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
 
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
 
SDD Predefined Functions
SDD Predefined FunctionsSDD Predefined Functions
SDD Predefined Functions
 
SDD Cconditional Loops
SDD Cconditional LoopsSDD Cconditional Loops
SDD Cconditional Loops
 
SDD Fixed Loops
SDD Fixed LoopsSDD Fixed Loops
SDD Fixed Loops
 
SDD Conditional Statements
SDD Conditional StatementsSDD Conditional Statements
SDD Conditional Statements
 
SD & D Arithmetic Operators
SD & D Arithmetic OperatorsSD & D Arithmetic Operators
SD & D Arithmetic Operators
 
N5 security precautions
N5 security precautionsN5 security precautions
N5 security precautions
 
N5 Code Efficiency
N5 Code EfficiencyN5 Code Efficiency
N5 Code Efficiency
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
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
 
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
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
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
 
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
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
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
 

Standard Algorithms