ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 28 November 2012

Similar documents
ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 19 November 2014

ECE 2035 Programming HW/SW Systems Spring problems, 5 pages Exam Three 8 April Your Name (please print clearly)

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 20 November 2013

ECE 2035 A Programming HW/SW Systems Spring problems, 5 pages Exam Three 13 April Your Name (please print clearly)

ECE 2035 Programming Hw/Sw Systems Spring problems, 8 pages Final Exam Solutions 1 May 2013

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 18 November 2015

ECE 2035 Programming HW/SW Systems Fall problems, 4 pages Exam Three 14 November Your Name (please PRINT clearly) Signed.

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 8 December 2014

2. dead code elimination (declaration and initialization of z) 3. common subexpression elimination (temp1 = j + g + h)

ECE 2035 A Programming Hw/Sw Systems Spring problems, 8 pages Final Exam 29 April 2015

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 9 December 2015

ECE 2035 A Programming Hw/Sw Systems Spring problems, 8 pages Final Exam Solutions 29 April 2015

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam Solutions 9 December 2015

ECE 2035 Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 9 December 2013

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Three 10 April 2013

ECE 2035 A Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 14 December 2016

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

ECE 2035 A Programming Hw/Sw Systems Fall problems, 10 pages Final Exam Solutions 14 December 2016

11 'e' 'x' 'e' 'm' 'p' 'l' 'i' 'f' 'i' 'e' 'd' bool equal(const unsigned char pstr[], const char *cstr) {

Concepts Introduced in Chapter 7

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

CSE 373 Spring 2010: Midterm #2 (closed book, closed notes, NO calculators allowed)

CSE 373 Autumn 2012: Midterm #2 (closed book, closed notes, NO calculators allowed)

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.

Q1: /14 Q2: /12 Q3: /8 Q4: /8. Total: /42

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

COMP 524 Spring 2018 Midterm Thursday, March 1

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

Programming and Data Structure Solved. MCQs- Part 2

Lecture 7: Binding Time and Storage

6.172 Performance Engineering of Software Systems Spring Lecture 9. P after. Figure 1: A diagram of the stack (Image by MIT OpenCourseWare.

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

In Java we have the keyword null, which is the value of an uninitialized reference type

Stack. 4. In Stack all Operations such as Insertion and Deletion are permitted at only one end. Size of the Stack 6. Maximum Value of Stack Top 5

MCS 360 Exam 2 11 November In order to get full credit, you need to show your work.

INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS

CSCE 2014 Final Exam Spring Version A

Low-Level C Programming. Memory map Pointers Arrays Structures

CSE351 Winter 2016, Final Examination March 16, 2016

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.

Dynamic Data Structures. CSCI 112: Programming in C

CSE 373 Autumn 2010: Midterm #2 (closed book, closed notes, NO calculators allowed)

Algorithms & Data Structures

Dynamic Data Structures (II)

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

Common Misunderstandings from Exam 1 Material

Dynamic Storage Allocation

CSE 12 Week Eight, Lecture One

CSE 373 Sample Midterm #2 (closed book, closed notes, calculators o.k.)

Declaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples:

! Determine if a number is odd or even. ! Determine if a number/character is in a range. ! Assign a category based on ranges (wind speed)

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam

Cpt S 122 Data Structures. Data Structures

Class Information ANNOUCEMENTS

Part I: Short Answer (12 questions, 65 points total)

CS61C : Machine Structures

Short Notes of CS201

Final Exam. 11 May 2018, 120 minutes, 26 questions, 100 points

CS 415 Midterm Exam Spring SOLUTION

Computer Science 9608 (Notes) Chapter: 4.1 Computational thinking and problem-solving

CS201 - Introduction to Programming Glossary By

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

Computer Science Foundation Exam

Types II. Hwansoo Han

Lecture Notes on Memory Management

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

Qualifying Exam in Programming Languages and Compilers

COMP26120: Linked List in C (2018/19) Lucas Cordeiro

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

C Programming Basics II

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

CS 415 Midterm Exam Spring 2002

Lecture 16 More on Hashing Collision Resolution

Some Practice Problems on Hardware, File Organization and Indexing

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 21 October 2016

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

Computer Science Foundation Exam

COS 226 Algorithms and Data Structures Fall Midterm

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

Run-time Environments - 3

Names, Scope, and Bindings

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total

A program execution is memory safe so long as memory access errors never occur:

CS61C : Machine Structures

CSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8

Introduction to Computer Systems. Exam 2. April 10, Notes and calculators are permitted, but not computers.

C Structures & Dynamic Memory Management

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

CSE 333 Midterm Exam Nov. 3, 2017 Sample Solution

Transcription:

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 25 20 30 25 100 1

Problem 1 (25 points) Hash Tables 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 <key, value, next> 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 <op, key, [value]>. Simulate the access list below and draw the ending state. Assume the heap pointer is initially 5040 and the free pointer is initially 0. Heap 5040 Free 0000 Pointer List Buckets 5000 5004 5016 5008 5028 5012 Entries 5016 37 5040 5064 5088 5020 555 5044 5068 5092 5024 0 5048 5072 5096 5028 18 5052 5076 5100 5032 333 5056 5080 5104 5036 0 5060 5084 5108 Hash Table Access Trace # op key value # op key value 1 insert 25 111 5 remove 18 n/a 2 insert 12 222 6 remove 25 n/a 3 insert 37 444 7 insert 40 888 4 insert 41 777 8 insert 15 999 2

Problem 2 (3 parts, 20 points) Associative Set Performance and Short Answer Part A (9 points) Consider a hash table that uses 11 buckets, each containing a list of items. Suppose the hash table contains 220 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 keys takes an average of eight operations. Ignore effects of spatial and temporal reference locality. Suppose that 75% of keys looked up are found in the hash table and 25% are not found. How many of these operations would be required for the average lookup in the hash table described above if the bucket list is unsorted versus sorted? (Show work.) number of operations when each bucket list is unsorted: number of operations when each bucket list is sorted: Part B (7 points) Suppose the hash table automatically resizes (with the same 220 entries and found key probabilities) so that the average access time becomes 26 operations. How many hash table buckets are being used, assuming each bucket contains an unsorted list of entries? (Show work.) New number of buckets: Part C (4 points) Describe one advantage that old-space/new-space copying garbage collection has over a mark-and-sweep garbage collection strategy. 3

Problem 3 (6 parts, 30 points) Heap Management Below is a snapshot of heap storage. Values that are pointers are denoted with a $. The heap pointer is $6172. The heap has been allocated contiguously beginning at $6000, with no gaps between objects. addr value addr value addr value addr value addr value addr value 6000 16 6032 12 6064 36 6096 16 6128 12 6160 0 6004 32 6036 $6100 6068 4 6100 $6052 6132 4 6164 4 6008 4 6040 10 6072 20 6104 16 6136 6032 6168 0 6012 16 6044 4 6076 8 6108 $6080 6140 0 6172 0 6016 8 6048 16 6080 8 6112 152 6144 24 6176 0 6020 8 6052 $6024 6084 6004 6116 8 6148 0 6180 0 6024 0 6056 $6100 6088 4 6120 16 6152 16 6184 0 6028 $6052 6060 8 6092 $6080 6124 6156 6156 12 6188 0 Part A (4 points) Assuming the heap has been allocated contiguously beginning at 6000, with no gaps between objects, circle all object size words in the map above. Part B (6 points) Suppose the stack holds a local variable whose value is the memory address $6036 and register $5 holds the address $6092. No other registers or static variables currently hold heap memory addresses. List the addresses of all objects in the heap that are not garbage. Addresses of Non-Garbage Objects: Part C (8 points) Create a free list by scanning the heap memory for garbage, starting at address 6000 and placing objects on the free list so that a first-fit allocation strategy will also always produce the best-fit. Free List: Part D (3 points) Based on the free list created in part C, if an object of size 26 bytes is allocated, what address will be returned using a first-fit allocation strategy? How many bytes of slack (if any) will result? Address: Slack: Part E (3 points) Based on the free list created in part C, if an object of size 5 bytes is allocated, what address will be returned using a best-fit allocation strategy? How many bytes of slack (if any) will result? Address: Slack: Part F (6 points) If the local variable whose value is the address $6036 is popped from the stack, which addresses will be reclaimed by each of the following strategies? If none, write none. (You need not list addresses already on the free list from part C.) Reference Counting: Mark and Sweep: Old-New Space (copying): 4

Problem 4 (2 parts, 25 points) Linked Lists Consider the following declarations. typedef struct Car { int Year; int Tag; struct Car *Next; Car; Car *KnownCars = Null; Part A (12 points) Write a C program Register_Vehicle that takes two integers (ModelYear and TagNum) as arguments. It should do the following: 1. allocate space on the heap for a new Car object, 2. print an error message if there is not enough heap space, 3. initialize the fields Year and Tag to the given inputs ModelYear and TagNum, and 4. push the new Car object on KnownCars. void Register_Vehicle(int ModelYear, int TagNum) { Part B (13 points) Complete the following C subroutine to remove a Car object from KnownCars if it has the input TagNum as its Tag field. Assume that there is at most one Car object in KnownCars with that TagNum as its Tag (so there may be none with that matching Tag). Be sure that your code does not create a memory leak. void Remove_Vehicle(int TagNum) { Car *ThisCar = KnownCars; Car **TrailingPointer = &KnownCars; /* Move ThisCar pointer and TrailingPointer down the KnownCars list while the end of the list is not reached and Car with TagNum is not found */ while( ){ /* If end of list is not reached (so Car with TagNum is found), splice that Car out of the list of KnownCars. Prevent memory leak. */ if ( ) { 5