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

Similar documents
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 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 19 November 2014

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

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

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 29 April 2015

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

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 23 October Your Name (please print clearly) Signed.

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

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

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam One 4 February Your Name (please print clearly)

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

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

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

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

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 22 September Your Name (please print clearly) Signed.

CPSC 311: Analysis of Algorithms (Honors) Exam 1 October 11, 2002

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

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

Do not start the test until instructed to do so!

COMP 524 Spring 2018 Midterm Thursday, March 1

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

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

York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

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

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

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

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

COS 226 Midterm Exam, Spring 2009

PROBLEM 1 : (And the winner is...(12 points)) Assume you are considering the implementation of a priority queue that will always give you the smallest

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

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

2016 Spring COP 3502 Final Exam. Date: 4/28/2016. Name:

Computer Science Foundation Exam

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

Computer Science Foundation Exam

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

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

CS 3114 Data Structures and Algorithms READ THIS NOW!

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

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

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

EE 312 Fall 2018 Midterm 1 Version A October 10, 2018

Q1 Q2 Q3 Q4 Q5 Q6 Total

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

Computer Science E-22 Practice Final Exam

CSCE 2014 Final Exam Spring Version A

CSE 131 Introduction to Computer Science Fall Exam II

COS 226 Algorithms and Data Structures Fall Midterm

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions:

Signature: ECE 551 Midterm Exam

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

Operating System Labs. Yuanbin Wu

CS 3114 Data Structures and Algorithms READ THIS NOW!

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Computer Science. Section 1B

CS 222/122C Fall 2016, Midterm Exam

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

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

Programming and Data Structure Solved. MCQs- Part 2

Computer Science Foundation Exam

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

Computer Science Foundation Exam

ECE264 Fall 2013 Exam 3, November 20, 2013

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 19 September 2012

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

COS 226 Algorithms and Data Structures Fall Midterm

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

Computer Science Foundation Exam

My malloc: mylloc and mhysa. Johan Montelius HT2016

BBM 201 DATA STRUCTURES

CSE 247 Data Structures and Algorithms Fall Exam I

CS106X Handout 35 Winter 2018 March 12 th, 2018 CS106X Midterm Examination

CSE 333 Midterm Exam 2/14/14

Prelim CS410, Summer July 1998 Please note: This exam is closed book, closed note. Sit every-other seat. Put your answers in this exam. The or

Computer Science Foundation Exam

York University. AP/ITEC Section M INTRODUCTION TO DATA STRUCTURES Winter Midterm Test

Problem Score Max Score 1 Syntax directed translation & type

Midterm, Spring 2013

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

DO NOT. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N.

NET/JRF-COMPUTER SCIENCE & APPLICATIONS. Time: 01 : 00 Hour Date : M.M. : 50

CSE 131S Introduction to Computer Science Summer SON Exam I

CS 241 Data Organization Binary Trees

Midterm II Exam Principles of Imperative Computation Frank Pfenning. March 31, 2011

CS 111X - Fall Test 1

Practice final for EECS 380, 2001: Prof Markov

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

COS 226 Midterm Exam, Spring 2011

Midterm 2 Exam Principles of Imperative Computation. Tuesday 31 st March, This exam is closed-book with one sheet of notes permitted.

CS 3343 (Spring 2013) Exam 2

Question Q1 Q2 Q3 Q4 Q5 Q6 Q7 Total

Elementary Data Structures: Lists

ECE242 Data Structures and Algorithms Fall 2008

CS 216 Exam 1 Fall SOLUTION

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Summer I Instructions:

8. Binary Search Tree

Transcription:

Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand; do not leave your seat. 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 clearly) This exam will be conducted according to the Georgia Tech Honor Code. I pledge to neither give nor receive unauthorized assistance on this exam and to abide by all provisions of the Honor Code. Signed 1 2 3 4 total 22 28 2 3 1 1

Problem 1 (2 parts, 22 points) Hash Tables Part A (14 points) 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. The initial state of the hash table is shown. List elements as allocated by malloc are shown in the figure. The symbol to the left of each list element (A, B, C,...) is the address returned by malloc. Entries that are freed are maintained in a last-in-first-out (LIFO) free list. Assume the free list is initially empty. Execute the access trace shown in the table below. For ease of representation, you may use the allocated blocks in any order. Show pointers both by their (symbolic) value, and with an arrow. If a value changes, cross it out and place the new value to the right. If a pointer changes, also place an x on the corresponding arrow, and draw the new arrow. Buckets (Hash Anchor Table) 3 2 1 A B A 19 555 D G B 38 333 E H C F I Hash Table Access Trace # op key value # op key value 1 insert 11 111 3 remove 19 n/a 2 insert 38 222 4 insert 15 777 Part B (8 points)consider a different hash table that uses 7 buckets, each containing a singly linked list of entries. The hash table contains a total of 14 entries evenly distributed across the hash table buckets. An application performs 1 lookups of various keys: 6 of the lookups find the key in the hash table and 4 lookups fail to find the key. The keys that are found are distributed throughout the buckets so that each position is equally likely to be where a key is found How many key comparisons would be required for the average lookup in the hash table if each bucket list is unsorted versus sorted? number of comparisons when each bucket list is unsorted: number of comparisons when each bucket list is sorted: 2

Problem 2 (4 parts, 28 points) Dynamic Memory Allocation on Heap Consider a memory allocator (malloc and free), such as described in class. Inside the C-code for the allocator, unsigned *heapptr is the address of the next word that could be allocated to the heap, and unsigned **freeptr is the address of the first block on the free list (and the word at the address of each block on the free list is a pointer to the next block on the free list). The allocator uses a best fit strategy with an unsorted free list, and never splits blocks. addr value addr value addr value addr value addr value addr value 8 8 832 2 864 4 896 848 8128 8 816 84 1234 836 868 12 81 814 8132 84 8164 88 4 84 43 872 836 814 4 8136 4 8168 22 812 16 844 12 876 8144 818 2 814 42 8172 7 816 872 848 896 88 8 8112 12 8144 43 8176 12 82 852 852 12 884 4 8116 8148 427 818 41 824 8132 856 8 888 812 4 8152 8 8184 4 828 8116 86 8116 892 16 8124 3 8156 8188 Suppose heapptr = 8128 and freeptr = 816. Consider each part below independently. Part A: (4 pts) Part B: (12 pts) How many blocks and useable bytes are on the free list? blocks = bytes = B.1) What value would be returned by the call malloc(1); B.2) Which (if any) values in the above map would be changed by the call in B.1? (fill in the address/value pairs above. There may be more pairs than needed) B.3) Fill in the values after the call in B.1: heapptr = freeptr = Part C: (8 pts) C.1) What value would be returned by the call malloc(22); C.2) Which (if any) values in the above map would be changed by the call in C.1? Part D: (4 pts) Which (if any) values in the above map would be changed by the call free(8116)? 3

Problem 3 (4 parts, 2 points) Heap Management Consider the following three heap management strategies: 1. First fit with free list sorted by increasing size (smallest to largest). 2. First fit with free list sorted by decreasing size (largest to smallest). 3. Best fit with unsorted free list. Part A (5 points) Which strategy (1, 2, or 3) has fastest average speed of malloc? Part B (5 points) Which strategy (1, 2, or 3) has slowest average speed of malloc? Part C (5 points) Which strategy (1, 2, or 3) has fastest average speed of free? Part D (5 points) Which strategy (1, 2, or 3) has the worst internal fragmentation? 4

Problem 4 (6 parts, 3 points) Suppose we have the following definition which is used to create singly-linked lists. typedef struct Element { int Num; struct Element *Next; Link; Linked Lists Part A (4 points) Fill in the blank below to allocate space for a Link structure using malloc and make the variable L1 point to the object allocated. Link *L1 = ; Part B Complete the following recursive function which takes a pointer (called Head) to the first Link of a linked list and a pointer (called NewEnd) to a Link (which has a null Next field). The function places NewEnd on the linked list as its last element. Follow the steps specified below. Link * Append(Link *Head, Link *NewEnd) { if (Head == NULL) return ; /* part B.1 */ ; /* part B.2 */ return ; /* part B.3 */ Part B.1 (5 points) Fill in what should be returned if the list is empty. Part B.2 (8 points) Call Append recursively to place NewEnd on the end of the rest of the list and then push Head on the result of this recursive call. Part B.3 (3 points) Fill in what should be returned. Part C The following subroutine should free up all elements in the linked list whose first Link is pointed to by the input parameter Head. What error does it make? Write the correct code below. void FreeElements(Link *Head) { Link *h; for (h = Head; h!= NULL; h = h->next) free(h); Part C.1 (4 points) What is the error? Part C.2 (6 points) Write the correct version of FreeElements? void FreeElements(Link *Head) { 5