Docsity

COP 4530 Term Exam 4 - Hash Tables and Priority Queues, Exams of Computer Science

Toggle sidebar
bg1
COP 4530 Term Exam 4 Name:
Fall 2001 SSN:
Professor Chris Lacher CS Username:
Score: /100
This test contains 2 questions (10 subquestions) on 3 pages. Each subquestion is worth 10 points.
1. Suppose that a hash table is (1) implemented using a private bucket vector object declared as
TVector < TList < TAssociation < String, int>>>bv;(2)table insert
uses TList<>::PushBack(); and (3) hash_function(String S) is implemented by:
unsigned int hash_function (const String& S)
{unsigned int hval(0), i;
for (i = 0; i < S.Size(); ++i)
hval += S[i] - 'a';
return hval;
}
Begin with a 5-bucket table t after the operations
t.Insert("ab",1);
t.Insert("cd",2);
t.Insert("ef",3);
t.Insert("gh",4);
t.Insert("pq",5);
have been performed.
a. Illustrate the result of the operation:
t.Dump(cout);
b. Illustrate the result of the traversal (I is a table iterator):
for (I = t.Begin(); I != t.End(); ++I) cout << *I;
Page 1 of 3
All rights reserved. No part of this exam may be reproduced, stored in a retrieval system, or transmitted in any means without written permission
from the publisher or a license from Florida State University. This exam may not be distributed and is the academic property of the Department
of Computer Science, Florida State University.
hash function vals
String value
a0
b1
c2
d3
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
pf3

Partial preview of the text

Download COP 4530 Term Exam 4 - Hash Tables and Priority Queues and more Exams Computer Science in PDF only on Docsity!

COP 4530 Term Exam 4 Name: Fall 2001 SSN: Professor Chris Lacher CS Username: Score: /

This test contains 2 questions (10 subquestions) on 3 pages. Each subquestion is worth 10 points.

  1. Suppose that a hash table is (1) implemented using a private bucket vector object declared as TVector < TList < TAssociation < String, int > > > bv; (2) table insert uses TList<>::PushBack(); and (3) hash_function(String S) is implemented by:

unsigned int hash_function (const String& S) { unsigned int hval(0), i; for (i = 0; i < S.Size(); ++i) hval += S[i] - 'a'; return hval; }

Begin with a 5-bucket table t after the operations t.Insert("ab",1); t.Insert("cd",2); t.Insert("ef",3); t.Insert("gh",4); t.Insert("pq",5); have been performed.

a. Illustrate the result of the operation: t.Dump(cout);

b. Illustrate the result of the traversal (I is a table iterator): for (I = t.Begin(); I != t.End(); ++I) cout << *I;

Page 1 of 3 All rights reserved. No part of this exam may be reproduced, stored in a retrieval system, or transmitted in any means without written permission from the publisher or a license from Florida State University. This exam may not be distributed and is the academic property of the Department

hash function vals String value a (^0) b 1 c (^2) d (^3) e f g h i j k l m n o p q r s t u v w x y z

COP 4530 Exam 1 Spring 2001

Now assume that these five additional operations t.Remove("ab"); t.Remove("gh"); t.Insert("ab",6); t.Insert("jk",7); t.Insert("pq",8); have been performed.

c. Illustrate the result of the operation: t.Dump(cout);

d. Illustrate the result of the traversal (I is a table iterator): for (I = t.Begin(); I != t.End(); ++I) cout << *I;

e. Under certain assumptions, a hash table has expected runtime O(1) for its insert, remove, and look-up operations. What are these assumptions?

Page 2 of 3 All rights reserved. No part of this exam may be reproduced, stored in a retrieval system, or transmitted in any means without written permission from the publisher or a license from Florida State University. This exam may not be distributed and is the academic property of the Department