CSS 443: Mid Term Exam

Similar documents
CSSAP 443: Mid Term Exam

Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson Quiz 1.

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

Introduction to Algorithms March 12, 2008 Massachusetts Institute of Technology Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 1

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

COMP 250 Midterm #2 March 11 th 2013

Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1

Class Note #02. [Overall Information] [During the Lecture]

Midterm solutions. n f 3 (n) = 3

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

Algorithms Lab 3. (a) What is the minimum number of elements in the heap, as a function of h?

CSE 2320 Section 002, Fall 2015 Exam 2 Time: 80 mins

CS171 Final Practice Exam

Introduction to Algorithms May 14, 2003 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser.

NAME: March 4. and ask me. To pace yourself, you should allow on more than 1 minute/point. For

CS 113 MIDTERM EXAM 2 SPRING 2013

CPSC 320 Midterm 2 Thursday March 13th, 2014

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

Remember to also pactice: Homework, quizzes, class examples, slides, reading materials.

Final Exam. Problem Parts Points Grade Grader Problem Parts Points Grade Grader Total 180. Name: Athena username: Joe WF3a. Joe WF2.

CS171 Final Practice Exam

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

Algorithm Design and Time Analysis

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

First Examination (March 7th, Tuesday) Name: Total Points: 150

ECE368 Exam 2 Spring 2016

Midterm 2. Read all of the following information before starting the exam:

University of Waterloo CS240, Winter 2010 Assignment 2

6.006 Final Exam Name 2. Problem 1. True or False [30 points] (10 parts) For each of the following questions, circle either True, False or Unknown.

ECE250: Algorithms and Data Structures Midterm Review

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total

Midterm Exam Amy Murphy 19 March 2003

CS171 Midterm Exam. October 29, Name:

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

CSE wi: Practice Midterm

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

Section 03: Asymptotic Analysis

Practice Midterm Exam Solutions

CMPSCI 311: Introduction to Algorithms Practice Final Exam

Prelim One Solution. CS211 Fall Name. NetID

CSE 241 Algorithms and Data Structures Fall Semester, Midterm Exam

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

Computer Science Foundation Exam

Computer Science II Fall 2009

CSSAP 443: Final Exam

Name Section Number. CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice

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

UNIVERSITY REGULATIONS

CSE 451 Midterm Exam May 13 th, 2009

Computer Science Foundation Exam. May 6, Computer Science. Section 1A. No Calculators! KEY. Score: 50

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 4 Notes. Class URL:

Computer Science Foundation Exam

CS/ENGRD2110: Final Exam

such a manner that we are able to understand, grasp and grapple with the problem at hand in a more organized fashion.

CSI 1100 / 1500 Fall 2004 Introduction to Computer Science I Final Examination

Spring 2016 Algorithms Midterm Exam (Show your work to get full credit!)

Computer Science Foundation Exam

Multiple-choice (35 pt.)

Introduction to Algorithms April 16, 2008 Massachusetts Institute of Technology Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 2

CIS 121 Data Structures and Algorithms with Java Spring Code Snippets and Recurrences Monday, January 29/Tuesday, January 30

CS302 Topic: Algorithm Analysis #2. Thursday, Sept. 21, 2006

CSE 332, Spring 2010, Midterm Examination 30 April 2010

Quiz 1 Solutions. Asymptotic growth [10 points] For each pair of functions f(n) and g(n) given below:

Computer Science Foundation Exam

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

Midterm Exam Solutions Amy Murphy 28 February 2001

CSE373 Fall 2013, Midterm Examination October 18, 2013

Technical University of Denmark

NAME: February 27. and ask me. To pace yourself, you should allow on more than 1 minute/point. For

CS302 Topic: Algorithm Analysis. Thursday, Sept. 22, 2005

1.00 Introduction to Computers and Engineering Problem Solving. Final Examination - May 19, 2004

CS61B, Fall 2011 Final Examination (corrected) P. N. Hilfinger

EECS Sample Midterm Exam

Section I B COMPUTER SCIENCE SOLUTION

CS 170 Algorithms Spring 2009 David Wagner MT2

Midterm Exam. CS169 Fall November 17, 2009 LOGIN: NAME: SID: Problem Max Points Points TOTAL 100

CS 61B Asymptotic Analysis Fall 2018

Final Exam in Algorithms and Data Structures 1 (1DL210)

Parallel Programming Languages COMP360

CSC 111, Test 1 (Fall 2009)

Computer Science Foundation Exam

EECS168 Exam 3 Review

MergeSort. Algorithm : Design & Analysis [5]

Introduction to Algorithms April 21, 2004 Massachusetts Institute of Technology. Quiz 2 Solutions

CS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014

CS583 Lecture 01. Jana Kosecka. some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes

Comp 249 Programming Methodology Chapter 11 Recursion

University of Waterloo CS240 Winter 2018 Assignment 2. Due Date: Wednesday, Jan. 31st (Part 1) resp. Feb. 7th (Part 2), at 5pm

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

Computer Science Foundation Exam

RAIK 183H Examination 2 Solution. November 10, 2014

CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial

CIS 120 Midterm II November 8, 2013 SOLUTIONS

CS4411 Intro. to Operating Systems Final Fall points 12 pages

cs1120: Exam 1 Due: Wednesday, 06 October at 3:30pm (in class)

DO NOT REPRODUCE. CS61B, Fall 2008 Test #3 (revised) P. N. Hilfinger

CLO Assessment CLO1 Q1(10) CLO2 Q2 (10) CLO3 Q4 (10) CLO4 Q3a (4)

Exam Duration: 2hrs and 30min Software Design

CS4411 Intro. to Operating Systems Exam 2 Fall 2009

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

Transcription:

Name: Student ID: CSS 443: Mid Term Exam Feb 19, 2003 3:30pm 5:35pm This exam contains 4 problems on 6 pages. You have 125 minutes to earn 100 points. This exam is open book. Do not spend too much time on any problem. Read them all through first and attack them in the order that allows you to make the most progress. Show your work, as partial credit will be given. You will be graded not only on the correctness of your answer, but also on the clarity with which you express it. Be neat! Please show all the details of your work and justify your answers. As in all cases in this class, correct answers without justifications will not earn you full credit. Problem 1 (25%) 1a (5%) 1b (5%) 1c (15%) Problem 2 (30%) 2a (5%) 2b (8%) 2c (2%) 2d (6%) 2e (6%) 2f (3%) Problem 3 (15%) Problem 4 (30%) 4a (10%) 4b (10%) 3c (10%)

Problem 1 (25%). Study our homework assignment #1 closely here are my new solution to the thread termination sequencing problem. Here is my new and improved TsyncObject: class TsyncObject { private int fid; private int fcount; // for keeping track of the number of treads ; // constructor TsyncObject() { fid = -1; fcount = 0; // counter methods synchronized public void IncrementCount() { fcount++; synchronized public int GetCount() { return fcount; // id comparison methods synchronized public void SetID(int id) { fid = id; synchronized public boolean IsID(int id) { boolean found = (fid == id); if (found) { if (fid == 4) fid = 0; else fid++; return found; This is what my new TcomputeThread looks like: class TcomputeThread extends Thread { ; // class variable: All threads share this!! static private TsyncObject sfsyncobject; // for synchronization... // class method static void SetClassVariables(TsyncObject syncobj) { sfsyncobject = syncobj; // instance variable private int fthreadid; // constructor TcomputeThread(int id) { fthreadid = id; public void run() { while (!sfsyncobject.isid(fthreadid) ); System.err.println("Thread[" + fthreadid + "]: dieing... "); sfsyncobject.incrementcount(); Page 2 of 6

Where my simplethread() looks like: public class TsimpleThread { // Driver program for TsimpleThread. public static void main(string args[]) { int numthreads = 5; TsyncObject syncobj = new TsyncObject(); TcomputeThread.SetClassVariables(syncObj); TcomputeThread mythreads[] = new TcomputeThread[numThreads]; // now initialize and start all the threads for (int i=0; i<numthreads; i++) { mythreads[i] = new TcomputeThread(i); mythreads[i].start(); System.err.println("5 Threads created and running... which to die first? "); Set up to read from keyboard int start; // which thread to start the termination input start from the keyboard syncobj.setid(start); // make sure all child threads are terminated before // we print out our message and terminate! while (syncobj.getcount()!= 5); ; // this is to make sure the main termination message // will only appear after all the children threads has die // System.err.println("Main User Interaction Thread exiting...!"); a. (5%) When the user enters a 2 as input, what would the output to look like? Please provide descriptions justifying why the output. If you run the above program n-times, where n is some large number, would you get the same output every time? Would this program terminate? b. (5%) After looking at the code for 8.6 seconds, Student Mary once again argued that this is a really bad design because the threads are still performing busy wait. Is Student Mary correct? Please justify your answers. c. (15%) Learned her lesson from hw#1, Student Mary claimed that none of the methods in the TsyncObject needs to be synchronized. Please evaluate Mary s argument by going through each of the 4 methods in TsyncObject class and describe if the method needs to be synchronized. Page 3 of 6

Problem 2 (30%). Refer the following array based linked list implementation: int SystemMemory[20]; int nextfield(int addr) { return SystemMemory[addr+1]; int keyfield(int addr) { return SystemMemory[addr]; int WhyDoIRecurse(int newlist, int link) { int cntptr, preptr; if ( link!= -1 ) { int next = nextfield(link); SystemMemory[link+1] = -1; if (keyfield(link) <= keyfield(newlist)) { SystemMemory[link+1] = newlist; newlist = link; else { cntptr = newlist; preptr = cntptr; while ( (cntptr!= -1) && (keyfield(link) > keyfield(cntptr)) ) { preptr = cntptr; cntptr = nextfield(cntptr); SystemMemory[link+1] = cntptr; SystemMemory[prePtr+1] = link; return WhyDoIRecurse( newlist, next ); return newlist; int ThisIsWhereItStart(int list) { int newlist = list; list = nextfield(list); SystemMemory[newList+1] = -1; return WhyDoIRecurse(newList, list); Given that initially fmemorysystem looks like: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 0-1 0-1 4 6 6-1 16 16-1 12 12 14 9 8 18 18-1 0 Also, the initial values for mylist=12: a. (5%) Draw the initial list content of mylist. You must include both the keyfield, and the nextfield of each link in the link list. b. (8%) What is the content of the list returned by ThisISWhereItStart(12)? Page 4 of 6

c. (2%) What does ThisIsWhereItStart() do? d. (6%) Please derive an equation describing best case run time of ThisISWhereItStart(). This question asks, in the very best case, assuming all conditions are favorable, what is the run time of ThisIsWhereItStart() for a n element link list? You can use the space besides the pseudo code to help show your analysis. e. (6%) Based on your equation in Part (d), what is the best case runtime of ThisIsWhereItStart()? f. (3%) What is the asymptotically tight lower bound (Ω) for the best case run time of ThisIsWhereItStart()? Problem 3 (15%). My co-worker says sorting a link-list based data structure is inefficient and complicated to implement. As such, he will copy the link list into an array, sort the array and then copy the results back to the link list. Professor Kelvin Sung says, 2 copying procedures each with O(n) running time, and the O(nlgn) sorting time, my co-worker has an O( n 3 lg n) algorithm. Assuming you have access to: CopyListToArray(inputList, outputarray), and, CopyArrayToList(inputArray, outputlist), and SortArray(array) functions. Show the pseudo code of my co-work s sorting strategy and comment on Professor Sung s analysis. Page 5 of 6

Problem 4 (30%). Professor Kelvin Sung proposed the following best sorting algorithm known to humankind: KelvinSort(A, startindex, endindex) // A is the array containing all the input numbers // startindex is the starting position we will sort // endindex is the end position if A[startIndex] > A[endIndex] then exchange A[startIndex] A[endIndex] if startindex + 1 >= endindex then return //*********************************************** // LOCATION A: // PrintArray(A, startindex, endindex); // For Debugging purposes: // prints out every element from startindex to endindex //************************************************* // now recursively call ourselves with smaller subproblem. offset= floor((endindex-startindex+1)/3) // round down KelvinSort(A, startindex, endindex-offset) // First two-thirds KelvinSort(A, startindex+offset, endindex) // Last two-thirds KelvinSort(A, startindex, endindex-offset) // First two-thirds again a. (10%) Use A[3 4 2 1] to show that KelvinSort(A,1,n) correctly sorts the input array A[1..n]. You must include the tracing of each recursive calls to KelvinSort, clearly indicating the values of startindex, endindex, offset and the contents of the array A before and after each calls to KelvinSort. b. (10%) Give a recurrence for the worst-case running time of KelvinSort and a tight asymptotic ( Θ notation ) bound on the worst-case running time. Compare this with other sorting algorithms we have learned. Should Professor Kelvin Sung teach algorithm classes? c. (10%) Trying to debug this algorithm, Kelvin un-commented the PrintArray() function located at LOCATION A:. Now, what is the tight asymptotic ( Θ notation ) bound on the worst-case running time of KelvinSort? Page 6 of 6