EECS 281 Homework 4 Key Fall 2004

Similar documents
Homework Assignment #3 Graph

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

CSE 100 Minimum Spanning Trees Prim s and Kruskal

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

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

CSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms

tree follows. Game Trees

CS 206 Introduction to Computer Science II

CSE 373: Data Structures and Algorithms

Chapter 9 Graph Algorithms

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

Computer Science E-22 Practice Final Exam

The Shortest Path Problem

Graphs Data Structures

CS/COE

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

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.

CSE 100: GRAPH ALGORITHMS

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

CHAPTER 13 GRAPH ALGORITHMS

Computer Science 302 Spring 2017 (Practice for) Final Examination, May 10, 2017

Introduction: (Edge-)Weighted Graph

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

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

CSE 100: GRAPH ALGORITHMS

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

(Dijkstra s Algorithm) Consider the following positively weighted undirected graph for the problems below: 8 7 b c d h g f

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

CS350: Data Structures Dijkstra s Shortest Path Alg.

Shortest Paths. CSE 373 Data Structures Lecture 21

CSE 21 Summer 2017 Homework 4

Final Examination CSE 100 UCSD (Practice)

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

CS Final - Review material

EECS 281 Homework 3 KEY Fall 2004

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

looking ahead to see the optimum

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

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

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:

Computer Science 385 Design and Analysis of Algorithms Siena College Spring Topic Notes: Dynamic Programming

Graphs. Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale Room - Faner 3131

Total Score /15 /20 /30 /10 /5 /20 Grader

CS 310 Advanced Data Structures and Algorithms

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013

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

Algorithms for Minimum Spanning Trees

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

Shortest path problems

Greedy Approach: Intro

Parallel Graph Algorithms

Graphs & Digraphs Tuesday, November 06, 2007

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

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

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

CSC 373 Lecture # 3 Instructor: Milad Eftekhar

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2

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

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

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: CS6402- Design & Analysis of Algorithm Year/Sem : II/IV UNIT-I INTRODUCTION

CSE 521: Design and Analysis of Algorithms I

CS61BL. Lecture 5: Graphs Sorting

Second Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

UCS-406 (Data Structure) Lab Assignment-1 (2 weeks)

Dynamic-Programming algorithms for shortest path problems: Bellman-Ford (for singlesource) and Floyd-Warshall (for all-pairs).

CS61B Fall 2014 Guerrilla Section 3

Graph definitions. There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs. An undirected graph

SHORTEST PATHS. Weighted Digraphs. Shortest paths. Shortest Paths BOS ORD JFK SFO LAX DFW MIA

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

Parallel Graph Algorithms

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

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

Graph Algorithms shortest paths, minimum spanning trees, etc.

(a) Write code to do this without using any floating-point arithmetic. Efficiency is not a concern here.

Dijkstra s Algorithm

Name: Lirong TAN 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G.

Department of Computer Science and Engineering Analysis and Design of Algorithm (CS-4004) Subject Notes

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

DESIGN AND ANALYSIS OF ALGORITHMS

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

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

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

Graph Representation DFS BFS Dijkstra A* Search Bellman-Ford Floyd-Warshall Iterative? Non-iterative? MST Flow Edmond-Karp

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

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

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

CS201 Discussion 12 HUFFMAN + ERDOSNUMBERS

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li

Algorithms Dr. Haim Levkowitz

Graph Algorithms shortest paths, minimum spanning trees, etc.

Mystery Algorithm! ALGORITHM MYSTERY( G = (V,E), start_v ) mark all vertices in V as unvisited mystery( start_v )

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

CSE332: Data Abstractions Lecture 25: Minimum Spanning Trees. Ruth Anderson via Conrad Nied Winter 2015

MST & Shortest Path -Prim s -Djikstra s

ECE 242 HOMEWORK 5. In the figure below, one can go from node B to A but not from A to B.

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm

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

SELF-BALANCING SEARCH TREES. Chapter 11

Weighted Graph Algorithms Presented by Jason Yuan

Graphs Weighted Graphs. Reading: 12.5, 12.6, 12.7

Transcription:

EECS 281 Homework 4 Key Fall 2004 Assigned: Due: 30NO04 14DE04, 6pm, EECS 281 box in room 2420 EECS Graph Algorithm Selection (10/50 points) You are planning a trip to Los Angeles, California and will be flying into Los Angeles LAX airport. You have a directed graph of all the possible flights in the US with the price of the ticket as the weight of the edges. For each of the following situations, choose the appropriate graph algorithm and briefly (1-2 sentences) explain your choice. 1. You want to fly out of JFK Airport in New York and want to find out if there is a direct flight from JFK to LAX. a) breadth-first search b) depth-first search c) Prim s algorithm d) Kruskal s algorithm e) Dijsktra s algorithm f) Floyd s algorithm Explanation: Implementing breadth-first search one depth can find the direct flight efficiently. 2. You don t have very much money and want to find the cheapest possible flight or series of flights from JFK Airport in New York to LAX. a) breadth-first search b) depth-first search c) Prim s algorithm d) Kruskal s algorithm e) Dijsktra s algorithm f) Floyd s algorithm Explanation: Dijsktra s algorithm is efficient to find the shortest paths from one source vertex. 3. You are planning the trip for a large group of people that will be flying out of airports all over the country. You want to find out the cheapest possible flight or series of flights from any airport in the country to LAX. a) breadth-first search b) depth-first search c) Prim s algorithm d) Kruskal s algorithm e) Dijsktra s algorithm f) Floyd s algorithm Explanation: Dijsktra s algorithm: Dijsktra s algorithm can be used to find the shortest paths to one destination vertex by reversing all edges (flights). Floyd s algorithm: Floyd s algorithm is to find all source shortest paths, which can of course be used to find the shortest paths to one destination vertex.

Graph Algorithm Complexity (10/50 points) Below is pseudo-code for Dijsktra s algorithm. Assume that implementation of the algorithm uses a heap for the priority queue and an adjacency list for representing the graph. It is unknown whether the graph is sparse or dense. Assume that the size of the priority queue is E. Derive the complexity. Show line-by line complexity analysis using appropriate indentation. Show overall (unsimplified) complexity in the first box at the bottom of the page. Then, simplify the complexity and show it in the second box at the bottom of the page. Dijsktra(G,s0) //Initialize n = V ; O( 1 ) createtable(n); //stores k,d,p O( V ) createpq( E ); //empty pq O( 1 ) table[s0].d = 0; O( 1 ) insertpq(0,s0); O( 1 ) while (!pq.isempty) do O( E ) v0 = pq.getmin(); O( loge ) if (!table[v0].k) then //not known O( V/E ) table[v0].k = true; O( 1 ) for each vi Adj[v0] do O( 1 + E/V ) newd=table[v0].d + weight(vi,v0); O( 1 ) if (table[vi].d) > newd) then O( 1 ) table[vi].d = newd; O( 1 ) table[vi].p = v0; O( 1 ) insertpq(newd,vi); O( loge ) 4. Unsimplified Complexity O(1 + V + 1 + 1 + 1 + E(logE + V/E(1 + (1 + E/V)(1 + 1(1 + 1 + loge))))) 5. Simplified Complexity O(V*logE + E*logE)

Shortest Path Algorithms (10/50 points) Use the following graph for this problem. 6. Show each iteration of Dijkstra s algorithm on the graph with a starting point of node F. The first iteration is provided for you. Iteration 1 Iteration 2 Iteration 3 Iteration 4 Iteration 5 Iteration 6 k D p A F - - B F - - C F 4 F D F 2 F E F 1 F A F - - C F 4 F D F 2 F A F 7 D C F 4 F A F 7 D C T 4 F A T 7 D C T 4 F k d P A T 7 D B T 9 E C T 4 F 7. Draw the resulting directed graph representing the single source shortest paths from node F. Include edge weights in your drawing.

Text Compression Algorithms (10/50 points) The following question is related to text compression using the Huffman Encoding Algorithm. 8. Given the following text string, populate the frequency table: CREATIVE PROJECTS WITH LEGOS MINDSTORMS Frequency Table A C D E G H I J L M N O P R S T V W Space 1 2 1 4 1 1 3 1 1 2 1 3 1 3 4 4 1 1 4 2 9. Suppose that the Frequency Table is as follows (by the way, it is not). Draw the Huffman Tree. When creating the Huffman Tree, you must apply the following rules for tie-breaking during the combination of two subtrees: If choosing between two subtrees with the same weight but different number of nodes, always pick the subtree with the smallest number of nodes first, If choosing between two subtrees with the same weight and the same number of nodes, always pick the subtree whose member has the lowest alphabetical order (i.e., pick a subtree containing a before picking a subtree containing b ). Frequency Table X Q K Z V W H G C 3 5 7 1 2 1 3 4 2 K H X G Q W Z C V 10. Suppose that the string is cabfeddefb and the Huffman tree is as follows:

a c b d f e What is the Huffman encoding of the string? 10001011100110111111111011100101 11. What is the total number of bits for Huffman encoding of the string? 32

Dynamic Programming (10/50 points) 12. The binomial coefficient is defined as n-1 n-1 +, 0 < k < n n k-1 k = k 1, k = 0 or k = n A recursive algorithm that solves the binomial coefficient follows: int BiCoeff(int n, int k) if (k==0 k==n) return 1; else return BiCoeff(n-1,k-1) + BiCoeff(n-1,k); Rewrite the recursive algorithm as an efficient, iterative, bottom-up dynamic program. Assume the presence of a global, two-dimensional array: int mem[maxn+1][maxk+1]. Your algorithm must run in O(nk) time. int BiCoeff(int n, int k) int mem [n+1][k+1]; for (int i = 0; i <= n; i++) mem [i][0] = 1; for (int j = 1; j <= k; j++) for (int i = j; i <= n; i++) if (i == j) mem [i][j] = 1; else c[i][j] = mem [i-1][j-1] + mem [i-1][j]; return mem [n][k];

Alternative Answer (slightly better) int BiCoeff(int n, int k) int mem [n+1][k+1]; for (int j = 0; j <= k; j++) for (int i = j; i <= n; i++) if ((i == j) (j == 0)) mem [i][j] = 1; else mem [i][j] = mem [i-1][j-1] + mem [i-1][j]; return mem [n][k];