Student number: Datenstrukturen & Algorithmen page 1

Similar documents
Student number: Datenstrukturen & Algorithmen page 1

Exam Datenstrukturen und Algorithmen D-INFK

Exam Datenstrukturen und Algorithmen D-INFK

Exam Datenstrukturen und Algorithmen D-INFK

Exam Datenstrukturen und Algorithmen D-INFK

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

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

CPSC 331 Term Test #2 March 26, 2007

Course Review. Cpt S 223 Fall 2009

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

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

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))

3. According to universal addressing, what is the address of vertex d? 4. According to universal addressing, what is the address of vertex f?

CSE 332, Spring 2010, Midterm Examination 30 April 2010

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

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

Course Review for Finals. Cpt S 223 Fall 2008

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

ECE250: Algorithms and Data Structures Midterm Review

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

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

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

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

INF2220: algorithms and data structures Series 1

INSTITUTE OF AERONAUTICAL ENGINEERING

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

Analysis of Algorithms

Data Structures Question Bank Multiple Choice

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

COS 226 Midterm Exam, Spring 2011

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

Lecture 6: Analysis of Algorithms (CS )

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

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

Part 1: Written Questions (60 marks):

銘傳大學九十二學年度轉學生招生考試 七月二十六日第三節 資料結構試題

VALLIAMMAI ENGINEERING COLLEGE

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

Section Summary. Introduction to Trees Rooted Trees Trees as Models Properties of Trees

CS301 - Data Structures Glossary By

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

Course Review. Cpt S 223 Fall 2010

Recitation 9. Prelim Review

CSE373 Fall 2013, Midterm Examination October 18, 2013

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g)

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

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

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

ECE 250 Algorithms and Data Structures

CS302 Data Structures using C++

& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n

END-TERM EXAMINATION

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

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

~UTS UNIVERSITY OF TECHNOLOGY SYDNEY

CSE 373 APRIL 17 TH TREE BALANCE AND AVL

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

Solutions to Exam Data structures (X and NV)

ECE242 Data Structures and Algorithms Fall 2008

Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College!

Lecture: Analysis of Algorithms (CS )

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

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Multiple-choice (35 pt.)

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

CSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Mid-Term Exam. CSE2100 DS & Algorithms 1

Section 1: True / False (2 points each, 30 pts total)

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

FINAL EXAM SOLUTIONS

Test 1 - Closed Book Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

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

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

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

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

Friday, March 30. Last time we were talking about traversal of a rooted ordered tree, having defined preorder traversal. We will continue from there.

CS 3114 Data Structures and Algorithms READ THIS NOW!

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

Table of Contents. Chapter 1: Introduction to Data Structures... 1

Faculty of Science FINAL EXAMINATION

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

Course goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance

Lecture 13: AVL Trees and Binary Heaps

MLR Institute of Technology

TREES. Trees - Introduction

Your favorite blog : (popularly known as VIJAY JOTANI S BLOG..now in facebook.join ON FB VIJAY

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

Computer Science E-22 Practice Final Exam

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

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

Data Structures and Algorithms for Engineers

CS1800 Discrete Structures Final Version B

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

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

INFO1x05 Tutorial 09

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

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

Computer Science Foundation Exam

Question Bank Subject: Advanced Data Structures Class: SE Computer

Transcription:

Student number: Datenstrukturen & Algorithmen page 1 Problem 1. / 16 P Instructions: 1) In this problem, you have to provide solutions only. You can write them right on this sheet. 2) You may use the notation, algorithms and data structures that were discussed in the lecture Datenstrukturen & Algorithmen without further explanations. If you use other methods, 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) Perform two iterations of Insertion Sort on the following array. The array has already been sorted by previous iterations up to the double bar. 3 7 10 15 8 6 9 5 2 13 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 b) Insert the keys 20, 24, 31 and 7 in this order into the hash table below. Use open hashing with the hash function h(k) = k mod 11. Resolve collisions using quadratic probing. In case of a collision, first try probing to the left and only after that, to the right. 11 15 5 19 9 0 1 2 3 4 5 6 7 8 9 10

Student number: Datenstrukturen & Algorithmen page 2 c) On the following union-find data structure, execute Union(h, Find(g)). Use union by height, and draw the data structure that results after the operation. After the operation: a c h b d e f g d) 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. 1 3 6 4 9 7 10 13 8 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 e) Specify a sequence of queries of smallest possible size that turns the list A B C D E F into the following list by applying the Move-to-Front rule: D A C B E F Queries:

Student number: Datenstrukturen & Algorithmen page 3 f) The following graph is traversed starting at vertex A. The neighbors of a vertex are visited in alphabetical order. Provide the two sequences in which a depth-first search and a breadth-first search visit the vertices. A B C Depth-first search: E G A,,,,,. Breadth-first search: F A,,,,,. g) Draw the natural search tree T that results if you insert the keys 5, 4, 8, 7, 1, 6, 10 in this order in an initially empty natural search tree. Provide the preorder, postorder and inorder traversal of the keys in T. natural search tree T : preorder traversal: inorder traversal: postorder traversal:

Student number: Datenstrukturen & Algorithmen page 4 / 2 P h) For each of the following data structures, mark with a cross whether the tree it uses is balanced (i.e. guarantees a height logarithmic in the number of stored keys) or not balanced. 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 exercise gives at least 0 points. You do not have to justify your answers. B-tree balanced not balanced Heap balanced not balanced AVL tree balanced not balanced Natural search tree balanced not balanced i) Which AVL tree results from first removing key 7 and afterwards inserting key 5 into the following AVL tree? 8 6 9 2 7 10 1 4 6 8 6 2 9 2 9 4 9 1 4 8 10 1 5 10 2 5 8 10 5 4 6 1 8 5 8 5 9 2 8 2 9 2 6 10 1 4 6 9 4 6 10 1 4 10 1 5

Student number: Datenstrukturen & Algorithmen page 5 / 3 P j) Consider the following recursive formula: { 5 T (n/8) + 8 n > 1 T (n) := 1 n = 1 Specify a closed (non-recursive) form for T (n) that is as simple as possible, and prove its correctness using mathematical induction. Hints: (1) You may assume that n is a power of 8. That is, use n = 8 k or k = log 8 (n). (2) For q 1, we have k i=0 qi = qk+1 1 q 1. Derivation (if required): Closed and simplified form: T (n) = T (8 k ) = Proof by induction:

Student number: Datenstrukturen & Algorithmen page 6 Proof by induction (continuation):

Student number: Datenstrukturen & Algorithmen page 7 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 = n; i >= 1; i = i - 5 ) { 2 int j = n; 3 while ( j > 1 ) { 4 j = j / 2; 5 } 6 } Running time as concisely as possible in Θ notation: 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 <= n; i = i + 1 ) { 2 for ( int j = 1; j < 2 * i; j = j + 2) { 3 ; 4 } 5 } Running time as concisely as possible in Θ notation: m) Specify an order for the functions below such that the following holds: If a function f is left of a 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 2 log(n), log(n2 ), 6 n, 2 15, n ( ) n n,, n log(n) 6 Solution:,,,,,,.

Student number: Datenstrukturen & Algorithmen page 8 Problem 2. / 10 P A palindrome is a sequence of characters whose meaning may be interpreted the same way in either forward or reverse direction, e.g. the word RACECAR. Formally, a palindrome is a character sequence of length 0 or 1, or a character sequence a 1,..., a l where a 1 = a l and a 2,..., a l 1 is a palindrome. You are given a sequence of characters Z = a 1,..., a n of length n. We say that Z contains a palindrome P if P is a (not necessarily contiguous) subsequence of Z. We are searching for the longest palindrome that is contained in Z. Example: The character sequence Z = A, N, A, N, A, S contains the palindrome of length 0, and the palindromes A, N, S, AA, NN, AAA, ANA, NAN, ANNA and ANANA (some of these palindromes occur multiple times). The longest palindrome contained in Z therefore is ANANA. For the above problem, design a dynamic programming algorithm. Address the following aspects in your solution. 1) What is the meaning of a table entry, and which size does the DP table have? 2) How can the table be initialized, and how can an entry be computed from the values of other entries? 3) In which order do the entries have to be computed? 4) How can the final solution be extracted once the table has been filled? Provide also the running time of your solution, and justify your answer.

Student number: Datenstrukturen & Algorithmen page 9 Size of the DP table / Number of entries: Meaning of a table entry: DP [ ]: Computation of an entry: DP [ ] = Order of computation:

Student number: Datenstrukturen & Algorithmen page 10 Computing the longest contained palindrome: Running time (with justification):

Student number: Datenstrukturen & Algorithmen page 11

Student number: Datenstrukturen & Algorithmen page 12 Problem 3. / 7 P Two computers should communicate reliably over a network. The computers are not necessarily directly connected, but in general send packages over several intermediate stations through the network. We want to make sure that a computer can send packages to the other computer even if a single, arbitrary connection in the network fails. The network is given as a set V of vertices and a set E of (directed) connections between two vertices each. Moreover, two vertices s and t in V are given that should communicate with each other. / 3 P a) We want to decide whether s is able to send packages to t even if a single, arbitrary connection in E is broken. For this purpose, model the above problem as a flow problem. Describe the construction of an appropriate network N a = (V a, E a, c a ), and describe which capacities c a the edges should have. How can you deduce from the value of a maximum flow if the communication from s to t is always possible if a single, arbitrary connection in E is broken? s a b c d e t Example: In the network depicted on the left, the vertex s can send packages to vertex t even if a single, arbitrary edge is removed. / 4 P b) Now we want to decide whether the vertex s is able to send packages to t if a vertex in V \{s, t} is broken and cannot be used. For this purpose, model this problem as a flow problem and describe an appropriate network N b = (V b, E b, c b ). How can you deduce from the value of a maximum flow in this modified network if the communication from s to t is possible if only a single vertex is removed? Example: In the network depicted above, the vertex s cannot send a package to the vertex t if vertex d cannot be used.

Student number: Datenstrukturen & Algorithmen page 13 Subtask a) Definition of the network N a (if possible in words and not formally): Vertex set V a : Edge set E a : Capacities c a : Schematic representation / drawing of the network: Communication from s to t is possible if:

Student number: Datenstrukturen & Algorithmen page 14 Subtask b) Definition of the network N b (if possible in words and not formally): Vertex set V b : Edge set E b : Capacities c b : Schematic representation / drawing of the network: Communication from s to t is possible if:

Student number: Datenstrukturen & Algorithmen page 15

Student number: Datenstrukturen & Algorithmen page 16 Problem 4. / 9 P You are given a set of n points P 1,..., P n with P i = (x i, y i ) Q 2 for all i {1,..., n}. No two points have the same x or y coordinates. Moreover you are given a set of m axis-parallel rectangles R 1,..., R m in the plane. Every rectangle R j with j {1,..., m} is specified by its left lower corner point (l j, u j ) Q 2 and its right upper corner point (r j, o j ) Q 2. No two rectangles overlap or touch each other, and no point P i is placed exactly on the border of a rectangle. We want to find all points that are not within one of the m rectangles. Example: In the figure on the right, five rectangles and eight points are shown. The points P 1, P 4, and P 7 are not within one of the rectangles. P 1 P 2 P 3 P 4 P 5 P 7 P 8 P 6 Design an efficient sweepline algorithm for the above problem. Address the following aspects in your solution. 1) In which direction is the sweepline moving, and what are the stopping points? 2) Which objects are maintained by the sweepline data structure, and what is an appropriate choice for this data structure? 3) What happens if the sweepline encounters a new stopping point? 4) How can the points that are not within a rectangle be recognized? 5) Provide the running time of your algorithm depending on n and m. Justify your answer.

Student number: Datenstrukturen & Algorithmen page 17 Movement of the sweepline (choose exactly one option): The sweepline is a vertical line; it moves from left to right / from right to left. The sweepline is a horizontal line; it moves from top to bottom / from bottom to top. The sweepline is a half-line; it rotates in clockwise direction / in counter clockwise direction around point. other movement:. Stopping points: set of stopping points: ordered by: Sweepline data structure: Operations when encountering a new stopping point:

Student number: Datenstrukturen & Algorithmen page 18 Computation of the solution: Running time of the algorithm: