Past-paper question · 2017 May-June · Paper 43 · Q2(b)(i)

Question 2(b)(i) 2017 · May-June · Paper 43 · 9 marks

Original past-paper question for 2(B)(I)
Original past-paper question for 2(B)(I)
Original past-paper question for 2(B)(I)
Reveal official mark-scheme answer Official mark-scheme answer for 2(B)(I)

Official answer for Question 2

Part (b)

(i)

✓
PROCEDURE InsertRecord(BYVAL NewCustomer : CustomerRecord)

Question 9

✓
TableFull ← FALSE
✓
// generate hash value
✓
Index ← Hash(NewCustomer.CustomerID)

Question 1

✓
Pointer ← Index
✓
// take a copy of index
✓
// find a free table element
✓
WHILE Customer[Pointer].CustomerID > 0

Question 1

✓
Pointer ← Pointer + 1

Question 1

✓
// wrap back to beginning of table if necessary
✓
IF Pointer > 199

Question 1

✓
THEN
✓
Pointer ← 0

Question 1

✓
ENDIF
✓
// check if back to original index
✓
IF Pointer = Index

Question 1

✓
THEN
✓
TableFull ← TRUE
✓
ENDIF
✓
ENDWHILE
✓
IF NOT TableFull

Question 1

✓
THEN
✓
Customer[Pointer] ← NewCustomer

Question 1

✓
ELSE
✓
OUTPUT "Error"

Question 1

✓
ENDIF
✓
ENDPROCEDURE
✓
9608/43
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2017
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s17_ms_43.pdf →

Show text version of question

Question 2

Part (b)

(i)

Question 2

A hash table has these associated operations:

  • create hash table
  • insert record
  • search hash table
A
hash table is to be used to store customer records.

Each record consists of a unique customer ID, the record key, and other customer data.

A
hashing function Hash exists, which takes as a parameter the customer ID and returns an

integer in the range 0 to 199 inclusive.

(i)

The procedure, InsertRecord, takes as a parameter the customer record to be

inserted into the hash table.

The procedure makes use of the function Hash. Collisions will be managed using open hashing. This means a collision is resolved by storing the record in the next available location. The procedure will generate an error message if the hash table is full.

Question 5

Complete the pseudocode for the procedure.

PROCEDURE InsertRecord(BYVALUE NewCustomer : CustomerRecord)

TableFull FALSE

// generate hash value

Index ..................................................................................................................

Pointer Index // initialise Pointer variable to hash value

// find a free table element

WHILE ........................................................................................................................

Pointer .......................................................................................................

// wrap back to beginning of table if necessary

IF ........................................................................................................................

THEN

.................................................................................................................

ENDIF

// check if back to original index

IF ........................................................................................................................

THEN

TableFull TRUE

ENDIF

ENDWHILE

IF ..............................................................................................................................

THEN

........................................................................................................................

ELSE

........................................................................................................................

ENDIF

ENDPROCEDURE

[9]

Question 6

Topic relevance

Why this question appears here

72% assigned-topic match · Programming › Constructs

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9608_s17_qp_43.pdf

Keep practising this topic