Answer all questions in the spaces provided. 1 Describe how the

Answer all questions in the spaces provided.
1 Describe how the elements in a non-empty queue are reversed with the aid of a stack.
.....................................................................................................................................................
.....................................................................................................................................................
.....................................................................................................................................................
.....................................................................................................................................................
.....................................................................................................................................................
(4 marks)
4
$VWDFNPD\EHLPSOHPHQWHGE\XVLQJHLWKHUDQDU UD\RUDOLQNHGOLVW
D *LYHDGLVDGYDQWDJHRI
L DQDUUD\LPSOHPHQWDWLRQ
(1 mark)
LL DOLQNHGOLVWLPSOHPHQWDWLRQ
(1 mark)
E 8QGHUZKDWFLUFXPVWDQFHVZRXOGLWEHPRUHDSSURSULDWHWRXVH
L DQDUUD\
(1 mark)
LL DOLQNHGOLVW
(1 mark)
4
LEAVE
MARGIN
BLANK
3 $QLQWHJHUDUUD\$FRQWDLQVWKHIROORZLQJLWHPV
$
>@
>@
>@
>@
>@
>@
>@
>@
>@
7KHRSHUDWRU',9SHUIRUPVLQWHJHUGLYLVLRQ[',9\FDOFXODWHVKRZPDQ\WLPHV\GLYLGHV
H[DFWO\LQWR[)RUH[DPSOH',9 D 'U\UXQWKHIROORZLQJDOJRULWKPE\FRPSOHWLQJWKHWUDFHWDEOH7DEOH
Number ← 12
Lower ← 1
Upper ← 9
While Lower<Upper
Current ← (Lower+Upper)DIV 2
If Number >= A [Current] Then Lower ← Current
If Number <= A [Current] Then Upper ← Current
EndWhile
Return Current
7DEOH
1XPEHU
/RZHU
8SSHU
&XUUHQW
9DOXHUHWXUQHG
(8 marks)
E :KDWLVWKHSXU SRVHRIWKLVDOJRULWKP"
(1 mark)
LEAVE
MARGIN
BLANK
4
)LJXUH
)URQW
'DWD
5HDU
1H[W
QRGH
'DWD
1H[W
'DWD
QRGH
1H[W
QRGH
D $VVXPHDTXHXHLVLPSOHPHQWHGDVDOLQN HGOLVWXVLQJSRLQWHUVDVLQ )LJXUH
*LYHWKHWKUHH VWHSVUHTXLUHGWRUHPRYHDQRGHIURPWKHIURQWRIWKHTXHXHDQGUHFR YHU
WKHPHPRU\VSDFHRFFXSLHGE\WKHQRGH
(3 marks)
E $VHWRIRSHUDWLRQVDUHGHI LQHGWRPDQLSXODWHWKHFRQWHQWVRIWKHTXHXH $VZHOODV
Remove WKHVHLQFOXGHFrontItem DQGIsQueueEmpty
1DPHDQRWKHURSHUDWLRQWKDWZRXOGEHHVVHQWLDOWRXVHWKLVTXHXH
(1 mark)
F 7KHTXHXHFRXOGEHLPSOHPHQWHGXVLQJDQDU UD\LQVWHDGRIDOLQNHGOLVW
L :KDWDGGLWLRQDORSHUDWLRQZLOOEHUHTXLUHGLIWKHTXHXHLVLPSOHPHQWHGXVLQJDQ
DUUD\"
(1 mark)
LL *LYHRQH DGYDQWDJHRIDUUD\LPSOHPHQWDWLRQ
(1 mark)
LLL *LYHWZRGLVDGYDQWDJHVRIDUUD\LPSOHPHQWDWLRQ
(2 marks)
LEAVE
MARGIN
BLANK
$linear search DQGDbinary search DUHWZRGLIIHUHQWPHWKRGVRIVHDUFKLQJDQRUGHUHGOLVW
$JLYHQOLVWFRQWDLQVLWHPV
D
L :KDWLVWKHPD[LPXPQXPEHURILWHPVDFFHVVHGZ KHQVHDUFKLQJIRUDSDU WLFXODU
LWHPIURPWKHJLYHQOLVWXVLQJDOLQHDUVHDUFK"
(1 mark)
LL ([SODLQ\RXUDQVZHU
(1 mark)
E
L :KDWLVWKHPD[LPXPQXPEHURILWHPVDFFHVVHGZ KHQVHDUFKLQJIRUDSDU WLFXODU
LWHPIURPWKHJLYHQOLVWXVLQJDELQDU \VHDUFK"
(1 mark)
LL ([SODLQ\RXUDQVZHU
(1 mark)
F $QLQWHJHUDUUD\$FRQWDLQVWKHIROORZLQJLWHPV
>@
>@
>@
>@
>@
$
L 'U\UXQWKHIROORZLQJDOJRULWKPE\FRPSOHWLQJWKHWUDFHWDEOH7DEOH
¨
For Count1
1 To 4
For Count2
1 To 4
If A[Count2] > A[Count2 + 1] Then
Temp
A[Count2]
A[Count2]
A[Count2 + 1]
A[Count2 + 1]
Temp
EndIf
EndFor
EndFor
¨
¨
¨
¨
LEAVE
MARGIN
BLANK
7DEOH
&RXQW
&RXQW
7HPS
±
±
±
>@
>@
$
>@
>@
>@
(5 marks)
LL :KDWLVWKHSXU SRVHRIWKLVDOJRULWKP"
(1 mark)
LLL 6XJJHVWRQH ZD\WKHDOJRULWKPFRXOGEHLPSURYHG
(1 mark)
LEAVE
MARGIN
BLANK
6 $WUHHKDVWKHIROORZLQJIXQFWLRQVGHI LQHG
5RRW9DOXH7 5HWXUQVWKHFRQWHQWVRIWKHURRWQRGHRIWKHWUHH 7
/HIW&KLOG7 5HWXUQVWKHOHIWFKLOGRIWKHURRWQRGHRIWKHWUHH 7
5LJKW&KLOG7 5HWXUQVWKHULJKWFKLOGRIWKHURRWQRGHRIWKHWUHH 7
$UHFXUVLYHO\GHILQHGSURFHGXUH3ZLWKDWUHHDVDSDUDPHWHULVGHI LQHGEHORZ
Procedure P (T)
If LeftChild(T) exists
then P(LeftChild(T))
Output RootValue(T)
If RightChild(T) exists
then P(RightChild(T))
EndProc
D :KDWLVPHDQWE\UHFXUVLYHO\GHILQHG"
(1 mark)
E
L &RPSOHWH7DEOH E\GU\UXQQLQJWKHSURFHGXUHFDOO37IRUWKHWUHH 7JLYHQ
EHORZ
0-DQ&37
Page 54 of 149
LEAVE
MARGIN
BLANK
7DEOH
3URFHGXUH&DOO
7
2XWSXW
3
(6 marks)
LL :KDWGRHVSURFHGXUH3GHVFULEH"
(2 marks)
7XUQRYHU
▲
0-DQ&37
LEAVE
MARGIN
BLANK
7 )RUDQREMHFWRULHQWHGSURJUDPWRVWRUHDQGUHWULHYHGHWDLOVRIDFRPSDQ\¶VYHKLFOHVD
9HKLFOHFODVVLVQHHGHG 7ZRVXEFODVVHVKDYHEHHQLGHQWLI LHG&DU DQG9DQZKLFKKDYH
LQKHULWDQFHUHODWLRQVKLSVZLWKFODVV9HKLFOH
D 'UDZDQLQKHULWDQFHGLDJUDPIRUWKHVHFODVVHV
(2 marks)
E 7KH9HKLFOHFODVVKDVGDWDI LHOGV5HJLVWUDWLRQ1XPEHU0DNH&RORXU
7KHFODVVGHI LQLWLRQIRU9HKLFOHLV
Vehicle = Class
Public
Procedure SetVehicleDetails
Function
GetRegistrationNumber
Function
GetMake
Function
GetColour
Private
RegistrationNumber : String
Make : String
Colour : String
End
:KLOHSUHVHUYLQJWKHSULYDWHVWDWXVRIWKH&RORXUI LHOGZKDWPRGLILFDWLRQZRXOG\RX
PDNHWRWKLVFODVVGHI LQLWLRQLQRUGHUWRDOORZWKHFRORXURIWKHY HKLFOHWREHFKDQJHG"
(2 marks)
Page 58 of 149
LEAVE
MARGIN
BLANK
F 7KH9DQFODVVKDVDGGLWLRQDOSULYDWHGDWDI LHOGV
●
●
&DSDFLW\WKDWUHSUHVHQWVWKHZHLJKWWKDWFDQEHFDU ULHGLQNLORJUDPV
7DLO/LIWWKDWUHSUHVHQWVZKHWKHUWKHYDQKDVDWDLOOLIWRUQRW
:ULWHWKHFODVVGHI LQLWLRQIRU9DQ
(6 marks)
7XUQRYHUIRUWKHQH[WTXHVWLRQ
LEAVE
MARGIN
BLANK
8 D
6WDWH WZR DGYDQWDJHVRIWKHREMHFWRULHQWHGDSSURDFKWRSUR
VWUXFWXUHGDSSURDFKWRSURJUDPGHVLJQ
JUDPGHVLJQR YHUWKH
(2 marks)
E $JROIFOXEN HHSVGHWDLOVRILWVPHPEHUV(DFKPHPEHUKDVDXQLTXHPHPEHUVKLS
QXPEHUI LUVWQDPHVXU QDPHDQGWHOHSKRQHQXPEHUUHFRUGHG 7KUHHFODVVHVKDYHEHHQ
LGHQWLILHG
0HPEHU
0LG:HHN0HPEHU
)XOO0HPEHU
7KHFODVVHVMidWeekMember DQGFullMember DUHUHODWHGE\VLQJOHLQKHULWDQFHWRWKH
FODVV0HPEHU
'UDZDQLQKHULWDQFHGLDJUDPIRUWKHJLYHQFODVVHV
(2 marks)
LEAVE
MARGIN
BLANK
F 3URJUDPVWKDWXVHREMHFWVRIWKHFODVV Member QHHGWRDGGDQH ZPHPEHU¶VGHWDLOV
DPHQGDPHPEHU¶VGHWDLOVDQGVKRZDPHPEHU¶VGHWDLOV1RRWKHUIRU PRIDFFHVVLVWR
EHDOORZHG:ULWHDFODVVGHI LQLWLRQIRUWKLVFODVV
0HPEHU &ODVV
(QG
(4 marks)
8
▲
7XUQRYHU
)RUDQREMHFWRULHQWHGSUR JUDPWRVWRUHDQGFDOFXODWHSD \UROOGHWDLOVIRUDQRU JDQLVDWLRQDQ
(PSOR\HHFODVVLVQHHGHG$VXEFODVVKDVEHHQLGHQWLI LHG +RXUO\3DLG(PSOR\HHZKLFKKDV
DQLQKHULWDQFHUHODWLRQVKLSZLWKFODVV (PSOR\HH
D 'UDZDQLQKHULWDQFHGLDJUDPIRUWKHVHFODVVHV
(2 marks)
E :KDWLVSRO\PRUSKLVP"
(1 mark)
F 7KH (PSOR\HH FODVVKDVGDWDI LHOGV Name, National Insurance Number, Annual Pay,
Gross Pay To Date
7KHFODVVGHI LQLWLRQIRU(PSOR\HH LV
TEmployee = Class
Public
Procedure AddNewEmployee
Procedure AmendEmployeeDetails
Procedure PrintPaySlip
Procedure CalculatePay
Private
Name : String
NationalInsuranceNumber : String
Annual Pay : Currency
GrossPayToDate : Currency
End
LEAVE
MARGIN
BLANK
0RQWKO\SD\IRUDQHPSOR \HHREMHFWRI 7(PSOR\HH FODVVGHI LQLWLRQLVFDOFXODWHGGLI IHUHQWO\
IURPWKHPRQWKO\SD\IRUDQHPSOR\HHREMHFWRI7+RXUO\3DLG(PSOR\HH FODVVGHILQLWLRQ
,QWKHFDVHRIDQHPSOR\HHREMHFWRIFODVVGHI LQLWLRQ
●
7+RXUO\3DLG(PSOR\HHPRQWKO \SD \LVFDOFXODWHGE \PXOWLSO \LQJQXPEHURIKRXUV
ZRUNHGLQPRQWKE\KRXUO\SD\UDWH
●
7(PSOR\HHPRQWKO\SD\LVFDOFXODWHGE\GLYLGLQJWKHDQQXDOSD\E\
$QKRXUO\SDLGHPSOR\HHREMHFWQHHGVRQHDGGLWLRQDORSHUDWLRQZKLFKFROOHFWVWKHQXPEHURI
KRXUVZRUNHGLQDPRQWK
:ULWHWKHFODVVGHI LQLWLRQ7+RXUO\3DLG(PSOR\HH
(6 marks)
9
785129(5)257+(1(;748(67,21
▲
7XUQRYHU
10 $recursively-defined SURFHGXUH%ZKLFKWDNHVDQLQWHJHUDVLWVVLQJOHSDUDPHWHU LVGHI LQHG
EHORZ7KHRSHUDWRUV',9DQG02'SHUIRU PLQWHJHUDULWKPHWLF
[',9\FDOFXODWHVKRZPDQ\WLPHV\GLYLGHVH[DFWO\LQWR[)RUH[DPSOH',9 [02'\FDOFXODWHVWKHUHPDLQGHUWKDWUHVXOWV) RUH[DPSOH02' 3URFHGXUH% 1XPEHU
,I1XPEHU 251XPEHU 7KHQ3ULQW1XPEHU
(OVH
% 1XPEHU',9
3ULQW1XPEHU02'
(QG,I
(QG3URFHGXUH
D :KDWLVPHDQWE\UHFXUVLYHO\GHILQHG"
(1 mark)
E :K\LVDVWDFNQHFHVVDU \WRH[HFXWHSURFHGXUH%UHFXUVLYHO\"
(1 mark)
F 'U\UXQWKHSURFHGXUHFDOOB(53) VKRZLQJFOHDUO\WKHYDOXHVRIWKHSDUDPHWHUDQGWKH
SULQWHGRXWSXWIRUWKHVL[FDOOVRI B
&DOO
1XPEHU
3DUDPHWHU
3ULQWHG2XWSXW
(6 marks)
G :KDWSURFHVVGRHVSURFHGXUH%GHVFULEH" (1 mark)
▲
7XUQRYHU
9
LEAVE
MARGIN
BLANK
11 :ULWHGR ZQWKHFRPSDULVRQVQHHGHGWRORRNXS
IROORZLQJOLVW
Newcastle XVLQJDELQDU \VHDUFKRQWKH
%LUPLQJKDP&RYHQWU\/LYHUSRRO0DQFKHVWHU1HZFDVWOH6KHIILHOG<RUN
(3 marks)
12
D +LJKOHYHOODQJXDJHVFDQEHFODVVLI LHGDVimperative, declarative, event-driven
:KDWLVPHDQWE\HDFK RIWKHVHWHUPV"*LYHDQH[DPSOHRIHDFKODQJXDJH
L ,PSHUDWLYH
([DPSOH
(2 marks)
LL 'HFODUDWLYH
([DPSOH
(2 marks)
LLL (YHQWGULYHQ
([DPSOH
(2 marks)
E
L ,QREMHFWRULHQWHGSURJUDPPLQJZKDWLVPHDQWE\HQFDSVXODWLRQ"
(1 mark)
0&37
3
Page 106 of 149
LEAVE
MARGIN
BLANK
LL )RUDQREMHFWRULHQWHGSUR JUDPWRVWRUHDQGGLVSOD \SHUVRQDOGHWDLOVRIPHPEHUV
RIDJROIFOXED0HPEHUFODVVQHHGVWREHGHFODUHGZLWKWKHSURSHU WLHV6XUQDPH
)LUVW1DPH7HOHSKRQH1XPEHU+DQGLFDSPXVWEHDZ KROHQXPEHU
:ULWHDFODVVGHI LQLWLRQIRUWKHFODVV0HPEHUWRDOORZWKHSURJUDPWRXVHREMHFWV
RIWKLVFODVVWRDGGDQH ZPHPEHU¶VGHWDLOVDPHQGDPHPEHU¶VGHWDLOVGLVSOD\D
PHPEHU¶VGHWDLOV1RRWKHUIRU PRIDFFHVVLVWREHDOOR ZHG
(4 marks)
11
785129(5)257+(1(;748(67,21
▲
7XUQRYHU
0&37
LEAVE
MARGIN
BLANK
13 An algebraic expression is represented in a binary tree as follows.
(a) On the above diagram, circle and label the root of this tree, a branch and a leaf node.
(3 marks)
(b) In the spaces below, draw the left sub-tree and the right sub-tree of this tree.
left sub-tree
right sub-tree
(2 marks)
(c) What is the result if this tree is printed using in-order traversal?
...........................................................................................................................................
(3 marks)
8
TURN OVER FOR THE NEXT QUESTION
▲
Turn over
LEAVE
MARGIN
BLANK
14 The list Days contains the following representation of the days of the week.
[Sun, Mon, Tue, Wed, Thu, Fri, Sat]
The table below shows some functions which take a list as their single argument and return a
result which is either an element of a list, another list, or a Boolean value.
Head(list) – returns the element at the head of list (e.g. Head(Days)→ Sun)
if list is non-empty otherwise it reports an error.
Tail(list) – returns a new list containing all but the first element of the original
list (e.g. Tail(Days)→ [Mon, Tue, Wed, Thu, Fri, Sat]) if list is non-empty
otherwise it reports an error.
Empty(list) – returns True if list is the empty list or False otherwise.
The empty list is denoted by [].
(a) What result is returned when the following function calls are made?
(i) Head (Tail(Days)).....................................................................................................
(1 mark)
(ii) Tail ([(Head(Days)]).................................................................................................
(1 mark)
(iii) Empty(Tail(Tail(Tail(Days)))) ..................................................................................
(1 mark)
(b) Explain why it is faster to access these elements if the above data is stored as a one
dimensional array.
...........................................................................................................................................
...........................................................................................................................................
(2 marks)
5
Page 118 of 149
15 A binary search and a linear search are two different methods of searching a list.
A given list contains 137 items.
(a)
(i) What is the maximum number of items accessed when searching for a particular
item from the given list using a binary search?
..................................................................................................................................
(ii) Explain your answer.
..................................................................................................................................
..................................................................................................................................
(b)
(i) What is the maximum number of items accessed when searching for a particular
item from the given list using a linear search?
..................................................................................................................................
(ii) Explain your answer.
..................................................................................................................................
..................................................................................................................................
(4 marks)
4
Turn over
16
(a)
(i) The birds Pheasant, Teal, Widgeon, Partridge, Woodpigeon are entered, in the
order given, into a linked list so that they may be processed alphabetically. Draw
this linked list.
(2 marks)
(ii) Redraw the list after two additional items, Grouse and Snipe, are added.
(2 marks)
(b) This linked list is said to be a dynamic structure. What is meant by the term dynamic
structure?
...........................................................................................................................................
...........................................................................................................................................
(2 marks)
(c) Explain how memory was allocated for the two additional data items.
...........................................................................................................................................
...........................................................................................................................................
(2 marks)
17 For the expression 3+x the binary tree stores + at the root, 3 at the left hand node and x at the
right hand node. If the nodes of this tree are printed as the tree is traversed, what will be
printed when the traversal is
8
(a) pre-order; ........................................
(b) in-order; ..........................................
(c) post-order? ......................................
(3 marks)
3
18
(a)
State two advantages of the object-oriented approach to program design over
a structured approach to program design.
1 ........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
...........................................................................................................................................
(2 marks)
(b) A sailing club has both junior and senior members. Each member has a unique
membership number, a name and an address recorded. Three classes have been
identified:
Member
JuniorMember
SeniorMember
The classes JuniorMember and SeniorMember are related, by single inheritance, to the
class Member.
Draw an inheritance diagram for the given classes.
(2 marks)
(c) Programs that use objects of the class Member need to add a new member’s details,
amend a member’s details, and show a member’s details. No other form of access is to
be allowed. Write a class definition for this class.
Member = Class
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
End;
(4 marks)
8
LEAVE
MARGIN
BLANK
19 The following data is input to a program, in alphabetical order, and is stored.
Anne
Bob
Claire
Dean
(a) Draw a diagram to show how this data is stored for:
(i) a stack;
(ii) a queue.
(4 marks)
(b) One item is retrieved from these data structures for processing, and Eden is input.
Draw the diagrams of this new situation for:
(i) the stack;
(ii) the queue.
(3 marks)
(c) Why are queues in computer systems usually implemented as circular queues?
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
(2 marks)
▲
Turn over
9
LEAVE
MARGIN
BLANK
20 A supermarket has a section labelled ‘Bottled Water’. Bottled water comes as ‘still bottled
water’ or ‘carbonated bottled water’.
In an object-oriented program, ‘bottled water’, ‘still bottled water’ and ‘carbonated bottled
water’ are three defined classes. The classes ‘still bottled water’ and ‘carbonated bottled
water’ are related, by single inheritance, to ‘bottled water’.
(a) What is meant here by
(i) class? ........................................................................................................................
..................................................................................................................................
(ii) inheritance? ..............................................................................................................
..................................................................................................................................
(2 marks)
(b) Draw an inheritance diagram for the given classes.
(3 marks)
(c) Give three advantages of the object-oriented approach to programming over a
structured approach.
1 .........................................................................................................................................
...........................................................................................................................................
2 .........................................................................................................................................
...........................................................................................................................................
3 .........................................................................................................................................
...........................................................................................................................................
(3 marks)
8
LEAVE
MARGIN
BLANK
21 A procedure to process an array of numbers is defined as follows.
Procedure P(Number)
Repeat
X ← StartofArray
Flag ← False
Repeat
If Number(X) > Number (X+1)
Then
Begin
Temp ← Number(X)
Number (X) ← Number (X+1)
Number(X+1) ← Temp
Flag ← True
End
X←X+1
Until EndofArray
Until Flag = False
Endproc
The array number, containing 17, 11, 21, 9, 23, 15, is to be processed by this procedure.
(a) List the array after the outer Repeat loop has been executed once.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
(2 marks)
(b) What algorithm does the procedure P describe?
...........................................................................................................................................
(1 mark)
(c) What is the purpose of Flag in this procedure?
...........................................................................................................................................
...........................................................................................................................................
(1 mark)
4
22 The list Ports contains the following names:
[Southampton, Barcelona, Athens, Alexandria, Tunis, Lisbon]
The table below shows some functions which take a list as their single argument and return a
result which is either an element of a list or a boolean value.
Head(list) – If the list is non-empty, it returns the element at the head of the list (e.g.
Head (Ports) A Southampton) otherwise it reports an error
Tail(list) – If the list is non-empty it returns a new list containing all but the first
element of the original list, otherwise it reports an error
Empty(list) – If the list is the empty list it returns True otherwise it returns False.
The empty list is donated by [ ]
(a) What result is returned when the following function calls are made?
(i) Tail(Ports) ................................................................................................................
..................................................................................................................................
(1 mark)
(ii) Head(Tail(Tail(Ports))) ............................................................................................
..................................................................................................................................
(2 marks)
(iii) Empty(Tail(Tail(Tail(Tail(Tail(Tail(Ports))))))) .......................................................
..................................................................................................................................
(2 marks)
A recursively defined procedure P, which takes a list as its single parameter, is defined below.
Define Procedure P(list)
If Not Empty(list)
Then
P(Tail(list))
Print Head(list)
EndIf
EndDefine
(b) What is meant by recursively defined?
...........................................................................................................................................
...........................................................................................................................................
(1 mark)
(c) Explain why a stack is needed to execute procedure P recursively.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
(2 marks)
(d) For the procedure call P(Ports) give the PRINTed output in the order in which it is
produced.
...........................................................................................................................................
...........................................................................................................................................
(4 marks)
(e) Complete the table to show the list Ports as a linked list so that the ports can be accessed
in alphabetical order.
1 Southampton
Head
Pointer
2 Barcelona
3 Athens
4 Alexandria
5 Tunis
6 Lisbon
(2 marks)
14
TURN OVER TO NEXT PAGE
LEAVE
MARGIN
BLANK
23 0DQ\SURJUDPVH[HFXWHGZLWKLQD*UDSKLFDO8VHU,QWHUI DFH*8,HQYLURQPHQWDUHobjectoriented DQGevent-driven
D *LYHDQH[DPSOHRIDQHYHQWLQWKLVFRQWH[W
(1 mark)
E 'HVFULEHKRZHYHQWGULYHQSURJUDPVGLIIHUIURPQRQHYHQWGULYHQSURJUDPV
(2 marks)
F /LVWWZR IHDWXUHVRIDQREMHFW
(2 marks)
G 1DPHDQREMHFWWKDWPLJKWEHSDU WRID*8,
(1 mark)
$UHFXUVLYHO\GHILQHGSURFHGXUH;ZLWKWKUHHLQWH JHUSDUDPHWHUVLVGHI LQHGEHORZ
x ',9y FDOFXODWHVKRZPDQ\WLPHVy GLYLGHVH[DFWO\LQWRx)RUH[DPSOH',9 Procedure X (E,L,H)
If L > H
Then Print ‘False’
Else M (L+H)DIV 2
If E = List[M]
Then Print ‘True’
Else
If E < List[M]
Then X (E,L,M-1)
Else X (E,M+1,H)
Endif
Endif
Endif
EndProc
‘
➔
‘
D :KDWLVPHDQWE\UHFXUVLYHO\GHILQHG"
(1 mark)
E
L 8VLQJWKHWDEOHEHORZGU\UXQWKHSURFHGXUHFDOO;DSSOLHGWRWKH
LQWHJHUDUUD\List FRQWDLQLQJWKHIROORZLQJHOHPHQWV
,QGH[
(
/LVW
/
+
0
/LVW>0@
3ULQWHG
2XWSXW
(7 marks)
LL :KDWSURFHVVGRHVSURFHGXUH;GHVFULEH"
(2 marks)
(1'2)48(67,216
10