Upcoming SlideShare
×

# Standard Algorithms

5,193 views
5,006 views

Published on

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

1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• :(

Are you sure you want to  Yes  No
• OH HEY

Are you sure you want to  Yes  No
Views
Total views
5,193
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
28
2
Likes
1
Embeds 0
No embeds

No notes for slide

### 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