



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




4 problems, 5 pages Exam Three 21 November 2008
Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate the pages of the exam. For maximum credit, show your work. Good Luck!
Your Name ( please print ) ________________________________________________
4 problems, 5 pages Exam Three 21 November 2008
Problem 1 (1 part, 25 points) Hash Tables and Heap
Consider an open hash table composed of a four-bucket table, with each bucket containing a variable length list. Each list entry has three slots corresponding to the three word groupings in the entries section. The hash function is key mod four. Inserted entries are appended to the end of a bucket list. Deallocated entries are maintained on a LIFO free list. When the free list is empty, new entry objects are allocated from heap memory. Accesses are listed as . Simulate the access list below and draw the ending state. Assume the hash table is initially empty, the heap pointer is initially 5016 and the free pointer is initially
Heap Pointer
(^5016) Free List
Buckets
5000 5004 5008 5012
Entries
5016 5040 5064 5088
Hash Table Access Trace
1 insert 7002 111 5 insert 7010 555 2 insert 7001 222 6 remove 7006 n/a 3 insert 7006 333 7 insert 7003 666 4 insert 7001 444 8 insert 7007 777
4 problems, 5 pages Exam Three 21 November 2008
Problem 3 (4 parts, 20 points) Short Answer
Part A (6 points) Consider a hash table that uses 50 buckets , each containing an unsorted LIFO list of items. Inserted entries are appended to the end of the bucket list. Suppose the hash table contains 450 entries total and the entries are evenly distributed across the hash table buckets. Assume that computing the hash function takes an average of three operations and comparing two strings takes an average of ten operations. Ignore effects of spatial and temporal reference locality. Suppose that 60% of keys looked up are found in the hash table and 40% are not found. How many of these operations would be required for the average lookup in the hash table described above? (show work)
operations Part B (7 points) Suppose the hash table automatically resizes (with the same 450 entries and found key probabilities) so that the average access time becomes 41 operations. How many hash table buckets are being used? (show work)
new number of buckets: Part C (4 points) Describe the effect of the C fragment below. Would it create an incorrect result, an error, and if so when and how would it be detected? Explain your answer.
int x = 2; float y = 3.14; float z = x + y;
Part D (3 points) Explain what “ $@ ” represents in the following makefile entry.
P2-4: $(OBJECTS) $(LN) $(LNFLAGS) -o $@ $(OBJECTS) $(LDLIBS)
4 problems, 5 pages Exam Three 21 November 2008
Problem 4 (2 parts, 20 points) Vision
In this problem, write proper C code to accomplish the stated objective.
Part A (6 points) Write a C fragment that allocates a RGB frame buffer Frame using Height and Width variables. If the buffer cannot be allocated, print an error message and exit.
unsigned char *Frame; unsigned int Height, Width;
Part B (14 points) Write a routine that reads the pixel (X,Y) from an image Frame, placing it in the pixel object P, which is then returned. typedef struct Pixel { unsigned char R, G, B; } Pixel;
Pixel Lookup_Pixel(unsigned int X, unsigned int Y, unsigned char *Frame, unsigned int Width, unsigned int Height) { Pixel P;
}