Past-paper question · 2017 May-June · Paper 41 · Q2(b)(ii)

Question 2(b)(ii) 2017 · May-June · Paper 41 · 9 marks

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

Official answer for Question 2

Part (b)

(ii)

✓
FUNCTION SearchHashTable(BYVAL SearchID : INTEGER) RETURNS

Question 9

✓
INTEGER
✓
// generate hash value
✓
Index ← Hash(SearchID)

Question 1

✓
// check each record from index until found or not there
✓
WHILE ( Customer[Index].CustomerID <> SearchID)

Question 1

✓
AND ( Customer[Index].CustomerID > 0 )

Question 1

✓
Index ← Index + 1

Question 1

✓
// wrap if necessary
✓
IF Index > 199

Question 1

✓
THEN
✓
Index ← 0

Question 1

✓
ENDIF
✓
ENDWHILE
✓
// has customer ID been found?
✓
Customer[Index].CustomerID = SearchID
✓
IF

Question 1

✓
THEN
✓
RETURN Index

Question 1

✓
ELSE
✓
RETURN -1

Question 1

✓
ENDIF
✓
ENDFUNCTION

Mark scheme 9608_s17_ms_41.pdf →

Show text version of question

Question 2

Part (b)

(ii)

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.

(ii)

The function SearchHashTable will search for a record in the hash table. The function

takes as a parameter the customer ID to be searched for. The function will return the position in the hash table where the record has been saved. If the hash table does not contain the record, the function will return the value −1.

You can assume that there is at least one empty record in the hash table.

Complete the pseudocode for the function.

FUNCTION SearchHashTable(BYVALUE SearchID : INTEGER) RETURNS INTEGER

// generate hash value

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

// check each record from index until found or not there

WHILE ( ....................................................................................................................)

AND (..................................................................................................................)

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

// wrap if necessary

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

THEN

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

ENDIF

ENDWHILE

// has customer ID been found ?

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

THEN

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

ELSE

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

ENDIF

ENDFUNCTION

[9]
Topic relevance

Why this question appears here

72% assigned-topic match · Hardware › Logic gates and logic circuits

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_41.pdf

Keep practising this topic