SlideShare a Scribd company logo
5
Most read
6
Most read
9
Most read
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

PPTX
Python Substrings
PPTX
Software Testing
PPTX
Parallel arrays in python
PPTX
Records in Python
PPTX
File Handling
PPT
Chapter Introduction to Modular Programming.ppt
PPTX
Types of software
PPTX
Compiler vs Interpreter-Compiler design ppt.
Python Substrings
Software Testing
Parallel arrays in python
Records in Python
File Handling
Chapter Introduction to Modular Programming.ppt
Types of software
Compiler vs Interpreter-Compiler design ppt.

What's hot (20)

PPTX
Web application presentation
PPTX
Computer Language Translator
PPSX
Files in c++
PPTX
Variables in python
PPTX
introduction to programming languages
PPT
Lecture# 7 midi file format
PPTX
Operating system components
PPT
Multimedia software tools
PDF
Lesson 03 python statement, indentation and comments
PPTX
Building visual basic application
PPTX
Python: Third-Party Libraries
PPTX
Python strings presentation
PPTX
Language processor
PPTX
Visual Basic Controls ppt
PPTX
function, storage class and array and strings
PPTX
Introduction to C programming
PPTX
History of Computer Programming Languages.pptx
PPTX
Benefits & features of python |Advantages & disadvantages of python
PPTX
Loaders ( system programming )
PPTX
Windows operating system presentation
Web application presentation
Computer Language Translator
Files in c++
Variables in python
introduction to programming languages
Lecture# 7 midi file format
Operating system components
Multimedia software tools
Lesson 03 python statement, indentation and comments
Building visual basic application
Python: Third-Party Libraries
Python strings presentation
Language processor
Visual Basic Controls ppt
function, storage class and array and strings
Introduction to C programming
History of Computer Programming Languages.pptx
Benefits & features of python |Advantages & disadvantages of python
Loaders ( system programming )
Windows operating system presentation
Ad

Similar to Standard Algorithms (20)

PPT
SD & D Standard Algorithms
PPT
1 D Arrays in C++
PPTX
An Introduction To Python - Tables, List Algorithms
PPT
Chap10
PDF
Standard Algorithms
PPTX
Standard algorithms
PPTX
Array ppt
PDF
Array.pdf
PPTX
ADST university of Sussex foundation class
PPTX
LINEAR SEARCH-WPS Office. .pptx
PPT
arrays1.ppt python programme arrays insertion
PPTX
ARRAY PPT.pptx for mca finals placement
PPTX
Arrays In C++
PPTX
DATA STRUCTURE linear search ALGORITHM-PROGRAM
PPTX
Arrays
PPTX
Sorting and searching arrays binary search algorithm
PPTX
Linear and Binary search .pptx
PDF
Acm aleppo cpc training seventh session
PPTX
Lecture_Oct26.pptx
PPTX
Searching techniques
SD & D Standard Algorithms
1 D Arrays in C++
An Introduction To Python - Tables, List Algorithms
Chap10
Standard Algorithms
Standard algorithms
Array ppt
Array.pdf
ADST university of Sussex foundation class
LINEAR SEARCH-WPS Office. .pptx
arrays1.ppt python programme arrays insertion
ARRAY PPT.pptx for mca finals placement
Arrays In C++
DATA STRUCTURE linear search ALGORITHM-PROGRAM
Arrays
Sorting and searching arrays binary search algorithm
Linear and Binary search .pptx
Acm aleppo cpc training seventh session
Lecture_Oct26.pptx
Searching techniques
Ad

More from Forrester High School (20)

PPTX
Program Design
PPTX
Database Evaluation
PPTX
PPTX
Database Query Design
PPTX
Data Dictionary
PPTX
Compound Keys
PPTX
Entity Occurrence Diagrams
PPTX
Entity Relationship Diagrams
PPTX
Database Analysis
PPTX
Software Evaluation
PPTX
Python Predefined Functions
PPTX
Variable Scope
PPTX
Sub-programs
PPT
SDD Predefined Functions
PPT
SDD Cconditional Loops
PPT
SDD Fixed Loops
PPT
SDD Conditional Statements
PPT
SD & D Arithmetic Operators
PPT
N5 security precautions
Program Design
Database Evaluation
Database Query Design
Data Dictionary
Compound Keys
Entity Occurrence Diagrams
Entity Relationship Diagrams
Database Analysis
Software Evaluation
Python Predefined Functions
Variable Scope
Sub-programs
SDD Predefined Functions
SDD Cconditional Loops
SDD Fixed Loops
SDD Conditional Statements
SD & D Arithmetic Operators
N5 security precautions

Recently uploaded (20)

PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Complications of Minimal Access Surgery at WLH
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Classroom Observation Tools for Teachers
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Pharma ospi slides which help in ospi learning
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Microbial diseases, their pathogenesis and prophylaxis
Complications of Minimal Access Surgery at WLH
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Microbial disease of the cardiovascular and lymphatic systems
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
GDM (1) (1).pptx small presentation for students
O5-L3 Freight Transport Ops (International) V1.pdf
Insiders guide to clinical Medicine.pdf
Cell Types and Its function , kingdom of life
Classroom Observation Tools for Teachers
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
human mycosis Human fungal infections are called human mycosis..pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Pharma ospi slides which help in ospi learning
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPH.pptx obstetrics and gynecology in nursing
STATICS OF THE RIGID BODIES Hibbelers.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra

Standard Algorithms