Upcoming SlideShare
×

# Algorithms

1,366 views

Published on

Explantion of algorithms with examples

Published in: Education, Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
1,366
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
59
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Algorithms

1. 1. Algorithms Sheet 2 Identifying Control Structures
2. 2. 1. Match the terms sequence , binary selection , multiway selection and iteration to the descriptions that follow: <ul><li>a decision taken in an algorithm which can go either of two ways </li></ul><ul><li>binary selection </li></ul><ul><li>(b) decision taken in an algorithm which allows more than two choices </li></ul><ul><li>multiway selection </li></ul>decision two decision more than two
3. 3. 1. Match the terms sequence , binary selection , multiway selection and iteration to the descriptions that follow: <ul><li>a decision taken in the processing done by an ATM to either withdraw, deposit or check account balance, depending on the key pressed </li></ul><ul><li>multiway selection </li></ul><ul><li>(d) a loop in a process which repeats the same instructions a number of times </li></ul><ul><li>iteration </li></ul>decision more than two repeats
4. 4. 1. Match the terms sequence , binary selection , multiway selection and iteration to the descriptions that follow: <ul><li>(e) a part of a program where we always add 1 to a counter and then print </li></ul><ul><li>sequence </li></ul><ul><li>(f) a portion of a program that is done over and over again, and only stops when the count reaches zero </li></ul><ul><li>iteration </li></ul>always over and over again
5. 5. 2. Identify two of the control structures used in each of the following algorithms <ul><li>(a) </li></ul><ul><li>Count = 0 </li></ul><ul><li>REPEAT </li></ul><ul><li>DoTheLoop </li></ul><ul><li>Add 1 to Count </li></ul><ul><li>UNTIL Count = 5 </li></ul><ul><li>sequence </li></ul><ul><li>iteration/repetition </li></ul><ul><li>sequence </li></ul>
6. 6. 2. Identify two of the control structures used in each of the following algorithms <ul><li>(b) </li></ul><ul><li>WHILE Count <= 5 </li></ul><ul><li>Add 1 to Count </li></ul><ul><li>DoTheLoop </li></ul><ul><li>END WHILE </li></ul><ul><li>iteration/repetition </li></ul><ul><li>sequence </li></ul>
7. 7. 2. Identify two of the control structures used in each of the following algorithms <ul><li>(c) </li></ul><ul><li>Get NextVideo </li></ul><ul><li>IF category = ‘X’ </li></ul><ul><li>THEN print ‘You cannot watch this!’ </li></ul><ul><li>ELSE DoBorrowProcess </li></ul><ul><li> Print details </li></ul><ul><li>END IF </li></ul><ul><li>sequence </li></ul><ul><li>selection (binary) </li></ul>
8. 8. 2. Identify two of the control structures used in each of the following algorithms <ul><li>(d) </li></ul><ul><li>REPEAT </li></ul><ul><li>Enter Number </li></ul><ul><li>IF Number > highest </li></ul><ul><li>THEN set highest to Number </li></ul><ul><li>END IF </li></ul><ul><li>UNTIL no more Numbers </li></ul><ul><li>iteration/repetition </li></ul><ul><li>sequence </li></ul><ul><li>selection </li></ul>
9. 9. 2. Identify two of the control structures used in each of the following algorithms <ul><li>(e) </li></ul><ul><li>WHILE more input </li></ul><ul><li>Select input </li></ul><ul><li>CASE 1 </li></ul><ul><li>DoWithdrawals </li></ul><ul><li>CASE 2 </li></ul><ul><li>DoDeposits </li></ul><ul><li>CASE 3 </li></ul><ul><li>DoAccountBalance </li></ul><ul><li>CASE other </li></ul><ul><li>DoErrorProcess </li></ul><ul><li>END select </li></ul><ul><li>Get input </li></ul><ul><li>END WHILE </li></ul><ul><li>iteration/repetition </li></ul><ul><li>selection (multiway) </li></ul><ul><li>sequence </li></ul>
10. 10. 3. Identify the control structure other than sequence used in the following algorithms:
11. 11. 3. Identify the control structure other than sequence used in the following algorithms:
12. 12. 3. Identify the control structure other than sequence used in the following algorithms:
13. 13. 3. Identify the control structure other than sequence used in the following algorithms:
14. 14. Remember <ul><li>You need to know how to apply this information, so see me for further help if you think it is necessary for you. </li></ul>