Standard Algorithms –search for an item in an array –count items in an array –find the largest (or smallest) item in an array.

Slides:



Advertisements
Similar presentations
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Advertisements

Standard Algorithms Find the highest number. ! Your name and today’s date ! Find the maximum Dim numbers(20) As Integer.
Efficiency of Algorithms
Topic 7 Standard Algorithms Learning Objectives Describe and exemplify the following standard algorithms in pseudocode and an appropriate high level.
Data Structures: A Pseudocode Approach with C
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Contd... Objectives Explain the design, use, and operation of a linear list Implement a linear.
Designing Algorithms Csci 107 Lecture 4. Outline Last time Computing 1+2+…+n Adding 2 n-digit numbers Today: More algorithms Sequential search Variations.
Standard Algorithms. 4 Standard Algorithms Input Validation Finding the Maximum / Minimum Counting Occurrences Linear Search.
Copyright © 2012 Pearson Education, Inc. Chapter 8: Searching and Sorting Arrays.
Searching Kruse and Ryba Ch and 9.6. Problem: Search We are given a list of records. Each record has an associated key. Give efficient algorithm.
CPSC 171 Introduction to Computer Science More Efficiency of Algorithms.
Standard Algorithms. Many algorithms appear over and over again, in program after program. These are called standard algorithms You are required to know.
the fourth iteration of this loop is shown here
Algorithms and Pseudocode Bioinformatics. Formulating Problems Clarify input and output elements Requires modeling the problem in some concise form Example:
Data Structures and Algorithms1 B-Trees with Minimum=1 2-3 Trees.
General Computer Science for Engineers CISC 106 Lecture 19 Dr. John Cavazos Computer and Information Sciences 04/06/2009.
Efficiency of Algorithms
Sorting and Searching. Searching List of numbers (5, 9, 2, 6, 3, 4, 8) Find 3 and tell me where it was.
Searching Chapter Chapter Contents The Problem Searching an Unsorted Array Iterative Sequential Search Recursive Sequential Search Efficiency of.
Designing Algorithms February 2nd. Administrativia Lab assignments will be due every Monday Lab access –Searles 128: daily until 4pm unless class in progress.
Designing Algorithms Csci 107 Lecture 3. Designing algorithms Last time –Pseudocode –Algorithm: computing the sum 1+2+…+n –Gauss formula for 1+2+…+n Today.
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
Designing Algorithms Csci 107 Lecture 3. Administrativia Lab access –Searles 128: daily until 4pm unless class in progress –Searles 117: 6-10pm, Sat-Sun.
Algorithms and Efficiency of Algorithms February 4th.
Designing Algorithms Csci 107 Lecture 4.
Chapter 2: Algorithm Discovery and Design
Searching and Sorting Arrays
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 9 Searching.
- SEARCHING - SORTING.  Given:  The array  The search target: the array element value we are looking for  Algorithm:  Start with the initial array.
Adapted from slides by Marie desJardins
Counting the Cost Recall linear search & binary search Number of items Worst CaseExpected Case Number of probes (comparisons) LinearBinary Linear Binary.
Computer Science 101 Fast Searching and Sorting. Improving Efficiency We got a better best case by tweaking the selection sort and the bubble sort We.
Chapter 19: Searching and Sorting Algorithms
Searching and Sorting Chapter Sorting Arrays.
Higher Grade Computing Studies 4. Standard Algorithms Higher Computing Software Development S. McCrossan 1 Linear Search This algorithm allows the programmer.
Starting Out with C++, 3 rd Edition 1 Searching an Arrays.
Chapter Searching and Sorting Arrays 8. Introduction to Search Algorithms 8.1.
+ ARRAYS - SEARCHING - SORTING Dr. Soha S. Zaghloul updated by Rasha M. AL_Eidan 2015.
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
Unit 4, Lesson 4 Using Function Formulas. Objectives Understand function formulas. Understand function formulas. Use the Average and Sum functions. Use.
CSC 211 Data Structures Lecture 13
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Dr. Soha S. Zaghloul2 Let arr be an array of 20 integers. Write a complete program that first fills the array with up to 20 input values. Then, the program.
Searching Chapter 13 Objectives Upon completion you will be able to:
Searching & Sorting Programming 2. Searching Searching is the process of determining if a target item is present in a list of items, and locating it A.
Binary search. What is binary search? We have  a sequence of data, sorted by a relation, and  an element to search for in the list We would like to.
Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
Insertion Sort while some elements unsorted: Using linear search, find the location in the sorted portion where the 1 st element of the unsorted portion.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
 Introduction to Search Algorithms  Linear Search  Binary Search 9-2.
Section 1.7 Comparing Algorithms: Big-O Analysis.
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Objectives Upon completion you will be able to: Explain the design, use, and operation of a linear.
Marr CollegeHigher Software DevelopmentSlide 1 Higher Computing Software Development Topic 4: Standard Algorithms.
while Repetition Structure
Lecture – 2 on Data structures
The Sequential Search (Linear Search)
Standard Algorithms Higher Computing.
Data Structures and Algorithms
Linear and Binary Search
Standard Algorithms Input validation Finding the minimum
Binary Search Counting
The Sequential Search (Linear Search)
Computer Science 101 A Survey of Computer Science
Section – Linear Programming
The Sequential Search (Linear Search)
CMPT 120 Lecture 29 – Unit 5 – Internet and Big Data
Presentation transcript:

Standard Algorithms –search for an item in an array –count items in an array –find the largest (or smallest) item in an array.

You must know 4 Standard Algorithms…….. 1.Linear Search 2.Count Occurrences 3.Find the Minimum 4.Find the Maximum

Linear Search Pseudocode for linear search (version 1) 1.for each element in the array 2. if element = target value then display position set found flag to true. 3. next element 4. If found flag is not true, then display “not found” message

Linear Search(2) Pseudocode for linear search (version 2 – more efficient version) 1.set pointer to 0 2. set found flag to false 3. Loop while (target not found) and (not end of list) 4. If element = target value then display position set found flag to true 5. increment pointer 6. End Loop 7. If found flag is not true then display “not found” message

Counting Occurences Pseudocode for Counting Occurrences 1.set counter = 0 2.for each element in the array 3. if element = target value then add 1 to counter 4.next element

Finding Minimum Pseudocode for Finding minimum 1.set minimum = first element 2.for each element in the array 3. if element < minimum then set minimum = current element 4.next element

Finding Maximum Pseudocode for Finding maximum 1.set maximum = first element 2.for each element in the array 3. if element > maximum then set maximum = current element 4.next element