CS 161 Fall 2015 Final Exam

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

Virtual University of Pakistan

Computer Science Spring 2005 Final Examination, May 12, 2005

Exam 3 Practice Problems

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

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

CSC Design and Analysis of Algorithms. Lecture 4 Brute Force, Exhaustive Search, Graph Traversal Algorithms. Brute-Force Approach

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

CSE 2320 Notes 6: Greedy Algorithms

DESIGN AND ANALYSIS OF ALGORITHMS

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&

Introduction to Algorithms November 17, 2011 Massachusetts Institute of Technology Fall 2011 Professors Erik Demaine and Srini Devadas Quiz 2

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

CS 373: Combinatorial Algorithms, Spring 1999

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

Computer Science 302 Spring 2017 (Practice for) Final Examination, May 10, 2017

DARSHAN INST. OF ENGG. & TECH.

END-TERM EXAMINATION

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

Lecture 6 Basic Graph Algorithms

Lecture 3. Brute Force

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

Design and Analysis of Algorithms

Computer Science E-22 Practice Final Exam

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

CS1800 Discrete Structures Final Version B

12 Abstract Data Types

4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting...

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

Letter STUDENT NUMBER ALGORITHMICS (HESS) Written examination. Monday 31 October 2016

CS 380 ALGORITHM DESIGN AND ANALYSIS

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

22 Elementary Graph Algorithms. There are two standard ways to represent a

U.C. Berkeley CS170 : Algorithms Midterm 1 Lecturers: Alessandro Chiesa and Satish Rao September 18, Midterm 1

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

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

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18

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

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

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018

COMP 251 Winter 2017 Online quizzes with answers

CS302 Data Structures using C++

Analysis of Algorithms

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%

Review for Midterm Exam

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

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

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

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

Subset sum problem and dynamic programming

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

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Graphs & Digraphs Tuesday, November 06, 2007

Total Score /15 /20 /30 /10 /5 /20 Grader

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

Total Points: 60. Duration: 1hr

Spanning Trees. Lecture 20 CS2110 Spring 2015

Question Points Score TOTAL 55 TOTAL (Calibrated) 50

Practice Problems for the Final

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

CS 410/584, Algorithm Design & Analysis, Lecture Notes 8!

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment

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

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

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

Chapter-6 Backtracking

Design and Analysis of Algorithms - - Assessment

Total Score /15 /20 /30 /10 /5 /20 Grader

Test 1 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 2 points each t 1

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

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

Algorithm Design Techniques (III)

Questions Total Points Score

CS490 Quiz 1. This is the written part of Quiz 1. The quiz is closed book; in particular, no notes, calculators and cell phones are allowed.

ECE250: Algorithms and Data Structures Final Review Course

( ) 1 B. 1. Suppose f x

CSC 172 Data Structures and Algorithms. Lecture 24 Fall 2017

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

CS 410/584, Algorithm Design & Analysis, Lecture Notes 8

16 Greedy Algorithms

FINAL EXAM SOLUTIONS

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Lecture: Analysis of Algorithms (CS )

Lecture 1. Introduction

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

CSCE 110 PROGRAMMING FUNDAMENTALS. Prof. Amr Goneid AUC

CS-6402 DESIGN AND ANALYSIS OF ALGORITHMS

56:272 Integer Programming & Network Flows Final Examination -- December 14, 1998

Algorithm Design Techniques. Hwansoo Han

CSC 373 Lecture # 3 Instructor: Milad Eftekhar

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

Prelim 2 Solutions. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

CSCE 321/3201 Analysis and Design of Algorithms. Prof. Amr Goneid. Fall 2016

CS6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK UNIT I

CSCE 350: Chin-Tser Huang. University of South Carolina

Introduction to Algorithms Third Edition

Transcription:

CS 161 Fall 2015 Final Exam Name: Student ID: 1: 2: 3: 4: 5: 6: 7: 8: Total:

1. (15 points) Let H = [24, 21, 18, 15, 12, 9, 6, 3] be an array of eight numbers, interpreted as a binary heap with the maximum value at its root (the first element of the array). What would be the contents of H after performing a delete-max operation on this heap? 2. (15 points) Suppose we are given n points on a line, and we wish to find one of these points that minimizes the sum of its distances to all the other points. Which of the following algorithms from the class could be used to solve this problem in the most efficient way: heapsort, quickselect, depth first search, the Bellman Ford algorithm, Graham scan, or the plane-sweep closest-pair algorithm? Explain how the algorithm you choose can be used to solve the minimum-sum-of-distances problem: what input do you give to the algorithm, and how do you produce the best point from its output? You may assume that the input is an array of n numbers, which are the x-coordinates of the points, and that their y-coordinates are all zero. Your return value should be the x-coordinate of the optimal point.

3. (15 points) One step of the Karatsuba multiplication algorithm is to split an n-bit input number x into two n/2-bit numbers x 1 and x 2, where the binary representation of x 1 consists of the n/2 most significant bits of x and the binary representation of x 2 consists of the n/2 least significant bits of x. Write assignment statements x 1 =... and x 2 =... that calculate x 1 and x 2 from x, assuming that n = 32. Your answer should use only addition, subtraction, and bitwise-boolean operations; do not use the multiplication or division operations. You may use the fact that 2 16 = 65536. 4. (15 points) Draw a depth-first search tree for the undirected graph shown below, with the depth-first search starting at vertex b. Each node of your tree should be labeled with the name of one of the graph vertices. When the search loops through the neighbors of any vertex, it should loop through them in alphabetical order. a p e t q b s r d c

5. (15 points) Draw an example of a directed graph, with weights on the edges and no negativeweight cycles, containing two vertices s and t such that Dijkstra s algorithm fails to find the correct shortest path distance from s to t. On your graph, what distance does Dijkstra s algorithm find from s to t, and what is the actual shortest path distance from s to t? 6. (15 points) Wythoff s game is played with a single chess rook on an n n chessboard. The positions of the board can be numbered by pairs of integers (x, y), where (0, 0) is the square at the bottom left of the board. A move in the game consists of moving the rook either left or down; you lose if the rook is already at (0, 0) and can t move. Define a value W [i, j] to be +1 if you can force a win from position (x, y), or 1 if your opponent can force a win no matter how you move from that position. Then these values obey the recurrence { W [h, j] for h < i, W [i, j] = max W [i, k] for k < j (the maximum is over i + j different earlier values, representing all the places the rook can move) with the base cases W [0, 0] = 1, and W [x, 0] = W [0, x] = +1 for all x > 0. Write pseudocode for a dynamic programming algorithm that takes as input the two numbers i and j and uses this recurrence to compute the value of W [i, j]. Do not use backtracking to find the optimal move; your pseudocode should stop and return W [i, j] once it has been computed.

7. (15 points) Recall that the approximation ratio for a given algorithm, on an optimization problem, is the ratio (quality of the algorithm s output)/(quality of the optimal solution). Consider the 0 1 knapsack problem, in which each item has a weight w i and a benefit b i, a solution is a subset of the items with total weight at most equal to the capacity C, and the quality of any solution is the sum of the benefits of the selected items. The greedy algorithm for the fractional knapsack problem chooses items in descending sorted order by b i /w i until there is no room for any more items. Suppose that we instead use the same greedy strategy as a heuristic for the 0 1 knapsack problem. Give an example of a collection of items with their weights and benefits that causes the approximation ratio of this greedy heuristic to be less than 1/10. Include in your answer the capacity for your example, the solution value found by the greedy heuristic, and the optimal solution value. 8. (15 points) For the set of eight points shown below, what sequence of push and pop operations on its stack would the Graham scan algorithm perform? For each push or pop operation, state which point is being pushed or popped. (Use the version of Graham scan described both in the lecture and in the book, in which the points are sorted in clockwise order around the bottom point.) c e h f a b d g