Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Thursday 1st June 2017 Time: 14:00-16:00

Similar documents
Problem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Thursday 27th January 2011 Time: 14:00-16:00

Chapter 9 Graph Algorithms

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Homework Assignment #3 Graph

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

Graph Algorithms (part 3 of CSC 282),

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

Chapter 9 Graph Algorithms

Graph Algorithms (part 3 of CSC 282),

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

Chapter 9 Graph Algorithms

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

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

CSE 373 Final Exam 3/14/06 Sample Solution

Algorithms Activity 6: Applications of BFS

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

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

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

Closed Book Examination. One and a half hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Wednesday 20 th January 2010

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

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

CS171 Final Practice Exam

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

CS490 Quiz 1. This is the written part of Quiz 1. The quiz is closed book; in particular, no notes, calculators and cell phones are allowed.

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

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

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

DESIGN AND ANALYSIS OF ALGORITHMS

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.)

CS171 Final Practice Exam

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

Problem Score Maximum MC 34 (25/17) = 50 Total 100

Review for Midterm Exam

Introduction to Algorithms April 16, 2008 Massachusetts Institute of Technology Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 2

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

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

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

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:

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

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

Lecture Summary CSC 263H. August 5, 2016

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

) $ f ( n) " %( g( n)

ECE250: Algorithms and Data Structures Final Review Course

CSI 604 Elementary Graph Algorithms

Quiz 2. Problem Parts Points Grade Grader. Total 120. Name: Recitation: Jayant 12 PM. Christina 10 AM. Jayant 1 PM. Jason 2 PM.

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

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

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

Algorithm Design (8) Graph Algorithms 1/2

Algorithm Design and Analysis

CS521 \ Notes for the Final Exam

Elementary Graph Algorithms: Summary. Algorithms. CmSc250 Intro to Algorithms

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

CS 112 Final May 8, 2008 (Lightly edited for 2011 Practice) Name: BU ID: Instructions GOOD LUCK!

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

END-TERM EXAMINATION

CSE 100: GRAPH ALGORITHMS

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8)

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

Lecture 9 Graph Traversal

Design and Analysis of Algorithms. Comp 271. Mordecai Golin. Department of Computer Science, HKUST

Homework 2. Sample Solution. Due Date: Thursday, May 31, 11:59 pm

( D. Θ n. ( ) f n ( ) D. Ο%

Inf 2B: Graphs, BFS, DFS

CSE 373: Practice Final

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

Graphs & Digraphs Tuesday, November 06, 2007

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

I A graph is a mathematical structure consisting of a set of. I Formally: G =(V, E), where V is a set and E V V.

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

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

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

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

CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14

CPSC 331 Term Test #2 March 26, 2007

D.K.M.COLLEGE FOR WOMEN (AUTONOMOUS), VELLORE-1.

Exam 3 Practice Problems

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

Algorithm Design and Analysis

Algorithm Design and Analysis

Assignment 3 (Due date: Thursday, 10/15/2009, in class) Part One: Provide brief answers to the following Chapter Exercises questions:

CS 170 Second Midterm ANSWERS 7 April NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt):

Problem Pts Score Grader Problem Pts Score Grader

CSci 231 Final Review

Introduction to Algorithms May 14, 2003 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser.

DIT960 Datastrukturer

COMP 251 Winter 2017 Online quizzes with answers

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

DESIGN AND ANALYSIS OF ALGORITHMS GREEDY METHOD

RYERSON UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE CPS 616 MIDTERM WINTER 2017

( ) 1 B. 1. Suppose f x

Course Review for Finals. Cpt S 223 Fall 2008

Questions Total Points Score

Basic Graph Definitions

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

Course Name: B.Tech. 3 th Sem. No of hours allotted to complete the syllabi: 44 Hours No of hours allotted per week: 3 Hours. Planned.

Transcription:

COMP 26120 Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE Algorithms and Imperative Programming Date: Thursday 1st June 2017 Time: 14:00-16:00 Please answer THREE Questions from the FOUR Questions provided Use a SEPARATE answerbook for EACH Question This is a CLOSED book examination The use of electronic calculators is permitted provided they are not programmable and do not store text

1. Path-finding in graphs a) Write a pseudocode description of Dijkstra s algorithm for finding the shortest path between a given node and all other nodes in a connected, undirected, weighted graph. Assume in your answer that the priority queue that is used in Dijkstra s algorithm, and the functions that operate on it, are given. (4 marks) b) A road network with distances between towns is represented by the following undirected weighted graph: The driver wants to go from the town A to the town J and the navigation system calculates the shortest route to be A E D C J of length 16. En route, exactly half way between the towns D and C, the navigation system receives a message that the road C J is closed because of an accident, and recalculates the new route. Give the progression of Dijkstra s algorithm, step by step, to determine the new shortest path. In your answer, assume that the driver needs first to go to the town C to turn around. The priority queue does not need to be shown explicitly in your answer, but the intermediate weights for all nodes should be presented. (10 marks) c) Give the time complexity of Dijkstra s algorithm when applied to the problem of finding the shortest path between a given node and all other nodes in an undirected, connected, weighted graph with N nodes and E edges. Contrast two different implementations of the priority queue: as a list and as a heap. Define sparse and dense graphs by expressing the asymptotic relationship between N and E in such graphs. Based on this, compare the asymptotic complexity of: Dijkstra s algorithm for finding the shortest path between all pairs of nodes (assuming that the priority queue is implemented as a heap), and the Floyd-Walshall algorithm (also known as Floyd s algorithm). (6 marks) Page 2 of 7

2. Applying Knapsack techniques The UK government has recently set up a Commission on Academic Quality (CAQ) to rank academics using an official database of scientific publications. Each publication in the database has: (i) a list of one or more authors, (ii) a number of pages (a positive integer) and (iii) a number of times this publication has been cited elsewhere (a non-negative integer - the citation number). The original plans provided for each UK academic to submit to the CAQ a list of publications of which they are an author, up to a limit of l pages in total. An academic s CAQ score is then just the sum of the citation numbers of the submitted publications. (It does not matter if those publications have other authors.) The strange decision was made to allow submission of just parts of publications (specified by a whole number of pages), with citations being counted proportionately. Thus, Dr. Smith might (for some reason) decide to submit 31 pages worth of an 80 page publication with 103 citations, which will then score 31 103/80 = 39.9125 points. Dr. Smith can submit any number of part- (or whole-) publications, up to the total page limit of l. a) Using pseudocode, give an algorithm for computing, for any academic with n publications, a list of (whole- and part-) publications which will maximize their CAQ score. State precisely the complexity of your algorithm, as a function of l and n. You may assume that all the data for the academic s publications has already been extracted from the database as a list of records (but this may be in any order). b) In a revised version of the CAQ rules, it was decided that only whole publications could be submitted (no part-publications), but still with a strict limit of l pages in total. Explain clearly how you would compute, in time polynomially bounded by n and l, a list of publications an academic should submit under this new scheme to maximise their CAQ score. A full program, or pseudocode, is not required. c) Following user-feedback, a further change was made to the CAQ rules. It was decided that the limit should not be l pages, but L = 2000l characters. Indeed, the official database had an additional, hidden field listing, for each publication, the number of characters it contains, and this field was duly made visible. What will be the effect of using the same approach as the one you used in part (b), but with a character limit of L instead of a page-limit of l? Give an alternative technique which will work well if, in practice, most academics hit the character limit with a small number of publications. Page 3 of 7

d) Some unscrupulous university departments found a ruse to maximize their scores. They decided that, on new publications, they would simply list the entire department as authors; that way, every academic in the department would get the score of the top-performing colleague. When government officials heard of this, they changed the rules so that no department could submit a publication twice. Thus, if Drs. Smith and Jones in the same department author a publication together, it could be submitted either by Dr. Smith or by Dr. Jones, but not both. However, the character limit was dropped and replaced with a limit on the number k of (whole) publications that any academic could submit. Explain clearly how you would compute, for a given department, a list of publications every academic in that department should submit to the CAQ so as to maximize the department s total CAQ score. The submissions must conform to the new rules. Give the complexity of your algorithm as a function of: the number m of academics in the department, the total number N of publications submitted by academics in the department, and the maximum number k of publications submitted by each academic. What techniques can you use to avoid needless search? Page 4 of 7

3. Trees and hashing Consider the following simplified scenario for task scheduling in a computer system with a single processor (CPU). We assume that all the CPU time is assigned to the execution of users tasks (i.e. the time taken to perform task scheduling is neglected). The CPU divides time into slots of varying duration c i+1 = t i+1 t i, i = 0,1,2,... (see the picture below). At the start time t i of each slot c i+1, a number of tasks T j i, j = 0,1,... with execution times τ j i arrive ready for execution. In addition, there may be tasks waiting from previous times but which have not yet been executed. During a single CPU slot only one task may be executed and its execution time must not exceed the time allocated for the current slot. The execution times of some tasks may be longer than individual CPU slots, and such tasks cannot be executed across multiple CPU slots. Tasks which are not executed at a particular time wait for succeeding time slots. Task scheduling aims to provide the best utilisation of the CPU. a) Explain how priority queues can be used to implement task scheduling. In your answer, give a suitable choice of a key (that represents the priority of a task in the scheduling) associated with each task in the queue, which will maximise the use of each CPU slot. In addition, explain the operations required to update the priority queue at the start of each slot. Hint: the old and the newly arrived tasks at t i need to be combined together in a new priority queue and the new keys associated with all the tasks need to be created; these keys should guarantee that the task sent to the execution represents the best fit among all tasks based on the current slot size c i+1 and the chosen task s execution time. Your answer can be either a clear explanation or a pseudocode program. (10 marks) Page 5 of 7

b) Consider the following set of tasks and set of CPU slots: Process (T j i ) T 0 1 T0 2 T0 3 T3 1 T3 2 T5 1 T5 2 Arrival time 0 0 0 16 16 33 33 Execution time (τ j i ) 4 10 2 3 7 12 5 Slot start time (t i ) 0 6 10 16 20 33 46 52 Slot length (c i+1 ) 6 4 6 4 13 13 6 10 Apply the scheduling algorithm from part (a) to perform scheduling of these tasks on the given CPU time resources. In your answer, consider that a priority queue is realised as a heap. For each discrete time t i, i = 0,...,7, give the content of the old priority queue, and the values of the new keys for each old and (possibly) newly arrived tasks. Based on the newly computed keys, draw the final priority queue (the intermediate steps taken during the creation of the heap are not required), and indicate which task (if any) is sent to the execution. Calculate the CPU usage, as a percentage, achieved by scheduling these tasks. (10 marks) Page 6 of 7

4. Graphs and graph algorithms a) Explain the following traversal techniques for finite directed graphs. Your traversal should visit all the nodes of the graph, restarting the traversal where necessary. You need not give programs, but you should explain clearly the rules which determine the order that nodes are visited. i. Depth-first Search (DFS), ii. Breadth-first Search (BFS), and iii. Priority Search, for graphs where each node has a non-negative integer priority assigned to it. (6 marks) b) Give an explicit algorithm for performing DFS of finite directed graphs which visits all the nodes and numbers them in the order that they are first encountered. You may either present a program or express the algorithm in pseudocode. c) Using Big-Oh notation, express the worst-case time complexity of DFS in terms of the number of nodes N, and the number of edges E, of a graph, using the following two representations of graphs: i. Adjacency lists, and ii. Adjacency matrices. In each case, explain why your answer is correct. (3 marks) d) A topological sorting of the nodes of a finite directed graph is a list of the nodes, each occurring exactly once in the list, such that, if there is an edge from node s to node t, then s is before t in the list. Explain clearly why a directed graph with a topological sorting must be acyclic. (2 marks) Given an acyclic finite directed graph, explain how, using a DFS or otherwise, a topological sorting may be constructed. (4 marks) Page 7 of 7 END OF EXAMINATION