Computer Science 101 A Survey of Computer Science

Slides:



Advertisements
Similar presentations
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Advertisements

Efficiency of Algorithms
While Loops. Challenge: ● Ask the user a simple math questions ● Continue asking the question until the user gets it right.
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.
@ Zhigang Zhu, CSC212 Data Structure - Section FG Lecture 19 Searching Instructor: Zhigang Zhu Department of Computer Science City College.
Arrays (II) H&K Chapter 8 Instructor – Gokcen Cilingir Cpt S 121 (July 14, 2011) Washington State University.
Match-and-Stop Search Will find FIRST match Use Boolean variable to denote whether a match has been found or not Found initially False If a match is found,
General Computer Science for Engineers CISC 106 Lecture 19 Dr. John Cavazos Computer and Information Sciences 04/06/2009.
Efficiency of Algorithms
Chapter 2: Algorithm Discovery and Design
Efficiency of Algorithms February 19th. Today Binary search –Algorithm and analysis Order-of-magnitude analysis of algorithm efficiency –Review Sorting.
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.
Chapter 2: Design of Algorithms
Designing Algorithms Csci 107 Lecture 4.
Chapter 2: Algorithm Discovery and Design
ALGORITHMS AND FLOWCHARTS
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 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
Efficiency of Algorithms Csci 107 Lecture 7. Last time –Data cleanup algorithms and analysis –  (1),  (n),  (n 2 ) Today –Binary search and analysis.
Sequences Jordi Cortadella Department of Computer Science.
Searching Given a collection and an element (key) to find… Output –Print a message (“Found”, “Not Found) –Return a value (position of key ) Don’t modify.
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.
Standard Algorithms –search for an item in an array –count items in an array –find the largest (or smallest) item in an array.
L. Grewe.  An array ◦ stores several elements of the same type ◦ can be thought of as a list of elements: int a[8]
CSC 211 Data Structures Lecture 13
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
Computer Science 101 Introduction to Sorting. Sorting One of the most common activities of a computer is sorting data Arrange data into numerical or alphabetical.
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
1 CompSci 105 SS 2005 Principles of Computer Science Lecture 6: Recursion Lecturer: Santokh Singh Assignment 1 due tomorrow. Should have started working.
Searching Algorithms Sequential Search – inspects every items in a sequential manner. Example, in an array, all values in the array are checked from index.
Computer Science 101 Fast Algorithms. What Is Really Fast? n O(log 2 n) O(n) O(n 2 )O(2 n )
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
Data Structures and Algorithms Searching Algorithms M. B. Fayek CUFE 2006.
Computer Science 101 A Survey of Computer Science Sorting.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Searching Given a collection and an element (key) to find… Output
- Standard C Statements
GC211Data Structure Lecture2 Sara Alhajjam.
Computer Science 101 A Survey of Computer Science
Chapter 4: Control Structures
Materials (detailed list) Quantity (be specific)
Numbering System TODAY AND TOMORROW 11th Edition
ALGORITHMS & FLOWCHARTING II
Lecture 2: Introduction to Algorithms
COMS W1004 Introduction to Computer Science and Programming in Java
ALGORITHMS AND FLOWCHARTS
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]
CSc 110, Spring 2017 Lecture 39: searching.
CSC212 Data Structure - Section RS
Computer Science 111 Fundamentals of Computer Programming I
Algorithm Discovery and Design
ALGORITHMS AND FLOWCHARTS
Search,Sort,Recursion.
Computer Science Core Concepts
Search,Sort,Recursion.
Type your project title here Your name Your teacher’s name Your school
The structure of programming
Discovery and Design of Algorithms
CSC212 Data Structure - Section KL
COMP108 Algorithmic Foundations Searching
Dale Roberts, Lecturer IUPUI
Computer Science 101 Survey of Computer Science
Program: Mini Phone Book 2/11/2016
COMP108 Algorithmic Foundations Searching
Sorting and Complexity
Presentation transcript:

Computer Science 101 A Survey of Computer Science Searching

Searching Searching is one of the most common operations of computing Search for student record based on id Search for “best” item based on some criteria Search for airline reservations Clearly we know all there is to know about searching

Or do we?

Or do we?

Or do we?

Or do we?

Or do we?

Sequential Search Algorithm Given: List of values v1,v2,…,vn Target value, T Output: Information about T if in list and message if T is not in list Strategy: Use variables: i for current location in list Found to indicate whether T located or not Initialize i=1, Found=false Pass through the list sequentially

Sequential Search-Names/Phone No’s Given: Names N1,N2,…Nn Target NAME Phone No’s T1,T2,…,Tn Output: Phone number of NAME Note: We’ll use this as an example for sequential search, but if the names are in alphabetical order there is a much better algorithm.

Names/Phone No’s Algorithm Set Found to false Set i to 1 While not Found and i ≤ last position Do if Ni = NAME then Print Ti Set Found to true else Set i to i+1 end-of-loop if Found=false then Print ‘Sorry, not in directory’ Stop

Algorithm to Find Largest Given: List of numbers A1,A2,…,An Output: Largest value in list and its position Strategy: Use variables: i for current location in list Largest for largest value found so far LargeLoc for position of largest found so far Initialize Largest=A1,LargeLoc=1,i=2 Pass through the list sequentially

Algorithm to Find Largest (cont) Set Largest to A1 Set LargeLoc to 1 Set i to 2 While i  n do if Ai > Largest then Set Largest to Ai Set LargeLoc to i Set i to i+1 end-of-loop Print Largest, LargeLoc Stop

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 9 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 9 1 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 9 1 2 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 9 1 2 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 9 1 2 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 9 1 3 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 9 1 3 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 9 1 3 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 9 1 3 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 1 3 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 3 3 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 3 4 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 3 4 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 3 4 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 3 4 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 3 5 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 3 5 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 3 5 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 3 5 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 3 6 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 3 6 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 3 6 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 12 3 6 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 3 6 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 6 6 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 6 7 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 6 7 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 6 7 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 6 7 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 6 8 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 6 8 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 6 8 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 6 8 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 6 9 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 6 9 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 6 9 8

Example: 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 1 2 3 4 5 6 7 8 9 5 12 6 3 15 10 14 1. Set Largest to A1 2. Set LargeLoc to 1 3. Set i to 2 4. While i  n do 5. if Ai > Largest then 6. Set Largest to Ai 7. Set LargeLoc to i 8. Set i to i+1 9. end-of-loop 10. Print Largest, LargeLoc 11. Stop Largest LargeLoc i n 15 6 9 8 OUTPUT: 15, 6

I guess we could call them Cow1, Cow2, Cow3, ...