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