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

Similar documents
CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 25: Review and Open Problems

COMP 251 Winter 2017 Online quizzes with answers

ECE250: Algorithms and Data Structures Final Review Course

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

Week 11: Minimum Spanning trees

Review of course COMP-251B winter 2010

Chapter 9 Graph Algorithms

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

Week 12: Minimum Spanning trees and Shortest Paths

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

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302

GRAPHS Lecture 17 CS2110 Spring 2014

Minimum Spanning Trees My T. UF

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

GRAPHS Lecture 19 CS2110 Spring 2013

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

Overview of Data Structures, Algorithm Analysis

Chapter 9 Graph Algorithms

CSE 373 MAY 10 TH SPANNING TREES AND UNION FIND

Lecture 25 Spanning Trees

CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION

CSci 231 Final Review

Practice Problems for the Final

Analysis of Algorithms

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

Introduction to Algorithms Third Edition

Introduction to Algorithms

Review for Midterm Exam

Contents. 1 Introduction. 2 Searching and Traversal Techniques. Preface... (vii) Acknowledgements... (ix)

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.

L.J. Institute of Engineering & Technology Semester: VIII (2016)

Chapter 9 Graph Algorithms

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

Solutions to relevant spring 2000 exam problems

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

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.

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

CSE 100 Minimum Spanning Trees Prim s and Kruskal

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

Minimum Spanning Trees. CSE 373 Data Structures

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees

END-TERM EXAMINATION

Virtual University of Pakistan

Outline. Graphs. Divide and Conquer.

Data Structures. 1. Each entry in a linked list is a called a (a)link (b)node (c)data structure (d)none of the above

CS521 \ Notes for the Final Exam

Introduction: (Edge-)Weighted Graph

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

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014

Minimum Spanning Trees

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

DATA STRUCTURES AND ALGORITHMS

Suggested Study Strategy

DESIGN AND ANALYSIS OF ALGORITHMS

4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting...

Spanning Tree. Lecture19: Graph III. Minimum Spanning Tree (MSP)

Algorithms and Data Structures

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

Course Review for Finals. Cpt S 223 Fall 2008

CS 561, Lecture 10. Jared Saia University of New Mexico

Algorithms and Data Structures

CS302 Data Structures using C++

DESIGN AND ANALYSIS OF ALGORITHMS GREEDY METHOD

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

Algorithm Design and Analysis

Data Structures and Algorithms

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Reference Sheet for CO142.2 Discrete Mathematics II

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

Weighted Graph Algorithms Presented by Jason Yuan

Final Exam. EECS 2011 Prof. J. Elder - 1 -

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

INSTITUTE OF AERONAUTICAL ENGINEERING

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

Lecture Summary CSC 263H. August 5, 2016

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018

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

22.3 Depth First Search

Shortest path problems

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

17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer

Dijkstra s algorithm for shortest paths when no edges have negative weight.

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

CS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14

Algorithms and Data Structures. Algorithms and Data Structures. Algorithms and Data Structures. Algorithms and Data Structures

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

CS4800: Algorithms & Data Jonathan Ullman

Graphs. Computer Science E-119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. What is a Graph? b d f h j

CSE 421 Greedy Alg: Union Find/Dijkstra s Alg

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016

CSCE 321/3201 Analysis and Design of Algorithms. Prof. Amr Goneid. Fall 2016

Greedy Algorithms. At each step in the algorithm, one of several choices can be made.

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

Design and Analysis of Algorithms

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

Chapter 23. Minimum Spanning Trees

Minimum Spanning Trees

Design and Analysis of Algorithms

Graphs - II. Announcements. Where did I leave that book? Where did I leave that book? Where did I leave that book? CS 2110, Fall 2016

Transcription:

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu Department of Computer Science Aalborg University Fall 2007

This Lecture Minimum spanning trees Definitions Kruskal s algorithm Prim s algorithm Example Course conclusion 2

Spanning Tree Revisit Given a graph G=(V, E), a spanning tree of it is a subgraph of G which Covers all vertices No vertex is omitted Forms a tree No cycle is allowed T=(V, E ) E E We have seen BFS spanning tree DFS spanning tree Shortest path spanning tree We will see minimum spanning tree 3

Motivation Example Given a number of cities, connect them by an electric power network of minimum cost Each city is a vertex Whenever a direct link between two cities is feasible, the corresponding vertices are connected by an edge e of cost c(e) The total cost of links really deployed is to be minimized E.g. a 2 d 1 2 4 Minimum spanning tree/forest How to find such a solution? b e 3 6 5 3 c f 5 a 2 d 1 2 b e 3 3 c f 4

General Principle G=(V, E) is a connected graph; X, Y are two sets of edges Loop Invariant: T=(V, X), X E, X Y=E There exists a minimum spanning tree T of G which contains all edges of X, but none of the edges of Y. Idea: add edges to X while maintaining the invariant Theorem E.g. If X and Y obey the loop invariant, C is a connected component of G. Let J(C)={{u,v} E-Y u C and v C}. Suppose e is a minimum cost edge in J(C), then X {e} and Y also obey the loop invariant. X={{a,b}, {b,c}} Y={} C covers a, b, c J(C)={{a,d},{a,e},{b,e},{c,e},{c,f}} a 2 d 1 2 b e c f a 2 d 1 2 4 b e 3 6 5 3 c f 5 5

Kruskal s Algorithm Input: connected graph G=(V,E) X:=Ø; Y:=Ø; Q:=E while Q Ø do Take an edge {u, v} of minimum cost out of Q if u and v are in different connected components of (V, X) then else X:=X {{u,v}} Y:=Y {{u,v}} return (V, X) Q should be a priority queue to ease the operation Can be used to find minimum spanning forests Different components are tried 6

Prim s Algorithm Idea: Loop invariant + staying within one connected component throughout the algorithm X:=Ø; Y:=Ø; Q:=Ø // set of edges out of the component C pick a V; insert all edges <a, w> into Q // treated as directed while Q Ø do remove from Q edge <u, v> with minimum cost insert {u, v} into X for each vertex w adjacent to v do if w is not visited then insert <v, w> into Q else if a path connects w to a in (V, X) then do nothing else // there must be an edge <x, w> Q if c(v, w) < c(x, w) then replace <x, w> in Q by <v, w> insert {x, w} into Y else insert <v, w> into Y 7

Example Kruskal Prim Pick a first Pick b first Pick c first Pick d first a 15 d 11 2 b 10 8 9 12 e c Pick e first 8

Algorithm Complexity Kruskal Dominant cost: insert and delete m edges into and out of priority queue q Prim O(m log m) for any implementation of priority queue Similar to Dijkstra s algorithm delete from priority queue: n times insert into priority queue: n times distance update: m times Total: O(n log n + m) Sparse graphs m=θ(n) Dense graphs m=θ(n 2 ) Kruskal O(n log n) O(n 2 log n) Prim O(n log n) O(n 2 ) 9

Course Conclusion Algorithmic problems Algorithms Data structures The expectation of attending course is to get prepared for attacking algorithmic problems The tools we learn in this course are algorithms and data structures They are closely correlated to each other Choose proper data structures and algorithms based on the characteristics of given problems To analyze the complexity of your own algorithm 10

Algorithmic Problems Easy (polynomial time complexity) Binary search Sorting Shortest path Minimum spanning tree Hard (exponential time complexity) Traveling salesperson problem Unsolvable Halting problem 11

Traveling Salesperson Problem Given a number of cities and the costs of traveling from any city to any other city, what is the least-cost round-trip route that visits each city exactly once and then returns to the starting city? All known algorithms are exponential 12

Abstract Data Type (ADT) ADTs are used to describe algorithms in an understandable way. Any ADT has two sides Operations Implementation Interface for users X Built by creators For a user, you can see and use the operations only Behaviors of operations are specified using pre- and postconditions One ADT can have many different implementations with different complexities As a user, we can analyze our algorithms without knowing the implementation details of the ADTs we use 13

Topics in the Course (1) Introduction Search in sequences Sequential scan vs. binary search Correctness of algorithms Partial vs. total correctness Pre- and post-conditions Iteration (assertions) vs. recursion (induction) Efficiency of algorithms Time and space complexity Worst case vs. average case Asymptotic complexity (O, Ω, Θ notations) Recurrence equations Repeated substituion Proof by math induction 14

Topics in the Course (2) Basic abstract data types Set, List, Stack, Queue Sorting Bubble, Selection, Insertion, Merge, Quick Radix sort Trees, binary trees, binary search trees Properties, ADT, traversals Symbol tables Different implementations Hashing Priority queue Special operations Used in graph algorithms 15

Topics in the Course (3) Algorithm design techniques Incremental Simple recursive, backtracking algorithms Divide-and-conquer Dynamic programming Greedy algorithms Graph Properties, Digraph ADT Adjacent matrix vs. adjacent list implementations Topological sorting, critical paths BFS, DFS Shortest paths (Bellman-Moore alg., Dijkstra s alg.) Minimum spanning trees (Kruskal s alg., Prim s alg) 16

Preparation for the Exam You are allowed to take all lecture notes, exercises and textbooks to the exam Go over each lecture one by one Read the relevant portions in the textbook or references Go through slides, understand and digest the contents No need to memorize algorithm codes, but do remember the ideas/rationales behind Re-solve by yourself exercise questions and check your solutions with those given online Try to solve some problems from exams of previous years Available online You are welcome to approach me if you get any problem about this course and the exam 17