alaris capture pro software - skuleexams.skule.ca/exams/bulk/20189/ece345f_2018_algorithm... ·...

15
University of Toronto Department of Electrical and Computer Engineering Final Examination ECE 345 Algorithms and Data Structures Fall 2018 Friday, December 14, 2018, 2PM Print your name and ID number neatly in the space provided below; print your name at the upper right corner of every page. The exam is 15 pages including the cover page; if not, report it to the instructor or TA. Name: IJTORid: Student number: This is an open book exam. You are permitted to use the textbook for the course, handouts from Quercus, and your notes, but nothing else is permissible. No calculators, tablets, smartphones, or other electronic devices are allowed on your desk. Non-native English speakers may use a dictionary. You are allowed to reference textbook pages/sections/algorithms if you wish. Do all five problems in this booklet. Try not to spend too much time on one problem. Read the problems carefully! Use terminology from the textbook. You must define any different terms before you use them. You are allowed to reference pages from our textbook CLRS (such as algorithms, notation, etc). Write clearly and only in the space provided. Ask the proctor if you need more paper. Nothing on the back of the sheets will be graded. You have 150 minutes for this exam. Raise your hand if you have a question. Do not give C code! Write pseudocode and analyze time/memory requirements of your algorithms when asked to receive full credit. All logarithms are base 2 unless otherwise noted. Question I Points I Score I Grader 1 20 2 20 3 20 4 20 5 20 Total 100

Upload: others

Post on 29-Jan-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

  • University of Toronto Department of Electrical and Computer Engineering

    Final Examination ECE 345 Algorithms and Data Structures

    Fall 2018 Friday, December 14, 2018, 2PM

    Print your name and ID number neatly in the space provided below; print your name at the upper right corner of every page. The exam is 15 pages including the cover page; if not, report it to the instructor or TA.

    Name: IJTORid: Student number:

    This is an open book exam. You are permitted to use the textbook for the course, handouts from Quercus, and your notes, but nothing else is permissible. No calculators, tablets, smartphones, or other electronic devices are allowed on your desk. Non-native English speakers may use a dictionary. You are allowed to reference textbook pages/sections/algorithms if you wish.

    Do all five problems in this booklet. Try not to spend too much time on one problem. Read the problems carefully! Use terminology from the textbook. You must define any different terms before you use them. You are allowed to reference pages from our textbook CLRS (such as algorithms, notation, etc).

    Write clearly and only in the space provided. Ask the proctor if you need more paper. Nothing on the back of the sheets will be graded.

    You have 150 minutes for this exam. Raise your hand if you have a question.

    Do not give C code! Write pseudocode and analyze time/memory requirements of your algorithms when asked to receive full credit. All logarithms are base 2 unless otherwise noted.

    Question I Points I Score I Grader

    1 20 2 20 3 20 4 20 5 20

    Total 100

  • ECE 345 Final - Fall 2018 2 Name:

    1. Multiple Choice, 20 points.

    Each question is worth 2 points and it has only one correct answer. Write clearly! If we cannot understand

    your answer, you will receive no credit.

    (a) Solve the following recurrence: T(n) = 2T() + /i7

    a) e(logn) b) e(n log n) c) 0(n) d) (/)

    The regular expression aba(alb)* will reject the string abaabaa

    a) 'hue b) False

    The following array is a binary mm-heap [2 3 4 5 6 7 8]

    a) True b) False

    If algorithm A has e(n) runtime and algorithm B has e(n lg n) runtime, algorithm A will run in less time than than algorithm B for every possible input.

    a) True b) False

    RadixSort still sorts correctly if we sort each individual digit using HeapSort instead of Count ingSort.

    a) 'hue b) False

    Every problem in NP can be solved in polynomial time (on a deterministic Turing Machine).

    a) True b) False c) Unknown

    A directed acyclic graph can have more than one topological ordering.

    a) True b) False

    It is possible to construct a binary mm-heap from an unsorted list in 0(n) time.

    a) True b) False

    n6 = Q (log n) for all e> 0.

    a) True b) False

    If A < 3-CNF-SAT, then A is definitely in complexity class:

    a) NP-hard b) P c) NP d) NP-complete

  • ECE 345 Final - Fall 2018 Name:

    2. Short Answers [Amortized Analysis, Max Flow, Difference Constraints], 7+7+6 points.

    (a) Consider the following pseudocode for a procedure called INSERT. All entries of the array A are initially

    0, and the global variable n is initially 0. Considering a sequence of INSERT operations, show that the

    amortized runtime of a single invocation of the INSERT procedure is 0(1) using the accounting method.

    INSERT(x)

    n= n+1;t x for i=r0,1,... [log rt] do

    if A[i] zA 0 then t =t+A[i] A[i] = 0

    else A[i] = t return

  • ECE 345 Final Fall 2018 4 Name:____________________________

    (b) Use the Ford-Fulkerson method to find the maximum flow from s to t in the following graph. For full credit, you must:

    [5 points] Clearly show the residual graph, augmenting path, and flow network for each iteration, writing clearly. Use depth-first search to find augmenting paths. When you have multiple choices for edges to follow, always select the edge with the largest capacity.

    [2 points] Highlight a minimum cut in the original graph shown below and show its capacity. Do not redraw the graph, use the one provided below.

    v 22 7

    ..Y

    all 23

    23 21

  • ECE 345 Final Fall 2018 Name:

    (c) We want to find a feasible solution or determine that no solution exists for the following system of

    difference constraints using the Bellman-Ford algorithm:

    X2 - X1 < 5 - x4 < 2

    X3 - X2 < —10 X4 - x3 < 3 - 4

    X1 - x4

  • ECE 345 Final - Fall 2018 6 Name:

    Greedy Algorithms, 6+2+6+6 points. You have been tasked with deciding where to build public art installations along a major street. You've decided to accept bribes from local businesses in exchange for locating the art installations near their store fronts. You have taken bribes from n businesses located at positions b1, b2, .. . , b metres along the street where b1 < b2 < ... < b,. In order to satisfy your clients, you must place an art installation within 250m of each of their businesses. Your goal is to satisfy all clients with as few art installations as possible. In other words, you must choose a set A = {al,a2,.. . ,am } such that for all 1 < i < n, there exists an aj E A with - a3 I < 250. You must also minimize the size of the set A.

    For example, if b1 = 1000, b2 = 1500, and b3 = 1750, one possible solution is A = 1750, 1250, 2000}. An optimal solution would be A = {1250, 20001.

    (a) Devise a greedy algorithm that finds an optimal set of art installation positions A to satisfy a set of business locations B.

    (b) Show that after making your first greedy choice, the problem is reduced to a smaller subproblem.

  • ECE 345 Final Fall 2018 Name:

    Prove the greedy choice property by showing that there is an optimal solution whose first art installation

    position is the same as the first one selected by your greedy algorithm.

    Prove the problem's optimal substructure by showing that the optimal solution to the subproblem

    (described in (b)) combined with the greedy choice leads to an optimal solution.

  • ECE 345 Final Fall 2018 Name:

    4. Shortest Paths, 15+5 points.

    You are given a directed weighted graph C = (V, E) with positive edge weights and two vertices s, t E V. You are traversing the graph from s to t in a special vehicle that allows you to traverse one edge on your path for free (at a cost of 0), regardless of the weight on the edge. Thus, the length of a path v1, v2, . . . , Vn in C is defined as the usual shortest path length minus the weight of the heaviest edge:

    n-i

    w(v,vi)— max w(v,v+i) j=i

    1

  • ECE 345 Final Fall 2018 Name:

    (b) Consider the graph C shown below. Draw the graph C' constructed by your algorithm from part (a). What is the special vehicle's shortest path from s to t in C? What is the corresponding shortest path in C'?

  • ECE 345 Final Fall 2018 10 Name:

    5. NP-Completeness, 3+12+5 points.

    Let C be a weighted undirected graph. A Hamiltonian cycle of C is heavy if the total weight of edges in the cycle is more than half the total weight of all edges in G.

    Consider the HEAVY-HAM-CYCLE problem as defined below.

    HEAVY-HAM-CYCLE: Given a weighted undirected graph C = (V, E) with non-negative edge weights, does C contain a heavy Hamiltonian cycle? That is, does C contain a cycle C where C visits every vertex exactly once and:

    > w(u,v)> (u,v)EC (u,v)EE

    (a) Show that HEAVY-HAM-CYCLE is in NP. Clearly explain the form of the certificate as well as how to verify it in polynomial time.

  • ECE 345 Final Fall 2018 11 Name:

    (b) Consider the problem HAM-PATH defined below.

    HAM-PATH: Given an unweighted undirected graph G = (V, E) does C contain a path that visits every vertex exactly once (i.e., a Hamiltonian path)?

    Assume HAM-PATH is NP-complete. Show that HEAVY-HAM-CYCLE is NP-hard by reducing from HAM-PATH

    to HEAVY-HAM-CYCLE. In other words, show that HAM-PATH

  • ECE 345 Final Fall 2018 12 Name:

    (c) Consider the graph C below. Draw the graph H that results from applying your reduction in part (b) to G. Clearly indicate a Hamiltonian path in C and a corresponding heavy Hamiltonian cycle in H.

  • ECE 345 Final - Fall 2018 13 Name:

    (DO NOT REMOVE - This page left intentionally blank)

  • ECE 345 Final Fall 2018 14 Name:

    (DO NOT REMOVE - This page left intentionally blank)

  • ECE 345 Final Fall 2018 15 Name:

    (DO NOT REMOVE - This page left intentionally blank)