COS 226 Final Exam, Spring 2009

Similar documents
COS 226 Final Exam, Spring 2010

COS 226 Midterm Fall 2007

COS 226 Written Exam 2 Fall 2016

Material covered. Areas/Topics covered. Logistics. What to focus on. Areas/Topics covered 5/14/2015. COS 226 Final Exam Review Spring 2015

COS 226 Midterm Exam, Spring 2011

COS 226 Algorithms and Data Structures Fall Final Exam

COS 226 Algorithms and Data Structures Fall Final

Final Exam Solutions

COS 226 Midterm Exam, Spring 2009

Final Exam. COS 226 Algorithms and Data Structures Fall 2015

COS 226 Algorithms and Data Structures Fall Final

COS 226 Algorithms and Data Structures Spring Final

COS 226 Algorithms and Data Structures Spring Second Written Exam

Princeton University Computer Science COS226: Data Structures and Algorithms. Final, Spring 2013

COS 126 Written Exam 2, Fall 2009

Final Exam Solutions

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Algorithms and Data Structures Fall Midterm

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

COS 226 Algorithms and Data Structures Spring Final Exam

Chapter 9 Graph Algorithms

END-TERM EXAMINATION

Chapter 9 Graph Algorithms

The Algorithm Design Manual

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

Virtual University of Pakistan

Theory of Computations Spring 2016 Practice Final Exam Solutions

Chapter 9 Graph Algorithms

University of New Mexico Department of Computer Science. Final Examination. CS 362 Data Structures and Algorithms Spring, 2006

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

( ) n 3. n 2 ( ) D. Ο

CS521 \ Notes for the Final Exam

COS 226 Algorithms and Data Structures Spring Midterm

Review of course COMP-251B winter 2010

University of Waterloo CS240R Fall 2017 Review Problems

Final Examination CSE 100 UCSD (Practice)

COS 226 Midterm Exam, Spring 2010

CMSC Theory of Algorithms Second Midterm

CSE 332 Winter 2018 Final Exam (closed book, closed notes, no calculators)

1. [5 points each] True or False. If the question is currently open, write O or Open.

CS61B, Fall 2015 Final Examination (with corrections) P. N. Hilfinger

University of Waterloo CS240R Winter 2018 Help Session Problems

COS 226 Algorithms and Data Structures Fall Final Solutions. 10. Remark: this is essentially the same question from the midterm.

COS 126 Written Exam 2 (Spring 2015)

Theory of Computations Spring 2016 Practice Final

COS 226 Algorithms and Data Structures Spring Midterm

Introduction to Computer Science

Data Structures and Algorithm Analysis in C++

CS 125 Section #10 Midterm 2 Review 11/5/14

) $ f ( n) " %( g( n)

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

6 NFA and Regular Expressions

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

Exam 3 Practice Problems

Homework Assignment #3 Graph

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.)

ICS 161 Algorithms Winter 1998 Final Exam. 1: out of 15. 2: out of 15. 3: out of 20. 4: out of 15. 5: out of 20. 6: out of 15.

Problem Score Maximum MC 34 (25/17) = 50 Total 100

Course Review for Finals. Cpt S 223 Fall 2008

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

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader

COS 226 Algorithms and Data Structures Fall Midterm

Spring 2018 Mentoring 13: April 25, New World Order. return a list of all the words that start with a given prefix.

CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018

Graph Algorithms (part 3 of CSC 282),

n 2 ( ) ( ) Ο f ( n) ( ) Ω B. n logn Ο

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu

Total Score /1 /20 /41 /15 /23 Grader

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

DESIGN AND ANALYSIS OF ALGORITHMS

Algorithm Design and Analysis

n 2 ( ) ( ) + n is in Θ n logn

Graph Algorithms (part 3 of CSC 282),

CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008

CSE 373: Data Structures and Algorithms

CS61B Spring 2016 Guerrilla Section 6 Worksheet

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

Final Exam May 8, 2018

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

Exam Sample Questions CS3212: Algorithms and Data Structures

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

( D. Θ n. ( ) f n ( ) D. Ο%

( ). Which of ( ) ( ) " #& ( ) " # g( n) ( ) " # f ( n) Test 1

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

CS 170 Second Midterm ANSWERS 7 April NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt):

CSE 373: Data Structures and Algorithms

Midterm I (Solutions) CS164, Spring 2002

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

COS 126 Midterm 1 Written Exam Fall 2011

Lecturers: Sanjam Garg and Prasad Raghavendra March 20, Midterm 2 Solutions

CS 216 Fall 2007 Final Exam Page 1 of 10 Name: ID:

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

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

(a) Write code to do this without using any floating-point arithmetic. Efficiency is not a concern here.

Princeton University Computer Science COS226: Data Structures and Algorithms. Midterm, Fall 2013

CSE 100 Minimum Spanning Trees Prim s and Kruskal

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302

L.J. Institute of Engineering & Technology Semester: VIII (2016)

Transcription:

NAME: login ID: precept #: COS 226 Final Exam, Spring 2009 This test is 16 questions, weighted as indicated. The exam is closed book, except that you are allowed to use a one page cheatsheet. No calculators or other electronic devices are permitted. Give your answers and show your work in the space provided. Put your name, login ID, and precept number on this page (now), and write out and sign the Honor Code pledge before turning in the test. You have three hours to complete the test. "I pledge my honor that I have not violated the Honor Code during this examination." 1 /8 2 /5 3 /5 4 /8 5 /4 6 /6 Subtotal /30 7 /6 8 /7 9 /7 10 /4 11 /14 Subtotal /30 12 /6 13 /3 14 /4 15 /4 16 /9 Subtotal /40 TOTAL /100 May 17, 2009

1. MST (8 points). Consider the following undirected weighted graph. a. Give the list of edges in the minimum spanning tree in the order that Kruskal's algorithm inserts them. For reference, the 18 edge weights are listed here: 4 9 12 18 19 21 22 23 24 25 30 33 34 35 36 39 42 65 b. Give the list of edges in the minimum spanning tree in the order that Prim's algorithm inserts them, assuming that it starts at vertex F. 2. KMP (5 points). The following is a KMP state-transition table for a 9-character string. a. Write the characters in the string in the blanks below the table. 0 1 2 3 4 5 6 7 8 A 1 1 3 1 X Y 1 1 9 B 0 2 0 4 0 Z 0 8 0 C W 0 0 0 0 6 7 0 0 b. Fill in the values of W, X, Y, and Z in the blanks provided below. W: X: Y: Z 2

3. Mystery code (5 points). Circle the choice that describes a use of the following code for (int i = 1; i <= G.V(); i++) for (int v = 0; v < G.V(); v++) for (Edge e : G.adj(v)) { int w = e.to(); if (dist[w] > dist[v] + e.weight()) { dist[w] = dist[v] + e.weight()) pred[w] = e; } } a. To find the longest cycle in a weighted digraph b. To compute the MST of a weighted graph c. To topologically sort a digraph d. To find shortest paths in a weighted digraph e. To implement DFS in a weighted graph 4. Acronyms (8 points). Match each of the given acronyms (at right) with a description (at left). Write the letter corresponding to your answer for each acronym in the space provided. In some cases, more than one answer might be argued, but you must put only one letter per space. If you pick the best matches, you will use all the letters. a. Abstract machine, basis for KMP algorithm. SAT b. General graph-searching scheme. KMP c. Substring-search algorithm. NFA d. Fundamental recursive method. DFA e. For single-source shortest paths in unweighted graphs. DFS f. Set of all problems checkable in polynomial time. BFS g. A logic problem. PFS h. Abstract machine, basis for grep NP 3

5. LZW compression (4 points). Which of the following best describes the length of the code produced by the LZW compression algorithm for a string consisting of N characters that are all the same? Circle your answer. a. log N b. (log N) * (log N) c. square root of N d. N e. N log N 6. 2D trees (6 points). Draw the partition of the plane that results from inserting the points drawn below A B C D E F G H I (in that order) into a 2D tree. The first partition (a vertical line) is drawn for you. Draw the tree here: 4

7. Suffix TST (6 points). The suffix TST corresponding to a string is constructed by building the TST corresponding to the string suffixes, including on each an end-of string character $ that is larger than every string character. Thus, every path through the TST ends in a $, below which we put an external node corresponding to the starting point of the suffix. For example, the suffix TST corresponding to the string cat is drawn at left. Draw the suffix TST corresponding to the string ooops. 5

8. String symbol table (7 points). Match each of the given search data structures with one or more of the given characteristics, where N is the number of keys, L is the average number of characters in a key, W is the length of the longest key, and M is the size of the alphabet. Write as many letters (in alphabetical order) as apply in the blank to the left of the name of the data structure. Assume that M is a constant. a. tree/trie shape is dependent on the order in which keys are inserted b. worst-case search time is proportional to W c. space usage (not including strings themselves) is not dependent on W d. worst-case search time is proportional to LN e. worst-case search time is proportional to WN M-ary trie BST TST red-black tree 6

9. RE pattern matching I (7 points). Draw an NFA (nondeterministic finite state automata) that recognizes the same language that the regular expression ((A*B C )* D ) describes. Use the notation and construction given in lecture. Circle your final answer. 10. RE pattern matching II (4 points). It is easy to build a NFA (nondeterministic finite state automata) corresponding to a regular expression, and a basic theorem from automata theory says that we can convert every NFA to a DFA (deterministic finite state automata). Why do we not do so to implement RE pattern matching? Circle one of the following choices. a. The DFA might have an exponential number of states. b. There might exist a string that the DFA recognizes but the NFA does not. c. There might exist a string that the NFA recognizes but the DFA does not. d. The NFA might loop. e. The proof of the theorem is not constructive (does not tell us how to construct the DFA from the NFA). 7

11. 7 sorting algorithms (14 points). The leftmost column is the original input of strings to be sorted, and the rightmost column is the sorted result. The other columns are the contents at some intermediate step during one of the 7 sorting algorithms listed below. Match up each algorithm by writing its letter under the corresponding column. Use each letter exactly once. fuzz benz zeta benz cruz cozy cozy benz benz fizz czar zinc cozy fizz faze fizz cozy cozy cozy cruz maze czar cozy faze fuzz czar cruz zinc cozy faze cruz fizz czar zinc faze czar fizz fizz fuze fuzz fizz benz fizz faze faze fuzz faze faze fizz faze cruz fizz fizz faze fizz fuzz raze fizz fizz faze fizz fizz faze fizz fuze fuze fuzz fizz fizz fuzz fizz fizz maze fuzz haze fizz fuze fizz benz fizz fizz faze fuze size fizz faze fizz czar fuze fizz czar fuze fuze faze czar fizz faze fuzz fizz benz faze faze fuze benz fizz maze fuzz fizz fuze fizz zing fuzz fuze fizz faze fuzz fizz fuzz fuzz zoom faze fuze fuze fizz maze fuze faze fizz czar fizz faze fuze fuze zinc fuze fizz fizz cozy fuzz fizz fuze fuzz cruz fuze jazz fuzz lazy fuze fuzz fuzz cruz fizz fuzz zoom fizz fuzz fuze fuzz fuzz jazz fuzz fuzz cruz fizz fizz faze zoom fuzz zing jazz fuzz zing faze fizz fizz zing fuzz zoom raze fuzz fuzz size fuzz haze jazz raze fuze zing haze raze raze fizz jazz raze zing fuzz zoom jazz fuze zing fizz lazy fuzz lazy lazy faze lazy lazy zeta benz maze lazy haze raze fizz maze haze zoom fuzz raze haze zeta fuze fuze raze zeta jazz fizz size zeta size haze fuze size size haze jazz zinc size zoom size haze zeta fuze lazy cruz zoom maze jazz zeta lazy zinc faze maze fuzz zing fuzz maze faze size zing fizz zinc fizz zeta zinc zinc fizz zeta zoom a. Mergesort b. MSD radix sort c. LSD radix sort d. Quicksort (with no random shuffle) e. Bottom-up mergesort f. Quicksort with 3-way partitioning (with no random shuffle) g. 3-way radix quicksort 8

12. Convex hull (6 points). Complete the trace given below for the Graham scan when used to find the convex hull of the following point set. For each point scanned, give the point followed by the current list of points on the trial hull after that point is scanned. The first three lines of the trace are filled in for you. next current point hull A A G C A G A G C 9

13. Strong Components (3 points). The following digraph has three strong components. List the vertices in each. first component second component third component 14. Reduction (4 points). You are a manager at a large and successful internet company that was built on solving problem A in cubic time. One of your mathematicians has proven that problem A linear-reduces to problem B. Working independently, one programmer has implemented a linear-time solution to problem B and another programmer has implemented a quadratic-time solution to problem A. What should you do? a. Fire the first programmer and promote the mathematician. b. Fire the second programmer and promote the mathematician. c. Promote the first programmer and fire the mathematician. d. Promote them all. e. Fire them all. 10

15. Huffman encoding (4 points). Draw a Huffman encoding trie for the message (17 characters). S H E S E L L S S E A S H E L L S 11

16. Hard problem identification (9 points). This question is in regard to your new job working for a software technology company. Your boss (having been told by you on the basis on your 126 knowledge that the company had better not bet its future on developing an application that finds an optimal tour connecting a set of cities) is still looking for a challenging project for you. Your boss is willing to invest in things that might be difficult, but not things that we know to be impossible or that we believe to be intractable. On the basis of your 226 knowledge, which of the following ideas can you tell your boss to forget about? Circle all that apply. A. A regular expression that describes palindromes B. An algorithm that guarantees to compress any given file by at least one percent C. A linear-time algorithm for finding the MST of a set of points in the plane that can only compare the distances between two points (not know their coordinate values) D. A linear-time algorithm for finding the MST of a graph with positive edge weights E. A linear-time algorithm for sorting an array of numbers that can only compare two numbers (not know their values) F. A fast poly-time algorithm for linear programming G. A fast poly-time algorithm for integer linear programming H. A sublinear expected-time (as a function of the total number of characters) algorithm for sorting random strings. I. A poly-time algorithm that finds the shortest path connecting two vertices in a digraph with edge weights that could be negative (but with no negative cycles). 12