Docsity

ECE 3035B Computing Mechanisms Exam Three: Fall 2004, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 3035B Computing Mechanisms Fall 2004
4 problems, 8 pages Exam Three 18 November 2004
1
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) ________________________________________________
1 2 3 4 total
25 25 25 25 100
pf3
pf4
pf5
pf8

Partial preview of the text

Download ECE 3035B Computing Mechanisms Exam Three: Fall 2004 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

4 problems, 8 pages Exam Three 18 November 2004

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 ) ________________________________________________

1 2 3 4 total

4 problems, 8 pages Exam Three 18 November 2004

Problem 1 (4 parts, 25 points) Associative Sets

Part A (10 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:

h ( k ) CharacterCode ( k )mod B ,

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:

h j ( k )=( h ( k )+ j^2 )mod B ,

where j = 1, 2, …, B-1. Show the result of inserting the following (key, value) pairs into this hashtable. (“AJC”, “Georgia”), (“NYT”, “New York”), (“WPOST”, “D.C.”), (“CT”, “Chicago”), (“GLOBE”, “Boston”). 0 1 2 3 4 5 6

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 five characters and an average bucket list length of 16 , (i.e., each bucket has approximately 16 entries). For the following questions assume that computing the hash function takes an average of three operations and comparing two strings takes an average of five operations. Ignore effects of spatial and temporal reference locality.

Part B.1 (5 points) How many of these operations would be required for the average lookup in the hash table described above? (show work)

Operations

Part B.2 (5 points) If the hash table were resized to 14 buckets (storing the same entries), how many of these operations would be required for the average lookup in the hash table? (show work)

Operations

Part B.3 (5 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)

Operations

4 problems, 8 pages Exam Three 18 November 2004

Part B.1 (5 points) Identify the webs (of def-use chains) for each variable by filling in the following table: for each variable, indicate a web label and the instruction numbers of the instructions that are included in the web (i.e., that are in the live range of the variable).

Variable name Web label Instructions in live range v w x y z

Part B.2 (5 points) Draw the interference graph using the nodes to represent the webs identified in part B.1.

Part B.3 (3 points) What is the minimum number of registers needed to cover all the variables in this code?

Registers

Part B.4 (3 points) Which of the variables would you choose to spill to memory (i.e., don’t assign a register to it, but instead store it in memory)? Briefly explain why.

Spill variable because

Part B.5 (3 points) If you spill the variable you chose in part B.4, what is the minimum number of registers needed to cover the rest of the variables?

Registers

4 problems, 8 pages Exam Three 18 November 2004

Problem 3 (3 parts, 25 points) Garbage Collection

Suppose the heap has the following contents. Address 6000 6016 6032 6048 6064 6080 6096 Size 12 12 12 12 12 12 12 Value 4 6 7 2 1 3 5 Left 6048 Null Null 6000 6048 6016 Null Right Null 6032 6080 6096 6080 6032 6080

The Address row shows the starting address of each object in the heap. The Size row indicates the number of bytes of data in each object. Each object is a struct that has three fields: an integer value and two pointers to objects of the same type.

Suppose an activation frame on the stack contains a pointer in local variable “Root” to the object at heap address 6064.

Part A (8 points ) Draw a box and pointer diagram that illustrates the object structure in the heap.

Part B (7 points ) Assign reference counts of the objects in the heap.

Address 6000 6016 6032 6048 6064 6080 6096 Size 12 12 12 12 12 12 12 Value 4 6 7 2 1 3 5 Left 6048 Null Null 6000 6048 6016 Null Right Null 6032 6080 6096 6080 6032 6080 Reference Count

Part C (10 points ) Suppose that the following statements are executed.

4 problems, 8 pages Exam Three 18 November 2004

Problem 4 (3 parts, 25 points) Parsing

Part A Consider the following grammar.

S (^) Æ T S (^) Æ T S T (^) Æ a T T Æ a^ T^ c T (^) Æ b T (^) Æ c

For each string below, determine whether it is ambiguous (i.e., has more than 1 parse tree). If not, show its unique parse tree. If it is ambiguous, draw two different parse trees for it.

Part A.1 (8 points) Is this string ambiguous? a a b c c YES / NO (circle one) Show parse tree(s) for it.

Part A.2 (8 points) Is this string ambiguous? a a a c YES / NO (circle one) Show parse tree(s) for it.

4 problems, 8 pages Exam Three 18 November 2004

Part B (9 points) Now consider the attribute grammar below. Productions Semantic Rules S 1 Æ S 2 D S^1 .val^ =^ 10S^2 .val^ +^ D.val S Æ D S.val^ =^ D.val D Æ B 1 B 2 B 3 D.val^ =^ 4B^1 .val^ +^ 2*B^2 .val^ +^ B^3 .val B Æ 1 B.val^ =^1 B Æ 0 B.val^ =^0

Draw the parse tree for the string 110101011 and determine the value of the attribute S.val that is computed in recognizing this string. (Show work.) Describe what the semantic analysis computes.

S.val:?

Parse tree:

Describe, in 10 words or less, what the semantic rules in this attribute grammar compute for a given binary string: