CSC 8301 Design and Analysis of Algorithms: Graph Traversal

Similar documents
CS 350 Algorithms and Complexity

CSC 8301 Design and Analysis of Algorithms: Exhaustive Search

CSC Design and Analysis of Algorithms. Lecture 4 Brute Force, Exhaustive Search, Graph Traversal Algorithms. Brute-Force Approach

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

Chapter 5. Decrease-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

CSC 8301 Design & Analysis of Algorithms: Linear Programming

CSC 1700 Analysis of Algorithms: Heaps

CSC 8301 Design and Analysis of Algorithms: Recursive Analysis

MA/CSSE 473 Day 12. Questions? Insertion sort analysis Depth first Search Breadth first Search. (Introduce permutation and subset generation)

CSC 1700 Analysis of Algorithms: Minimum Spanning Tree

CSC 1052 Algorithms & Data Structures II: Linked Lists Revisited

Computer Science 385 Design and Analysis of Algorithms Siena College Spring Topic Notes: Brute-Force Algorithms

CSC 8301 Design and Analysis of Algorithms: Heaps

LECTURE 17 GRAPH TRAVERSALS

Graph. Vertex. edge. Directed Graph. Undirected Graph

4. Apply insertion sort to sort the list E, X, A, M, P, L, E in alphabetical order.

CSC 8301 Design & Analysis of Algorithms: Warshall s, Floyd s, and Prim s algorithms

Brute Force: Selection Sort

CSC 172 Data Structures and Algorithms. Lecture 24 Fall 2017

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

CS61BL. Lecture 5: Graphs Sorting

CSC 1052 Algorithms & Data Structures II: Recursion

Lecture 9 Graph Traversal

CS/COE

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

CSC Design and Analysis of Algorithms. Lecture 5. Decrease and Conquer Algorithm Design Technique. Decrease-and-Conquer

e-pg PATHSHALA- Computer Science Design and Analysis of Algorithms Module 14 Component-I (A) - Personal Details

LECTURE 3 ALGORITHM DESIGN PARADIGMS

CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs

Algorithm Design Paradigms

Lecture 26: Graphs: Traversal (Part 1)

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.

Anany Levitin 3RD EDITION. Arup Kumar Bhattacharjee. mmmmm Analysis of Algorithms. Soumen Mukherjee. Introduction to TllG DCSISFI &

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Uninformed Search. (Textbook Chpt 3.5) Computer Science cpsc322, Lecture 5. May 18, CPSC 322, Lecture 5 Slide 1

Lecture 3. Brute Force

Solutions to relevant spring 2000 exam problems

CMPSCI 250: Introduction to Computation. Lecture #24: General Search, DFS, and BFS David Mix Barrington 24 March 2014

CSC 1052 Algorithms & Data Structures II: Introduction

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

Graphs and Algorithms

CS Data Structures and Algorithm Analysis

Graph Traversals BFS & DFS 1 CS S-16

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

MA/CSSE 473 Day 17. Divide-and-conquer Convex Hull. Strassen's Algorithm: Matrix Multiplication. (if time, Shell's Sort)

Uninformed Search Strategies

Discrete Motion Planning

Module 2: Classical Algorithm Design Techniques

CSC Design and Analysis of Algorithms

Recursion & Performance. Recursion. Recursion. Recursion. Where Recursion Shines. Breaking a Problem Down

Computer Science and Software Engineering University of Wisconsin - Platteville. 3. Search (Part 1) CS 3030 Lecture Notes Yan Shi UW-Platteville

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI. Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II

CS Elementary Graph Algorithms & Transform-and-Conquer

Basic Graph Algorithms (CLRS B.4-B.5, )

Outline. Graphs. Divide and Conquer.

CSC Design and Analysis of Algorithms. Lecture 7. Transform and Conquer I Algorithm Design Technique. Transform and Conquer

CS 310 Advanced Data Structures and Algorithms

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

Data Structures and Algorithms

CS 445: Data Structures Final Examination: Study Guide

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

COMP 182 Algorithmic Thinking. Breadth-first Search. Luay Nakhleh Computer Science Rice University

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

Data Structures and Algorithms

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

CSC 1052 Algorithms & Data Structures II: Queues

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

CSI 604 Elementary Graph Algorithms

Module 5 Graph Algorithms

Algorithm Design and Analysis

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

CSC Design and Analysis of Algorithms

Shell Sort. Biostatistics 615/815

CSC 1052 Algorithms & Data Structures II: Lists

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer

Graph Search. CS/ECE 374: Algorithms & Models of Computation, Fall Lecture 15. October 18, 2018

CSCE f(n) = Θ(g(n)), if f(n) = O(g(n)) and f(n) = Ω(g(n)).

CPS 616 TRANSFORM-AND-CONQUER 7-1

Introduction to Algorithms

An Appropriate Search Algorithm for Finding Grid Resources

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

Graph Search. Algorithms & Models of Computation CS/ECE 374, Fall Lecture 15. Thursday, October 19, 2017

Topic Analysis PART-A

CS24 Week 8 Lecture 1

Figure 1: A directed graph.

Info 2950, Lecture 16

W4231: Analysis of Algorithms

About this exam review

Improving Search In Peer-to-Peer Systems

Homework Assignment #3 Graph

Computer Science 431 Algorithms The College of Saint Rose Spring Topic Notes: Decrease and Conquer

CSC Design and Analysis of Algorithms. Lecture 5. Decrease and Conquer Algorithm Design Technique. Decrease-and-Conquer

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

Introduction to Computer Science and Programming for Astronomers

CSci 231 Final Review

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

CS Divide and Conquer

CS 350 Final Algorithms and Complexity. It is recommended that you read through the exam before you begin. Answer all questions in the space provided.

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions

CSE 332: Data Abstractions Lecture 15: Topological Sort / Graph Traversals. Ruth Anderson Winter 2013

Transcription:

CSC 8301 Design and Analysis of Algorithms: Graph Traversal Professor Henry Carter Fall 2016

Exhaustive Search Combinatorial/Optimization problems often require exhaustive search Exhaustive search is critical in many other problems The algorithm for search can be optimized based on data structure and application 2

Exhaustive (Graph) Search Graphs are a very common construction in computer science Specially structured graphs called trees are a common way to store data How do we search graph vertices in an ordered fashion? 3

Depth-First Search Searches vertices by moving as far as possible from the starting node Produces a set of trees containing the searched vertices called a Depth-First Search Forest Implemented with a stack (last in first out) data structure (or a recursive call stack) 4

Breadth-First Search Searches vertices by staying as near as possible from the starting node Also outputs a search forest Implemented with a queue (first in first out) data structure 5

BFS Algorithm 6

BFS: Example Graph 7

BFS: Analysis Matrix: List 8

What s the point? Mathematical: acyclicity, minimum-edge paths Networks (communication, social) are often represented as trees Breadth first search finds nearby neighbors (e.g., closest social connection, closest BitTorrent peer) Also used in garbage collection (e.g., Java) 9

Ordering In some application, the order of traversal matters BFS yields a unique ordering (objects enter/exit the queue in one order) DFS yields two orderings depending on when vertices are recorded Pre-order Post-order 10

BFS Order 11

DFS Pre-order 12

DFS Post-order 13

Practice f c b e d a g 14

Decrease-and-Conquer Previous chapters focus on solving the full-sized problem Brute force: not efficient Some problems can (should) be broken into smaller versions 15

Decrease-and-Conquer Solutions that use relations between the problem instance and a smaller instance Comes in three delicious flavors: Decrease by a constant Decrease by a constant factor Variable decrease 16

Decrease by a constant Reduces problem size by an additive constant (like 1) Can be iterative OR recursive Example: Exponentiation 17

Decrease by a constant factor Divide problem size by a constant (like 2) Common in recursion (divide-and-conquer) Example: Exponentiation v. 2 18

Variable decrease Reduction depends on problem and input Includes problems that aren t clearly reduce-by-constant or reduce-by-constant-factor Example: Euclid s algorithm 19

Applying decrease-and-conquer: sorting Insertion sort iteratively inserts an element into a presorted array Differs from previous algorithms that do not assume any previous sorting Iterative application allows for sorting a completely unsorted list 20

Insertion Sort Algorithm Insertion Sort(A[0..n-1]) for i 1 to n-1 do v A[i]; j i - 1 while j 0 and A[j] > v do A[j+1] A[j] j j - 1 A[j+1] v 21

Insertion Sort Example 22

Insertion Sort Analysis C worst (n) = C best (n) = C avg (n) 23

Insertion Sort Facts Good elementary sorting algorithm (very good on nearly-sorted data) Can be extended in many ways (e.g., Shellsort) Equivalent order of growth to selection sort in worst/average cases 24

Ferrying Soldiers A detachment of n soldiers must cross a wide and deep river with no bridge in sight. They notice two 12-yearold boys playing in a rowboat by the shore. The boat is so tiny, however, that it can only hold two boys or one soldier. How can the soldiers get across the river and leave the boys in joint possession of the boat? How many times need the boat pass from shore to shore? 25

Recap Decrease-and-conquer solutions relate a problem to a smaller instance Three varieties: Decrease-by-constant Decrease-by-constant-factor Variable Decrease Insertion sort iteratively inserts elements into a previously sorted list Great for nearly-sorted data 26

Next Time... Levitin Chapter 4.2, 4.4 Remember, you need to read it BEFORE you come to class! Homework 3.5: 4, 6, 7 4.1: 2, 4, 5, 9, 11 27