Download presentation
Presentation is loading. Please wait.
Published byAriel Banks Modified over 9 years ago
1
Standard Algorithms –search for an item in an array –count items in an array –find the largest (or smallest) item in an array.
2
You must know 4 Standard Algorithms…….. 1.Linear Search 2.Count Occurrences 3.Find the Minimum 4.Find the Maximum
3
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
4
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
5
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
6
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
7
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.