



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!




28 + 12 = 40
20 + 12 = 32
virtual address physical address page fault?
DE8269AC 1119AC N
DE82012 N/A (unallocated) Y
DE829248 N/A (on disk) Y
35CF64 D3A4BF64 N
Virtual Address: CAB
Part A (8 points) Consider a hash table that uses seven buckets. Suppose our hash function is the sum of the character codes of the characters in the key modulo the number of buckets B=7. Assume the character codes are as follows (A=1, B=2, C=3, D=4, E=5, F=6, G=7, H=8, I=9, J=10, K=11, L=12, M=13, N=14, O=15, P=16, Q=17, R=18, S=19, T=20, U=21, V=22, W=23, X=24, Y=25, Z=26). That is, the hash function is:
i
=∑ i
where i = 0 … |key|-1 and ki is the i th^ character of the key.
Suppose the hash table is implemented using closed hashing with a quadratic probe strategy to handle collisions. That is, the elements of the hash table are stored within the bucket array itself, using h(k) to determine the bucket. However, if a collision occurs, compute a series of alternative locations in the bucket array until one with the same key or an empty one is found. The alternative locations h 1 (k), h 2 (k), etc. are computed using a secondary quadratic probe function:
where j = 1, 2, …, B-1. Show the result of inserting the following (key, value) pairs into this hashtable. (“GLOBE”, “Boston”) (“AJC”, “Georgia”), (“CT”, “Chicago”), (“WPOST”, “D.C.”), (“BCA”, “British Columbia”). Note that this sequence of pairs is different from the one used in Exam 3. 0 AJC Georgia 1 BCA British Columbia 2 CT Chicago 3 WPOST D.C. 4 5 6 GLOBE Boston
Part B Now consider a hash table that uses a chaining strategy (implemented with a singly linked list) to handle collisions. The hash table has seven buckets and inserted entries are pushed on the front of the bucket list. Suppose the hash table has an average key length of three characters and an average bucket list length of 11 , (i.e., each bucket has approximately 11 entries). For the following questions assume that computing the hash function takes an average of four operations and comparing two strings takes an average of six operations. Ignore effects of spatial and temporal reference locality.
Part B.1 (4 points) How many of these operations would be required for the average lookup in the hash table described above? (show work)
Part B.2 (4 points) If instead of a hash table, an unsorted list were used to store the same entries, how many operations would be required for the average lookup using sequential search? (show work)
6(77+1)/2 = 234 Operations
Part B.3 (4 points) If we wanted to store the same entries in a hashtable that uses closed hashing with a simple linear probe strategy, what is the minimum number of buckets we would need to hold all the entries? (show work)
77 Buckets
Part D (5 points) Fill in the MIPS code after the call to Solve to restore the values from Solve’s activation frame and assign the value of “x”. lw $31, 20($29) # restore return addr lw $30, 16($29) # restore frame pointer lw $3, 0($29) # load in return value addi $29, $29, 24 # pop Solve’s activation frame sw $3, -4($30) # update the value of x in Test’s AF
Part E (4 points) Finish the implementation of Test by implementing its return to its caller. lw $3, -4($30) # $3: x (optional, already in $3) sw $3, 0($30) # store x in return value slot add $29, $30, $0 # pop off locals jr $31 # return to caller of Test
Part A (10 points) Consider the following C code. sum = 0; i = 0; elt = V[0]; do { sum += elt; i++; elt = V[i]; } while (elt != -9999); avg = sum/i;
Assume that registers $2 and $3 contain the values of variables sum and i, respectively. Complete the following MIPS code fragment with the appropriate instructions to implement the C code. Place the current elt in register $4 and the resulting avg in register $1. For maximum credit, use a minimum number of MIPS instructions. You may use additional registers.
Part B (5 points) Perform at least one standard compiler optimization on the following C code fragment by writing the optimized version (in C) to the right.
In 5 words or less, describe which standard compiler optimization you applied:
B
B
B
B
B
B
B
B
B
B
B