Algorithms

14
Algorithms Sheet 2 Identifying Control Structures

Transcript of Algorithms

Page 1: Algorithms

Algorithms Sheet 2Identifying Control Structures

Page 2: Algorithms

1. Match the terms sequence, binary selection, multiway selection and

iteration to the descriptions that follow:

(a) a decision taken in an algorithm which can go either of two ways

binary selection

(b) decision taken in an algorithm which allows more than two choices

multiway selection

decisiontwo

decisionmore than two

Page 3: Algorithms

1. Match the terms sequence, binary selection, multiway selection and

iteration to the descriptions that follow:

(c) a decision taken in the processing done by an ATM to either withdraw, deposit or check account balance, depending on the key pressed

multiway selection

(d) a loop in a process which repeats the same instructions a number of times

iteration

decision

more than two

repeats

Page 4: Algorithms

1. Match the terms sequence, binary selection, multiway selection and

iteration to the descriptions that follow:

(e) a part of a program where we always add 1 to a counter and then print

sequence

(f) a portion of a program that is done over and over again, and only stops when the count reaches zero

iteration

always

over andover again

Page 5: Algorithms

2. Identify two of the control structures used in each of the following algorithms

(a)Count = 0REPEAT

DoTheLoopAdd 1 to

CountUNTIL Count = 5

sequenceiteration/repetition

sequence

Page 6: Algorithms

2. Identify two of the control structures used in each of the following algorithms

(b)WHILE Count <= 5

Add 1 to Count

DoTheLoopEND WHILE

iteration/repetitionsequence

Page 7: Algorithms

2. Identify two of the control structures used in each of the following algorithms

(c)Get NextVideoIF category = ‘X’

THEN print ‘You cannot watch this!’ELSE DoBorrowProcess

Print detailsEND IF

sequenceselection (binary)

Page 8: Algorithms

2. Identify two of the control structures used in each of the following algorithms

(d)REPEAT

Enter NumberIF Number > highest

THEN set highest to NumberEND IF

UNTIL no more Numbers

iteration/repetitionsequenceselection

Page 9: Algorithms

2. Identify two of the control structures used in each of the following algorithms

(e)WHILE more input

Select inputCASE 1

DoWithdrawalsCASE 2

DoDepositsCASE 3

DoAccountBalanceCASE other

DoErrorProcessEND selectGet input

END WHILE

iteration/repetitionselection (multiway)

sequence

Page 10: Algorithms

3.Identify the

control structure other than sequence used in the following

algorithms:

Page 11: Algorithms

3.Identify the

control structure other than sequence used in the following

algorithms:

Page 12: Algorithms

3.Identify the

control structure other than sequence used in the following

algorithms:

Page 13: Algorithms

3.Identify the

control structure other than sequence used in the following

algorithms:

Page 14: Algorithms

RememberYou need to know how to apply this information, so see me for further help if you think it is

necessary for you.