Examination paper for TDT4120 Algorithms and Data Structures

Similar documents
Lecture 20: Combinatorial Search (1997) Steven Skiena. skiena

Homework Assignment #1

Common Mistakes. Quick sort. Only choosing one pivot per iteration. At each iteration, one pivot per sublist should be chosen.

Chapter 5 Backtracking. The Backtracking Technique The n-queens Problem The Sum-of-Subsets Problem Graph Coloring The 0-1 Knapsack Problem

Problem Set 7: Network Flows Fall 2018


A Level Computer Science H446/02 Algorithms and programming. Practice paper - Set 1. Time allowed: 2 hours 30 minutes

4.4 Shortest Paths in a Graph Revisited

Decision Mathematics D1 Advanced/Advanced Subsidiary. Friday 17 May 2013 Morning Time: 1 hour 30 minutes

Midterm Examination. CSCI 561: Artificial Intelligence

Eight Queens Puzzle Solution Using MATLAB EE2013 Project

CS61B Lecture #22. Today: Backtracking searches, game trees (DSIJ, Section 6.5) Last modified: Mon Oct 17 20:55: CS61B: Lecture #22 1

Artificial Intelligence Lecture 3

CS/COE 1501

In the game of Chess a queen can move any number of spaces in any linear direction: horizontally, vertically, or along a diagonal.

A CLASSIFICATION OF QUADRATIC ROOK POLYNOMIALS

COMM901 Source Coding and Compression Winter Semester 2013/2014. Midterm Exam

Design of Parallel Algorithms. Communication Algorithms

If a word starts with a vowel, add yay on to the end of the word, e.g. engineering becomes engineeringyay

UNIVERSITY of PENNSYLVANIA CIS 391/521: Fundamentals of AI Midterm 1, Spring 2010

Huffman Coding - A Greedy Algorithm. Slides based on Kevin Wayne / Pearson-Addison Wesley

Link State Routing. Brad Karp UCL Computer Science. CS 3035/GZ01 3 rd December 2013

After learning the Rules, What should beginners learn next?

SMS Dictionary. Solution hint. Input format. Output format. (Indian National Olympiad in Informatics, INOI, 2007)

Finite Mathematical Structures A

Written examination TIN175/DIT411, Introduction to Artificial Intelligence

and 6.855J. Network Simplex Animations

Question Score Max Cover Total 149

Adversarial Search Aka Games

Chess Puzzle Mate in N-Moves Solver with Branch and Bound Algorithm

Midterm. CS440, Fall 2003

Link State Routing. Stefano Vissicchio UCL Computer Science CS 3035/GZ01

Decision Mathematics practice paper

Unless stated otherwise, explain your logic and write out complete sentences. No notes, books, calculators, or other electronic devices are permitted.

Google DeepMind s AlphaGo vs. world Go champion Lee Sedol

CS61B Lecture #33. Today: Backtracking searches, game trees (DSIJ, Section 6.5)

Which Rectangular Chessboards Have a Bishop s Tour?

Module 3 Greedy Strategy

WPF PUZZLE GP 2018 ROUND 7 INSTRUCTION BOOKLET. Host Country: Netherlands. Bram de Laat. Special Notes: None.

Introduction to Spring 2009 Artificial Intelligence Final Exam

Problem A. Worst Locations

CSE 21 Practice Final Exam Winter 2016

Contents. MA 327/ECO 327 Introduction to Game Theory Fall 2017 Notes. 1 Wednesday, August Friday, August Monday, August 28 6

Adversarial Search. Robert Platt Northeastern University. Some images and slides are used from: 1. CS188 UC Berkeley 2. RN, AIMA

Programming Abstractions

MAS336 Computational Problem Solving. Problem 3: Eight Queens

Lecture 7. Review Blind search Chess & search. CS-424 Gregory Dudek

Binary Continued! November 27, 2013

ISudoku. Jonathon Makepeace Matthew Harris Jamie Sparrow Julian Hillebrand

Module 3 Greedy Strategy

CSE 473 Midterm Exam Feb 8, 2018

Chained Permutations. Dylan Heuer. North Dakota State University. July 26, 2018

WPF PUZZLE GP 2018 ROUND 2 INSTRUCTION BOOKLET. Host Country: Switzerland. Markus Roth, Roger Kohler, Esther Naef

Princeton ELE 201, Spring 2014 Laboratory No. 2 Shazam

Introduction to Genetic Algorithms

Foundations of Artificial Intelligence

10/5/2015. Constraint Satisfaction Problems. Example: Cryptarithmetic. Example: Map-coloring. Example: Map-coloring. Constraint Satisfaction Problems

Section Marks Agents / 8. Search / 10. Games / 13. Logic / 15. Total / 46

2014 ACM ICPC Southeast USA Regional Programming Contest. 15 November, Division 1

NANYANG TECHNOLOGICAL UNIVERSITY SEMESTER II EXAMINATION MH1301 DISCRETE MATHEMATICS. Time Allowed: 2 hours

AIMA 3.5. Smarter Search. David Cline

Introduction to. Algorithms. Lecture 10. Prof. Piotr Indyk

A few chessboards pieces: 2 for each student, to play the role of knights.

Decision Mathematics D1

More Adversarial Search

LESSON 2: THE INCLUSION-EXCLUSION PRINCIPLE

Asymptotic Results for the Queen Packing Problem

Math Circle Beginners Group May 22, 2016 Combinatorics

CSE 573 Problem Set 1. Answers on 10/17/08

Cryptic Crosswords for Bright Sparks

COCI 2008/2009 Contest #3, 13 th December 2008 TASK PET KEMIJA CROSS MATRICA BST NAJKRACI

CS 188 Fall Introduction to Artificial Intelligence Midterm 1

Chess Handbook: Course One

Search then involves moving from state-to-state in the problem space to find a goal (or to terminate without finding a goal).

In order for metogivebackyour midterms, please form. a line and sort yourselves in alphabetical order, from A

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 17: Heaps and Priority Queues

Two Parity Puzzles Related to Generalized Space-Filling Peano Curve Constructions and Some Beautiful Silk Scarves

Adversarial Search (Game Playing)

MITOCW R22. Dynamic Programming: Dance Dance Revolution

Twenty-fourth Annual UNC Math Contest Final Round Solutions Jan 2016 [(3!)!] 4

Irish Collegiate Programming Contest Problem Set

Chapter 4 Number Theory

Jamie Mulholland, Simon Fraser University

CSS 343 Data Structures, Algorithms, and Discrete Math II. Balanced Search Trees. Yusuf Pisan

MA/CSSE 473 Day 13. Student Questions. Permutation Generation. HW 6 due Monday, HW 7 next Thursday, Tuesday s exam. Permutation generation

Math Circle Beginners Group May 22, 2016 Combinatorics

BMT 2018 Combinatorics Test Solutions March 18, 2018

Solving Problems by Searching

the question of whether computers can think is like the question of whether submarines can swim -- Dijkstra

MITOCW ocw lec11

Simple Search Algorithms

Heuristics, and what to do if you don t know what to do. Carl Hultquist

Math 1111 Math Exam Study Guide

Introduction to. Algorithms. Lecture 10. Prof. Constantinos Daskalakis CLRS

Lectures: Feb 27 + Mar 1 + Mar 3, 2017

Topic 10 Recursive Backtracking

CS 758/858: Algorithms

SOLITAIRE CLOBBER AS AN OPTIMIZATION PROBLEM ON WORDS

Lecture5: Lossless Compression Techniques

Rules of the game. chess checkers tic-tac-toe...

Transcription:

Department of Computer and Information Science Examination paper for TDT0 Algorithms and Data Structures Academic contact during examination Magnus Lie Hetland Phone 98 5 99 Examination date Dec 0, 08 Examination time (from to) 09:00 :00 Support material code D Other information The problem sheets are handed in, with answers in answer boxes under the problems Language English Number of pages (front page excluded) 7 Number of pages enclosed 0 Informasjon om trykking av eksamensoppgave Originalen er -sidig -sidig sort/hvit i farger Skal ha flervalgskjema Checked by Date Signature Students will find the examination results in Studentweb. Please contact the department if you have questions about your results. The Examinations Office will not be able to answer these.

Candidate no.: Page of 7 Questions for us? We may only answer questions about possible errors, flaws or ambiguities in the problem texts. We make one round and have limited time. Read all problems first and have any questions ready! Please read this thoroughly (i) (ii) Read the entire exam thoroughly before you start! Write your answers in the answer boxes and hand in the problem sheet. Feel free to use a pencil! Or draft your answers on a separate piece of paper, to avoid strikouts, and to get a copy for yourself. (iii) You are permitted to hand in extra sheets, if need be, but the intention is that the answers should fit in the boxes on the problem sheets. Long answers do not count positively. Problems 5%. In a connected graph with n vertices and m edges, what is the least and greatest number of edges a spanning tree may have? 5%. In a Huffman code for an alphabet of n characters, what is the least and greatest length a codeword for a single character may have? 5%. Assume that Π is a predecessor matrix for the all-pairs shortest path problem. What does π ij represent, if you assume π ij = nil? 5%. What is a cut of a flow network G = (V, E)? TDT0 Algorithms and Data Structures Dec 0, 08

Candidate no.: Page of 7 5% 5. What is a vertex cover for a graph G = (V, E)? 5% 6. Table-Insert has a worst-case running time of Θ(n), but an amortized running time of O(). What does that mean? 5% 7. In the n-rooks problem one has an n n chessboard and is to place n rooks on the board, so there is exactly one rook in each row and one in each column. (A more thorough explanation may be found on page 7.) Your friend Klokland has found a solution to this problem, for a specific n that is, a specific placement of the n rooks. Your friend Smartnes wants to know which of the possible solutions Klokland has found, but he won t tell her. Instead, she gets to guess, asking yes/no questions. How many questions will she need, in the worst case, if you can t assume anything about how smart Smartnes is? Give your answer in asymptotic notation. Explain your answer. 5% 8. In the 0--knapsack problem, assume that you have n objects and a knapsack capacity of m. What is the running time of the solution in the curriculum? 5% 9. If you insert the numbers,..., n into a binary search tree in random order, where n = k for an integer k, what is the expected height of the tree, as a function of k? Use Θ notation. TDT0 Algorithms and Data Structures Dec 0, 08

Candidate no.: Page of 7 Q 5 6 5 7 8 9 Q 5 6 7 8 9 5 Figure : Example queue for problem. The values are inserted from the start, so Q.head = Q.tail = Figure : Example queue for problem. The values are not inserted from the start. Q.head = Q.tail = 5% 0. Your friend Smartnes executes DFS on a DAG. Which kinds of edges could she get? (Here kinds refers to the DFS edge classification.) 5%. Your friend Gløgsund has inserted n distinct numbers in increasing order into a FIFO queue Q, implemented as an array. The queue is full, so the array contains only the elements she has inserted. In other words, the elements either make up a single increasing segment, x,..., x n (see fig. ), or two increasing segments, x k,..., x n, x,... x k (see fig. ), where x i < x i+ for i =... n. Unfortunately, Gløgsund has forgotten where the queue begins and ends (i.e., Q.head og Q.tail). Describe an algorithm that determines this as efficiently as possible. What is the running time? (A high-level description suffices, without concern for practical details or special cases.) 5%. In each iteration of the outermost loop of Insertion-Sort, an operation is performed on A[.. n ] and A[j]. What is this operation, and what is the running time, as a function of j? Use O notation. TDT0 Algorithms and Data Structures Dec 0, 08

Candidate no.: Page of 7 0 5 6 0 0 W 0 0 T () 0 0 0 0 0 0 0 Figure : Weight matrix for G, used in problem Figure : Previous state, used in problem 5 5%. Your friend Lurvik has developed a new priority queue of which he is quite proud. It may be constructed in linear time, just like a binary heap, while Extract-Min and Decrease-Key have respective running times of O(n ) and O(n ), where n is the number of elements in the queue. What is the running time of Dijkstra if one uses Lurviks priority queue? Explain briefly. (Note that Lurvik does not employ a series of calls to Insert to build his queue, but constructs it in linear time at the beginning of Dijkstra.) 5%. Let G be a weighted graph, defined by the weight matrix in fig.. Execute DAG-Shortest-Path on the graph, with as the start node. Fill in the distances to each node after each iteration in each row of the table below. 0 0 5% 5. You have executed one iteration of Transitive-Closure, and ended up with the matrix T () as shown in fig.. Execute the next iteration, and fill in the resulting values in the table below. T () TDT0 Algorithms and Data Structures Dec 0, 08

Candidate no.: Page 5 of 7 5% 6. What is the running time of the algorithm Alpha, below, where n is an integer? Give your answer in Θ notation, as a function of n. Alpha(n) for i = to n for j = i to n for k = to n print Lurvik rulz! 5% 7. What is the running time of the algorithm Beta, below, where n is an integer? Give your answer in Θ notation, as a function of n. Beta(n) if n m = n/ Beta(m) Beta(n m) 5 for i = to n 6 print Smartnes rocks! 5% 8. Which problem does the algorithm Delta, below, solve, where n, m 0 are integers? Gamma(n, m) if m == 0 return n else return Gamma(n, m ) + Delta(n, m) if m == 0 return 0 else return Gamma(n, Delta(n, m )) 5% 9. Your friend Kvikstad is naming a set of computers. He wants the names to start with different letters, one beginning with A, one with B, etc. He has not yet decided which machine gets a name beginning with which letter, but he has some naming suggestions for each machine, and wants to select each name from those. Draw a flow network (on the next page) that finds a valid selection for him, based on the following table: Machine Possible names Abhoth Aletheia, Byatis Aletheia, Byakhee, C thalpa Azathoth, Byakhee, Cthulhu, Dagon TDT0 Algorithms and Data Structures Dec 0, 08

Candidate no.: Page 6 of 7 Answer to problem 9: 5% 0. A knight is placed in square a on an n n chessboard and is to be moved k times, or until such a move would have placed it outside the board. For each step, one of the 8 possible moves is to be chosen at random. Describe an algorithm based on dynamic programming that determines the probability that the knight is still on the board after k moves. (A more thorough explanation may be found on the next page.) TDT0 Algorithms and Data Structures Dec 0, 08

Page 7 of 7 8 0Z0Z0S0Z 7 S0Z0Z0Z0 6 0Z0s0Z0Z 5 Z0Z0Z0S0 0Z0Z0Z0S Z0S0Z0Z0 0S0Z0Z0Z Z0Z0S0Z0 a b c d e f g h Figure 5: The n-rooks problem. The black rook threatens the squares indicated by black dots 8 0Z0Z0Z0Z 7 Z0Z0Z0Z0 6 0Z0Z0Z0Z 5 Z0Z0m0Z0 0Z0Z0Z0Z Z0Z0Z0Z0 0Z0Z0Z0Z Z0Z0Z0Z0 a b c d e f g h Figure 6: A knight may jump to one of eight squares, as indicated by black dots About the chess problems In the problems we consider, we permit arbitrarily large quadratic grids as chessboards, so an n n chessboard consists of n rows and n columns. In the n-rooks problem (see problem 7) we have an n n chessboard and n rooks that are to be placed on the board, so that none of them threatens any other. A rook threatens all others in the same row or column, independently of color. (See fig. 5 for an example.) In other words, the problem consists of placing exactly one rook in each row and exactly one rook in each column. There are, of course, several correct solutions to this problem. In the knight problem (see problem 0), we have only a single piece on an n n chessboard. This piece is a knight, which may be moved to one of (at most) eight different positions, as shown in fig. 6. That is, it may be moved two squares up, down, to the right or to the left, and then one square to the side. For example, two squares to the right and then one square down, or two squares down and one to the right. If the knight is near the edge of the board, some of these eight moves will no longer be permissible, as they would take the knight off the board. In our problem we still select among all eight (with uniform probability), and wish to see whether the knight does end up outside the board. If, for example, it is placed on square a (bottom left) and moves two squares up and one to the left, which is one of the eight possible moves, it has ended up outside, and we can no longer keep moving it. We select each move independently of the others. Remember that the probability for two independent events A and B with respective probabilities P(A) and P(B) to both occur is the product of their probabilities, P(A) P(B) TDT0 Algorithms and Data Structures Dec 0, 08