Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Standard Algorithms

5,665 views

Published on

Three standard algorithms:
Linear search
Find occurrences
Find maximum/minimum

Published in: Education, Technology, Business

Standard Algorithms

  1. 1. Standard Algorithms
  2. 2. Linear Search  A linear search is a search through a list, comparing each item in the list with the search criteria  A linear search returns the position of an item in a list, or an appropriate message if the item is not found.
  3. 3. Linear Search Example 1: Linear search for the number 6 Number 6 is in position 7 Example 2: Linear search for the number 5 Number 5 is in position 2 Example 3: Linear search for the number 10 Number 10 is not in the list
  4. 4. Linear Search Algorithm: Get search_item REPEAT for all items in the list IF current_item = search_item THEN position = current_item_position EXIT LOOP END IF END REPEAT DISPLAY position
  5. 5. Counting Occurrences Count occurrences of a particular item in a list Example: Count occurrences of the number 7 There are 3 occurrences
  6. 6. Counting Occurrences Algorithm: Get search_item occurrences = 0 REPEAT for all items in the list IF current_item = search_item THEN occurrences = occurrences + 1 END IF END REPEAT DISPLAY occurrences
  7. 7. Finding Maximum / Minimum Find maximum or minimum number in a list Example: Find maximum number The maximum is 13 Example: Find minimum number The minimum is 2
  8. 8. Finding Maximum / Minimum Algorithm (Maximum) maximum = 0 REPEAT for all items in the list IF current_item > maximum THEN maximum = current_item END IF END REPEAT DISPLAY maximum
  9. 9. Finding Maximum / Minimum Algorithm (Minimum) minimum = 999 REPEAT for all items in the list IF current_item < minimum THEN minimum = current_item END IF END REPEAT DISPLAY minimum

×