Technical University of Denmark

Similar documents
Course Review for Finals. Cpt S 223 Fall 2008

Midterm solutions. n f 3 (n) = 3

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

Data Structures Question Bank Multiple Choice

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

Solutions to Exam Data structures (X and NV)

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

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

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

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

CSE2331/5331. Topic 6: Binary Search Tree. Data structure Operations CSE 2331/5331

Basic Data Structures (Version 7) Name:

Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

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

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

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

Analysis of Algorithms

COMP 251 Winter 2017 Online quizzes with answers

Priority Queues. Priority Queues Trees and Heaps Representations of Heaps Algorithms on Heaps Building a Heap Heapsort.

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

Binary Search Trees. Nearest Neighbor Binary Search Trees Insertion Predecessor and Successor Deletion Algorithms on Trees.

CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial

Binary Search Trees. Binary Search Trees. Nearest Neighbor. Nearest Neighbor

DATA STRUCTURES AND ALGORITHMS

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

Leftist Heaps and Skew Heaps. (Leftist Heaps and Skew Heaps) Data Structures and Programming Spring / 41

CSE 5311 Notes 4a: Priority Queues

COMPSCI 311: Introduction to Algorithms First Midterm Exam, October 3, 2018

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

CISC 320 Midterm Exam

CSE 332, Spring 2010, Midterm Examination 30 April 2010

Example. Minimum-Cost Spanning Tree. Edge Selection Greedy Strategies. Edge Selection Greedy Strategies

Minimum-Cost Spanning Tree. Example

CSL 201 Data Structures Mid-Semester Exam minutes

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

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

Data Structure. IBPS SO (IT- Officer) Exam 2017

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

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

Fibonacci Heaps Priority Queues. John Ross Wallrabenstein

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

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING ADVANCED DATA STRUCTURES AND ALGORITHMS EXAM EXAMINATION JUNE 2014

CSci 231 Final Review

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

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

18.3 Deleting a key from a B-tree

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

Exam Sample Questions CS3212: Algorithms and Data Structures

Final Examination CSE 100 UCSD (Practice)

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

Data Structures Brett Bernstein

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

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

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

COS 226 Midterm Exam, Spring 2009

Heaps with merging. We can implement the other priority queue operations in terms of merging!

CS171 Final Practice Exam

CSE 100: GRAPH ALGORITHMS

Heap: A binary heap is a complete binary tree in which each, node other than root is smaller than its parent. Heap example: Fig 1. NPTEL IIT Guwahati

Multi-way Search Trees. (Multi-way Search Trees) Data Structures and Programming Spring / 25

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

Heaps Outline and Required Reading: Heaps ( 7.3) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

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

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

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

CS521 \ Notes for the Final Exam

Major2 Examination Term: 162 Year: 2016/2017

Largest Online Community of VU Students

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

Warm Up. Use Kruskal s algorithm to find the minimum spanning tree and it s weight.

Final Exam. Problem Parts Points Grade Grader Problem Parts Points Grade Grader Total 180. Name: Athena username: Joe WF3a. Joe WF2.

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

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

CS583 Lecture 01. Jana Kosecka. some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes

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.

Summer Final Exam Review Session August 5, 2009

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

CS301 - Data Structures Glossary By

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

Course Review. Cpt S 223 Fall 2009

Matriculation number:

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

Questions Total Points Score

Priority queues. Priority queues. Priority queue operations

Notes on Minimum Spanning Trees. Red Rule: Given a cycle containing no red edges, select a maximum uncolored edge on the cycle, and color it red.

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

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

Recitation 9. Prelim Review

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

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

EXAM ELEMENTARY MATH FOR GMT: ALGORITHM ANALYSIS NOVEMBER 7, 2013, 13:15-16:15, RUPPERT D

Outline. Computer Science 331. Heap Shape. Binary Heaps. Heap Sort. Insertion Deletion. Mike Jacobson. HeapSort Priority Queues.

: Fundamental Data Structures and Algorithms. June 06, 2011 SOLUTIONS

2. (a) Explain when the Quick sort is preferred to merge sort and vice-versa.

CSE 100 Advanced Data Structures

Transcription:

Technical University of Denmark Written examination, May 7, 27. Course name: Algorithms and Data Structures Course number: 2326 Aids: Written aids. It is not permitted to bring a calculator. Duration: hours. Weights: Exercise - 2 %, Exercise 2-25 %, Exercise 3-2 %, Exercise - 3 %, Exercise 5-22 %. The weights are approximate. The grade is given based on an overall assessment. All exercise should be answered by filling out the areas below the description. As your solution to the exam, just hand in the page and the following pages. If you need more space, you may use extra pieces of paper and hand these in along with your solution. Asymptotic bounds should be as tight as possible. Unless otherwise specified, the base of all logarithms is 2 and log k n means (log n) k. Name: Student ID: Exam 2326, Spring 27 page of

Complexity. (5 %) For each statement below, mark whether or not it is correct: n3 + n 2 log n + 7 n 2 = Θ(n 3 ) 7 + (n 3 ) 2 + log 2 n = O(n 5 ) 2 log n + n + n /3 = Ω( n) 2 log n + n,5 3 3 + log n = Θ(n) (log n)(log 2 n + log n) = O(log 2 n) Yes No.2 (5 %) Arrange the following functions in increasing order according to asymptotic growth. That is, if g(n) immediately follows f (n) in your list, it must hold that f (n) = O (g(n)). 8 n log(2 n ) 7n 3 n 3 log 2 n n /2.3 ( %) State the running time for each of the following algorithms. Write your answer in O-notation as a function of n. ALG(n) c = for i = to n/3 do c = c + end for for j = to n/5 do c = c + end for ALG2(n) if n then return else return +ALG2(n 2) end if ALG3(n) for j = to n do i = n while i 3 do i = i/2 end while end for Exam 2326, Spring 27 page 2 of

2 Data Structures Consider the following forest of trees representing a family of sets in a union find data structure constructed using the quick union algorithm. 3 2 3 6 5 6 7 8 5 7 8 2 9 2. (5 %) State the results of the following FIND( ) operations. FIND(2) : FIND() : FIND() : FIND(8) : FIND(2) : FIND(7) : 2.2 (5 %) Assume that we now use path compression on the forest above. Show the forest of trees after a FIND(8) operation. Exam 2326, Spring 27 page 3 of

2.3 (5 %) Consider the following max heaps H and H 2. 32 H H 2 29 8 8 9 7 6 9 3 6 Draw H after an INSERT operation with key 2. 2. (5 %) Draw H 2 after an EXTRACT-MAX operation. 2.5 (5 %) We want to support the DELETE-MAX() operation on each of the following data structures. DELETE-MAX() should remove the largest element in the data structure and then reestablish the data structure over the remaining elements. As an example, if the data structure is a min heap with elements {6, 32, 8, 7, 2}, DELETE-MAX() removes element 32 and re-establishes a min heap with the elements {6, 8, 7, 2}. For each of the data structures, state the time needed to perform a DELETE-MAX() operation in O-notation as a function of n, where n is the number of elements in the data structure. Singly-linked list: Doubly-linked list: Max heap: Min heap: Binary search tree: Exam 2326, Spring 27 page of

3 Graphs Consider the following graph G. 2 3 5 6 7 8 9 3. (5 %) Show the DFS tree for G when starting in node and state the discovery and finish times for each node. Assume that the adjacency lists are sorted in increasing order. 2 3 5 6 7 8 9 3.2 (5 %) Show the BFS tree for G when starting in node and state the distance for each node. Assume that the adjacency lists are sorted in increasing order. 2 3 5 6 7 8 9 Exam 2326, Spring 27 page 5 of

3.3 (5 %) Consider the graph below. Show a shortest path tree for the graph starting at node. State the length of the shortest path from node to each node. 3 6 2 3 6 8 7 8 3 6 7 5 7 6 5 2 2 8 9 2 3 5 6 7 8 9 3. (5 %) Consider the graph below. Show a minimum spanning tree and state the total weight of the tree. 3 7 6 2 3 6 3 8 7 8 3 6 7 5 7 6 5 2 2 8 9 2 3 5 6 7 8 9 Total weight: Exam 2326, Spring 27 page 6 of

Trees This exercise is about rooted binary trees. Any node x has fields x.parent, x.left and x.right denoting the parent, left child, and right child of x, respectively. The root r has r.parent = null. Furthermore, any node has a weight given by the field x.weight.. ( %) Let x be a node in the tree. The node x is skewed according to the following conditions. If x is a leaf then x is skewed. If x is an internal node with two children then x is skewed if and only if x.left.weight < x.weight < x.right.weight. If x is an internal node with a left child but no right child then x is skewed if and only if x.left.weight < x.weight. If x is an internal node with a right child but no left child then x is skewed if and only if x.weight < x.right.weight. Consider the following tree. Mark all skewed nodes in the tree with a cross. 6 3 7 7 5 2 8 5 Exam 2326, Spring 27 page 7 of

.2 (5 %) Give an algorithm, SKEWED(X), that given a node x returns true if and only if the node is skewed. Write your algorithm in pseudocode and analyze the running time of your algorithm as a function of n, where n is the number of nodes in the tree. Exam 2326, Spring 27 page 8 of

.3 (7 %) Give a recursive algorithm, SKEWCOUNT(x), that, given the root node, computes the number of skewed nodes in the tree. Write your algorithm in pseudocode and analyze the running time of your algorithm as a function of n, where n is the number of nodes in the tree. Exam 2326, Spring 27 page 9 of

5 Super Mario Run 8 8 7 7 6 6 5 5 goal goal 3 3 2 start 2 start 2 3 5 6 7 8 2 3 5 6 7 8 (a) (b) Figure : 8 8 Mario world and corresponding Mario graph. A Mario world M consists of a k k grid. Each field in the grid is empty or brick. Two empty fields are marked as start and goal (see Fig. 5(a)). The goal of the game is to move the player, called Mario, from the start field to the goal field. When Mario is in field (x, y) he has the following options: Forward Mario moves to the field (x +, y). This move is possible if (x +, y) is empty and (x +, y ) is brick. Jump Mario moves to the field (x +, y + 2). This move is possible if (x +, y + 2) is empty, (x, y + ) is empty, and (x +, y + ) is brick. Fall Mario moves to the field (x +, y ) where y < y is the maximal value y such that (x +, y ) is brick and (x +, y), (x +, y ),..., (x +, y ) are empty. For instance, Mario in field (, ) can move forward to (5, ) or jump to field (5, 6). A move is valid if the move can be done according to the above rules. All fields that can be reached via valid moves from the start field are the valid fields. For example, (, ) is a valid field, since it can be reached from the start field in (, 2) doing the sequence of valid moves: forward, forward, jump. A Mario world M defines a directed graph G with n vertices and m edges (see Fig. 5(b)). All valid fields correspond to a vertex and the valid moves define the edges (there is an edge from field (x, y) to field (x, y ) if Mario can move from (x, y) to (x, y ) with a valid move). The edges corresponding to forward, jump and fall are denoted by forward edges, jump edges and fall edges. 5. (3 %) Let M be a Mario world defined on a k k grid and let G be the corresponding Mario graph. Give the maximum number of nodes n that can appear in G as a function of k. O(log k) O( k) O(k) O(k log k) O(k 2 ) O(2 k ) Give the maximum number of edges m that can appear in G as a function of k. O(log k) O( k) O(k) O(k log k) O(k 2 ) O(2 k ) Exam 2326, Spring 27 page of

5.2 (6 %) We are now interested in checking if it is possible to go from the start field to the goal field. A Mario graph is valid if there exists a path from start to goal. Give an algorithm that given a Mario graph G, decides whether or not there is a path from the start field to the goal field. Analyze the running time of your algorithm as a function of n and m. Exam 2326, Spring 27 page of

5.3 (5 %) It s tough work for Mario to jump and fall. Thus, we associate a price with each edge e, price(e), such that a forward edge costs, a jump edge costs 2 2 and a fall edge costs. We define the price of a path to be the sum of the prices on the edges of the path. Give an algorithm which, given a valid Mario graph, finds a cheapest path from the start field to the goal field. Analyze the running time of your algorithm as a function of n and m. Exam 2326, Spring 27 page 2 of

5. (5 %) Now, we re also interested in collecting a mushroom during the game. A mushroom graph is a valid Mario graph where a single node c is marked as a mushroom node and there exists a path from start to goal going through c. Give an algorithm which, given a mushroom graph, finds a cheapest path from the start field to the goal field going through c. Analyze the running time of your algorithm as a function of n and m. Exam 2326, Spring 27 page 3 of

5.5 (3 %) A k-mushroom graph is a valid Mario graph where k nodes c,..., c k are marked as mushroom nodes and for each mushroom c i, i k, there exists a path from start to goal going through c i. A mushroom path in a k-mushroom graph is a path from start to goal going through at least one of the k mushrooms. Give an algorithm which, given a k-mushroom graph, finds a cheapest mushroom path from the start field to the goal field. Analyze the running time of your algorithm as a function of n, m and k. Exam 2326, Spring 27 page of