Exam Datenstrukturen und Algorithmen D-INFK

Similar documents
Exam Datenstrukturen und Algorithmen D-INFK

Exam Datenstrukturen und Algorithmen D-INFK

Exam Datenstrukturen und Algorithmen D-INFK

Student number: Datenstrukturen & Algorithmen page 1

Student number: Datenstrukturen & Algorithmen page 1

Datenstrukturen & Algorithmen Solution of Sheet 11 FS 14

Datenstrukturen & Algorithmen Blatt P13 HS 18

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

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

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

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

CPSC 331 Term Test #2 March 26, 2007

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

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

ECE250: Algorithms and Data Structures Midterm Review

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

Problem Set 6 Due: 11:59 Sunday, April 29

Datenstrukturen & Algorithmen Blatt P7 HS 18

We don t have much time, so we don t teach them [students]; we acquaint them with things that they can learn. Charles E. Leiserson

Exam Datastrukturer. DIT960 / DIT961, VT-18 Göteborgs Universitet, CSE

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

CSE 332, Spring 2010, Midterm Examination 30 April 2010

ECE 250 Algorithms and Data Structures

Exam A Informatik D-MATH/D-PHYS :15 14:55

CSE373 Fall 2013, Midterm Examination October 18, 2013

Spring 2002: Fundamental Structures of Computer Science

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

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

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

Midterm solutions. n f 3 (n) = 3

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

You have 90 minutes to complete the exam of InformatikIIb. The following rules apply:

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

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY

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

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

Exam B Informatik D-MATH/D-PHYS :15 14:55

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

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

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

Practice Midterm Exam Solutions

Algorithms, Probability, and Computing Midterm Exam HS17

CS 2150 Final Exam, Spring 2018 Page 1 of 10 UVa userid:

Exam Informatik D-MATH/D-PHYS :00 11:00

2. (a) Explain the concept of virtual functions in C++ with suitable examples. (b) Explain the concept of operator overloading in C++.

Name: 1 stack<int> s; 2 s.push(9) 3 s.push(5) 4 s.push(10) 5 s.push(1) 6 s.pop() 7 s.pop() 8 s.push(0) 9 s.pop() 10 s.pop() 11 s.

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

CS 112 Final May 8, 2008 (Lightly edited for 2012 Practice) Name: BU ID: Instructions

Final Examination CSE 100 UCSD (Practice)

ECE 250 Algorithms and Data Structures

Computer Science Foundation Exam

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

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

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

CSL 201 Data Structures Mid-Semester Exam minutes

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

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

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2017

Exam Datastrukturer. DIT960 / DIT961, VT-18 Göteborgs Universitet, CSE

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

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

Course Review for Finals. Cpt S 223 Fall 2008

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

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

ASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n))

Question Bank Subject: Advanced Data Structures Class: SE Computer

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING ECE 250 ALGORITHMS AND DATA STRUCTURES

Computer Science 136 Spring 2004 Professor Bruce. Final Examination May 19, 2004

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

21# 33# 90# 91# 34# # 39# # # 31# 98# 0# 1# 2# 3# 4# 5# 6# 7# 8# 9# 10# #

6.7 b. Show that a heap of eight elements can be constructed in eight comparisons between heap elements. Tournament of pairwise comparisons

ECE242 Data Structures and Algorithms Fall 2008

Math 454 Final Exam, Fall 2005

Exam Informatik D-MATH/D-PHYS :00 17:00

Computer Science E-22 Practice Final Exam

~UTS UNIVERSITY OF TECHNOLOGY SYDNEY

Questions Total Points Score

Technical University of Denmark

Introduction to Algorithms December 16, 2011 Massachusetts Institute of Technology Fall 2011 Professors Erik Demaine and Srini Devadas

Computer Science Foundation Exam

CS1800 Discrete Structures Final Version B

INFO1x05 Tutorial 09

END-TERM EXAMINATION

Computer Science Foundation Exam

(D) There is a constant value n 0 1 such that B is faster than A for every input of size. n n 0.

CS 3114 Data Structures and Algorithms READ THIS NOW!

York University AK/ITEC INTRODUCTION TO DATA STRUCTURES. Final Sample II. Examiner: S. Chen Duration: Three hours

Prelim 2. 5:30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs. Max Score Grader

Data Structure and Algorithm, Spring 2013 Midterm Examination 120 points Time: 2:20pm-5:20pm (180 minutes), Tuesday, April 16, 2013

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

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING ECE 250 ALGORITHMS AND DATA STRUCTURES

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

Questions Total Points Score

Computer Science 302 Fall 2018 (Practice for) Third Examination, November 14, 2018

Final Exam May 6, 2015

Solutions to Exam Data structures (X and NV)

INSTITUTE OF AERONAUTICAL ENGINEERING

INF2220: algorithms and data structures Series 1

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.

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

Transcription:

Eidgenössische Technische Hochschule Zürich Ecole polytechnique fédérale de Zurich Politecnico federale di Zurigo Federal Institute of Technology at Zurich Institut für Theoretische Informatik Peter Widmayer Thomas Tschager Exam Datenstrukturen und Algorithmen D-INFK January 27, 2016 Last name, first name: Student number: With my signature I confirm that I was able to participate in the exam under regular conditions, and that I read and understood the notes below. Signature: Please note: You may not use any accessories except for a dictionary and writing materials. Please write your student number on every sheet. Immediately report any circumstances that disturb you during the exam. Use a new sheet for every problem. You may only give one solution for each problem. Invalid attempts need to be clearly crossed out. Please write legibly with blue or black ink. We will only grade what we can read. If not explicitly asked for, you may use algorithms and data structures of the lecture without explaining them again. If you modify them, it suffices to explain your modifications. You have 180 minutes to solve the exam. Good luck!

Datenstrukturen & Algorithmen Student number: problem 1 2 3 4 Σ max. score 17 11 8 12 48 score

Datenstrukturen & Algorithmen

Student number: Datenstrukturen & Algorithmen page 1 Problem 1. Please note: 1) In this problem, you have to provide solutions only. You can write them directly on this sheet. 2) If you use algorithms and notation other than that of the lecture, you need to briefly explain them in such a way that the results can be understood and checked. 3) We assume letters to be ordered alphabetically and numbers to be ordered ascendingly, according to their values. a) Insert the keys 18, 4, 17, 7, 15, 29 in this order into the hash table below. Use double hashing with the hash function h(k) = k mod 11. Resolve collisions using h (k) = 1 + (k mod 9) for probing (to the left). 0 1 2 3 4 5 6 7 8 9 10 b) Insert the closed intervals [1, 3], [1, 5], [4, 6], [2, 4], [2, 2] and [1, 2] in the following interval tree. Mark all nodes that are visited in a query for x = 2.5. 4 u: d: 2 u: d: 6 u: d: u: 1 d: 3 u: d: u: 5 d: 7 u: d: c) Consider the following self-organizing list. Provide the number of key comparisons when the elements C, B, D and B are accessed in this order using the Move-to-Front rule. A B C D E

Student number: Datenstrukturen & Algorithmen page 2 d) Mark in the following graph the first edge that is visited by the algorithm of Kruskal, but not added to the minimum spanning tree. 5 12 8 1 4 2 7 11 e) Given the following graph G = (V, E), provide a set E E of smallest cardinality, such that G = (V, E \ E ) can be sorted topologically. Provide also a topological ordering for G. v w E = z topological ordering for G : x y f) Draw a connected graph on six vertices that has exactly two perfect matchings.

Student number: Datenstrukturen & Algorithmen page 3 g) The following array contains the elements of a min-heap stored in the usual fashion. Specify the array after the minimum has been removed and the heap condition has been reestablished. 2 8 10 9 12 15 11 13 14 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 h) Draw an AVL tree with five vertices and the keys stored in these vertices, such that the insertion of a sixth key leads to a left-right double rotation. Indicate which key has to be added and draw the resulting AVL tree. Before the insertion of the 6th key: After the insertion of the 6th key: Key that has to be inserted:

Student number: Datenstrukturen & Algorithmen page 4 3 P i) Consider the following recursive formula: { 4T (n/4) + n + 6 n > 1 T (n) := 1 n = 1 Specify a closed (i.e., non-recursive) form for T (n) that is as simple as possible, and prove its correctness using mathematical induction. You may assume that n is a power of 4. Hint: For q 1, we have k i=0 qi = qk+1 1 q 1.

Student number: Datenstrukturen & Algorithmen page 5 j) Specify (as concisely as possible) the asymptotic running time of the following code fragment in Θ notation depending on n N. You do not need to justify your answer. 1 for(int i = 1; i < n; i = 2 i) 2 for(int j = n; j >= 0; j = j 1) 3 ; k) Specify (as concisely as possible) the asymptotic running time of the following code fragment in Θ notation depending on n N. You do not need to justify your answer. 1 for(int i = 1; i < n; i = i+2) { 2 for(int j = 1; 2*j <= i; j = j + 1) 3 ; 4 int k = n; 5 while(k > 2) 6 k = k / 2; 7 } l) Specify (as concisely as possible) the asymptotic running time of the following code fragment in Θ notation depending on n N. You do not need to justify your answer. 1 for(int i = 1; i*i < n; i = i+2) { 2 for(int j = 1; j/2 <= n; j = j + 4) 3 ; 4 }

Student number: Datenstrukturen & Algorithmen page 6 g) Specify an order for the functions below such that the following holds: If function f is left of function g, then f O(g). Example: The three functions n 3, n 7, n 9 are already in a correct order, since n 3 O(n 7 ) and n 7 O(n 9 ). ( ) n log(n 4n ),, 16 5 n n, log(n), n + n3, n!, 1052 24 2 P n) For each of the following statements, mark with a cross whether it is true or false. Every correct answer gives 0.5 points, for every wrong answer 0.5 points are removed. A missing answer gives 0 points. In overall the question gives at least 0 points. You do not have to justify your answers. A binary search tree is balanced. True False Let G = (V, E) be a connected graph. Every spanning tree of G has exactly V 1 edges. True False Selection sort and insertion sort are in-situ sorting algorithms. True False If you only insert keys into an empty binary search tree (and no key is removed), then the insertion order corresponds exactly to the preorder traversal. True False

Student number: Datenstrukturen & Algorithmen page 7 Problem 2. Problem definition. 2n components are placed on a circuit board in two layers with n components each. Every component of the upper layer is assigned to exactly one component of the lower layer and vice versa. These pairs of components should be connected by straight circuit paths. Develop an algorithm that computes how many components can by connected at most if no two circuit paths are allowed to intersect. 1 2 3 4 5 2 1 5 3 4 Example: In the figure above 10 components are placed on a circuit board. Components with the same numbering should be connected. In this example, there exist two solutions in which three pairs of components can be connected: (i) components with numbers 1, 3 and 4. (ii) components with numbers 2, 3 and 4. 7 P 2 P 2 P a) Provide a dynamic programming algorithm that is as efficient as possible asymptotically for computing the maximum number of circuit paths that do not intersect pairwise. Address the following aspects in your solution. 1) What is the meaning of a table entry, and what size does the DP table have? 2) How can an entry be computed? 3) Describe the order of the computation steps. 4) How can the maximum number of non-intersecting circuit paths be obtained from the DP table? Hint: The trivial algorithm that simply enumerates all possible solutions does not give any points (as is it not efficient). b) Describe in detail how the algorithm can be modified such that it additionally computes a set of non-intersecting circuit paths of maximum cardinality. c) Provide the running time of the algorithms developed in a) and in b), and justify your answer.

Student number: Datenstrukturen & Algorithmen page 8

Student number: Datenstrukturen & Algorithmen page 9 Problem 3. 6 P a) There are n assistants and m exercise groups that take place at different times. Every assistant specifies which exercise groups he can supervise. An assistant can supervise at most one exercise group. Develop an algorithm to compute how many exercise groups can be supervised by the assistants. Example: An assignment of n = 3 assistants to m = 3 exercise groups should be computed (cf. table). In this example, every exercise can be supervised by an assistant: Assistant 1 supervises group 1, assistant 2 group 3 and assistant 3 group 2. Assistant exercise groups assistant 1 group 1 or 3 assistant 2 group 3 assistant 3 group 1 or 2 Model the above problem as a flow problem. For this purpose, describe the construction of an appropriate network N = (V, E, c) with the vertex set V and edge set E, and describe which capacities c the edges should have. Name an efficient algorithm for computing the maximum flow in N. What is the time complexity of this algorithm depending on n and m? How can you deduce from the value of a maximum flow how many exercise groups can be supervised? 2 P b) Now you also need to assign rooms to the exercise groups, where k rooms are available. For every exercise group it is given, which rooms are available. Compute an assignment of as many assistants as possible to exercise groups and rooms, such that no room is occupied multiple times. Example: An assignment for n = 3 assistants, m = 3 exercise groups and k = 4 rooms should be computed: assistant exercise groups exercise group available rooms assistant 1 group 1 or 3 assistant 2 group 2 assistant 3 group 2 group 1 room 1 group 2 room 1 group 3 room 2, 3 or 4 In this example, not all groups can be supervised: For example, assistant 1 can supervise group 3 in room 1 and assistant 2 group 3 in room 4. Group 1 cannot be supervised in this case, because room 1 is already occupied by group 3. Model this extended assignment problem as a flow problem. Describe the construction of an appropriate network N = (V, E, c ) with the vertex set V and edge set E, and describe which capacities c the edges should have. How can you deduce from the value of a maximum flow how many exercise groups can be supervised?

Student number: Datenstrukturen & Algorithmen page 10

Student number: Datenstrukturen & Algorithmen page 11 Problem 4. An arrangement of n roofs is represented by a set of n non-intersecting line segments: A roof is given as a line segment starting and ending at coordinates (x l, y l ) and (x r, y r ). All x-coordinates and all y-coordinates are pairwise different. It rains evenly everywhere and raindrops fall vertically on some roofs (i.e. those roofs that are not sheltered by other roofs). The rain flows to the lower ends of these roofs. Then it trickles vertically to the next roof or to the floor. Depending on the arrangement of the roofs some roofs get wet and others remain dry. You should determine the dry roofs. 9 P 3 P a) All roofs are sloped to the right, i.e. for every roof it holds that y r < y l. Thus, the right end is also the lower end for every roof. Design an efficient scanline algorithm for computing the dry roofs. Address in particular the following aspects in your solution. 1) In which direction is the scanline moving, and what are the stopping points? 2) Which objects have to be stored in the data structure, and what is an appropriate choice for it? 3) What happens if the scanline encounters a new stopping point? 4) How can the set of dry roofs be obtained? 5) Provide the running time of the algorithm in dependency of n and justify your answer. b) Now we consider arbitrarily sloped roofs. For every given roof it holds that y l y r. Describe how the algorithm can be modified such that it computes the set of dry roofs. Provide the running time of your algorithm depending on n and justify your answer. Example: In the following figures, rain is depicted as dashed lines. In the left figure for exercise a) the roofs d 4 and d 5 remain dry. In the right figure for exercise b) only d 4 remains dry. Exercise a) Exercise b) d 1 d 2 d 1 d 2 d 3 d 4 d 5 d 3 d 4 d 5 d 6