100% found this document useful (1 vote)
325 views8 pages

Computer Science HL P2 PDF

The document describes a binary search algorithm that searches a file of product data records sorted by product code. It contains several parts: 1) The binary search algorithm uses pass-by-reference to return whether the item was found and its location. 2) Questions ask to outline differences between procedures/functions, iterative/recursive algorithms, and ask the student to write a recursive binary search function. 3) Sales data for products is stored in a 2D array, and a question asks to write an algorithm to find the lowest sales for each product.

Uploaded by

anon_550062370
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
325 views8 pages

Computer Science HL P2 PDF

The document describes a binary search algorithm that searches a file of product data records sorted by product code. It contains several parts: 1) The binary search algorithm uses pass-by-reference to return whether the item was found and its location. 2) Questions ask to outline differences between procedures/functions, iterative/recursive algorithms, and ask the student to write a recursive binary search function. 3) Sales data for products is stored in a 2D array, and a question asks to write an algorithm to find the lowest sales for each product.

Uploaded by

anon_550062370
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

c

IB DIPLOMA PROGRAMME
PROGRAMME DU DIPLME DU BI
PROGRAMA DEL DIPLOMA DEL BI

N02/650/H(2)+

COMPUTER SCIENCE
HIGHER LEVEL
PAPER 2
Wednesday 20 November 2002 (morning)
2 hours 30 minutes

INSTRUCTIONS TO CANDIDATES
y
y

Do not open this examination paper until instructed to do so.


Answer all the questions.

882-312

8 pages

2
1.

N02/650/H(2)+

A small shop stocks drinks and other items for sale. Details of the items are held in a stock
file with the following record structure:
newtype ITEM record
CODE integer
DESCRIPTION string
PRICE real
STOCK integer
REORDER integer
endrecord
declare DATA is ITEM file

Records are held in the DATA file in sequential order of CODE which is a 5-digit integer. The
following algorithm conducts an iterative binary search of the DATA file.
procedure BINARYSEARCH(val
val
ref
ref
//
//
//
//

WANTED integer,
SIZE integer,
FOUND boolean,
PLACE integer)

FOUND returns true if the WANTED code is in the file


PLACE returns its location in the file DATA
SIZE is the number of components in the data file
The first component of DATA is numbered 0
declare MIDPOINT,LOW,HIGH,CODE integer
declare CURRENT is ITEM
FOUND <- false
LOW <- 0
HIGH<- SIZE 1
while (HIGH >= LOW) and (not FOUND) do
MIDPOINT <- (LOW + HIGH) div 2
moveto(DATA,MIDPOINT)
input(DATA) CURRENT
if CURRENT.CODE > WANTED then
HIGH <- MIDPOINT 1
elsif CURRENT.CODE < WANTED then
LOW <- MIDPOINT + 1
else
FOUND <- true
endif
endwhile
PLACE <- MIDPOINT

endprocedure BINARYSEARCH

(This question continues on the following page)

882-312

N02/650/H(2)+

(Question 1 continued)
(a)

Outline why the parameters FOUND and PLACE are pass-by-reference.

[2 marks]

(b)

Outline one difference between a procedure and a function.

[2 marks]

(c)

Outline one difference between iterative and recursive algorithms.

[2 marks]

(d)

Construct the algorithm which implements the binary search as a recursive


function which returns the place of the wanted item in the file or 1 if
the item is not found.

[10 marks]

Outline a Boolean condition that could be used to ensure that the CODE
numbers all have 5 digits.

[2 marks]

(e)
(f)

Construct the algorithm which conducts a linear (sequential) search of


the data file and outputs the following information for each product
whose STOCK level is less than the REORDER level:
ITEM CODE
DESCRIPTION
SHORT (which equals REORDER minus STOCK)

The algorithm must also output the total value of the stock in the shop
(that is the sum of STOCK*PRICE for every item).

[7 marks]

(This question continues on the following page)

882-312

Turn over

N02/650/H(2)+

(Question 1 continued)
The sales figures for each month are held in a 2D integer array SALES[500,13] with the
following structure:
1

10

11

12

13

10232 112 209 187

93 103 163 231 206 194 300 314 256

10343

22

10344 324 504 342 564

10356

53

43

10412

11342

12

...

etc.
...

...

...

13

15

32
34

34

33

...

...

...

...

...

...

...

...

...

...

500
(all cells are filled with integer data)
The first column of the array contains the 5-digit ITEM number and the remaining columns contain
the sales figures with column 2 being January sales, column 3 being February sales and so on.
(g)

Construct the algorithm which outputs the following information for


each product in the array:
ITEM CODE
LOWEST (that is the lowest value of sales in the 12 months)

882-312

[5 marks]

N02/650/H(2)+

This question requires the use of the Case Study.


2.

(a)

State one reason why the CT numbers are stored in 2 bytes even though
only 12 bits are required for storage.

[2 marks]

Outline one difference and one similarity between parity checks and check
sums used to ensure data integrity.

[4 marks]

(c)

Outline the meaning of the term handshaking.

[2 marks]

(d)

Modern investigations use digital modelling and simulation in preference


to physical models, made of plaster, for example. Explain two advantages
and two disadvantages of digital modelling compared to physical modelling.

[8 marks]

(e)

Outline any two ethical issues relating to the case study.

[4 marks]

(f)

Outline any two precautions that a researcher should take to ensure that
his or her username and password are not found out by hackers.

[4 marks]

Explain one way in which the job of a researcher in this field might have
changed since the introduction of CT.

[2 marks]

Outline one advantage and one disadvantage of the world-wide-web as a


medium for sharing scientific data such as the cranial reconstructions
described in the case study.

[4 marks]

(b)

(g)
(h)

882-312

Turn over

6
3.

N02/650/H(2)+

Consider the following two algorithms used to delete an integer value from an array:
function SHUFFLE(var PLACE integer,
ref INTARRAY integer array[1..SIZE]) result boolean
if PLACE <= SIZE then
for I <-- PLACE to (SIZE 1) do
INTARRAY[I] <-- INTARRAY[I+1]
endfor
return true
else
return false
endif
end SHUFFLE
function MARK (var PLACE integer,
ref INTARRAY integer array[1..SIZE]) result boolean
if PLACE <= SIZE then
INTARRAY[PLACE] <-- 999
return true
else
return false
endif
end MARK

(a)

Compare the efficiency of these two algorithms in execution time and


memory requirements. A determination of their big-O time complexity
is expected as part of your answer.

[6 marks]

A queue is implemented as a linked list, g is the element at the front of the queue:
a

rear

front

(b)

Describe how a new element can be enqueued to this structure.

[3 marks]

(c)

Explain how this structure can be modified to use a circular linked list.

[2 marks]

(d)

Outline a method that could be used to count the number of items in the
modified queue.

[4 marks]

882-312

7
4.

N02/650/H(2)+

During the execution of a computer program, data held in primary memory is passed to the
ALU and instructions are passed to the CU.
(a)
(b)

Explain the functions of the accumulator, instruction register and program


counter in this process.

[6 marks]

Outline one recent development in processor architecture that attempts


to overcome the limitations of processing machine instructions one by one.

[2 marks]

As part of the fetch-decode-execute cycle, the interrupt register is checked. An 8-bit register
is shown below:
7

The most significant bit holds the highest priority interrupt.


(c)

State the hexadecimal representation of this register.

(d)

Explain how a byte such as hexadecimal 80 can be used to check the


status of the most significant bit.

(e)

[1 mark]
[2 marks]

Buffers are used with peripheral devices. In some situations they may
become full.
[2 marks]

882-312

(i)

Outline why buffers are used.

(ii)

Outline one way that the system would deal with a full buffer.

[2 marks]

Turn over

8
5.

N02/650/H(2)+

A data processing company uses a mainframe computer to prepare mobile phone bills. When
a new customer is added the data is put onto a tape file. This tape is then sorted by customer ID
order and used to update the customer master file which is held on disk, also in customer ID order.
(a)
(b)

State one error that can occur when the master file is updated (not including
file corruption or programming errors).
Outline one reason why the master file is held on disk.

[1 mark]
[2 marks]

The company takes over another large company.


(c)
(d)

882-312

Outline two problems that may occur when combining the two companies
customer files.

[4 marks]

Explain the process of merging together two sorted customer files.

[8 marks]

You might also like