CSC 380: Design and Analysis of Algorithms

Slides:



Advertisements
Similar presentations
CSE 373 Data Structures and Algorithms Lecture 20: Graphs II.
Advertisements

22C:19 Discrete Math Graphs Fall 2010 Sukumar Ghosh.
Graph-02.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
CSE 373: Data Structures and Algorithms Lecture 19: Graphs III 1.
9.2 The Traveling Salesman Problem. Let us return to the question of finding a cheapest possible cycle through all the given towns: We have n towns (points)
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
Graph & BFS Lecture 22 COMP171 Fall Graph & BFS / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D.
Graphs Chapter 28 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Backtracking.
GRAPH Learning Outcomes Students should be able to:
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Chapter 9 Graph Algorithms Real-life graph problems Algorithms for some graph problems Choice of data structures for graph problems.
Computer Science 112 Fundamentals of Programming II Introduction to Graphs.
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
Representing and Using Graphs
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
CS 200 Algorithms and Data Structures
CIRCUITS, PATHS, AND SCHEDULES Euler and Königsberg.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
Graphs. Graph Definitions A graph G is denoted by G = (V, E) where  V is the set of vertices or nodes of the graph  E is the set of edges or arcs connecting.
1 Euler and Hamilton paths Jorge A. Cobb The University of Texas at Dallas.
Exhaustive search Exhaustive search is simply a brute- force approach to combinatorial problems. It suggests generating each and every element of the problem.
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
Graphs.
Graphs Chapter 20.
EECS 203 Lecture 19 Graphs.
Data Structures Graphs - Terminology
CSC 172 DATA STRUCTURES.
Introduction to Graphs
Routing Through Networks - 1
SULE SOLMAZ BEYZA AYTAR
Introduction to Graphs
EECS 203 Lecture 20 More Graphs.
CS120 Graphs.
CMSC 341 Lecture 21 Graphs (Introduction)
CSE 373: Data Structures and Algorithms
Discrete Maths 9. Graphs Objective
Graph.
Refresh and Get Ready for More
Graph Algorithm.
CSC 172 DATA STRUCTURES.
Introduction to Graph Theory Euler and Hamilton Paths and Circuits
Graph Theory.
Graphs Chapter 13.
Graphs CSE 2011 Winter November 2018.
Genome Assembly.
Minimum Spanning Trees
Chapter 9: Graphs Basic Concepts
Graph Operations And Representation
Algorithms: Design and Analysis
Backtracking and Branch-and-Bound
Graphs G = (V, E) V are the vertices; E are the edges.
Euler and Hamiltonian Graphs
CSC 380: Design and Analysis of Algorithms
GRAPHS G=<V,E> Adjacent vertices Undirected graph
CSC 380: Design and Analysis of Algorithms
CSC 380: Design and Analysis of Algorithms
CSE 373 Graphs 3: Implementation reading: Weiss Ch. 9
CSC 380: Design and Analysis of Algorithms
CSC 380: Design and Analysis of Algorithms
Graphs: Definitions How would you represent the following?
Lecture 10 Graph Algorithms
CSC 380: Design and Analysis of Algorithms
Algorithms CSCI 235, Spring 2019 Lecture 32 Graphs I
Chapter 9: Graphs Basic Concepts
Chapter 9 Graph algorithms
For Friday Read chapter 9, sections 2-3 No homework
Introduction to Graphs
Presentation transcript:

CSC 380: Design and Analysis of Algorithms Dr. Curry Guinn

Quick Info Dr. Curry Guinn CIS 2015 guinnc@uncw.edu www.uncw.edu/people/guinnc 962-7937 Office Hours: MWF: 10:00am-11:00m and by appointment

Today Traveling Salesman Problem Homework 3 due tonight!

Travelling Salesman Problem (TSP) Given n cities and the costs of travelling from one city to another. Find the shortest tour that visits all cities exactly once and then returns to the starting city.

Travelling Salesman Problem (TSP) Given a weighted undirected complete graph with n nodes. Starting at node s find a cycle that visits each node exactly once and ends in s (Hamiltonian cycle) with the least weight.

Example B 3 A 8 2 2 2 C 4 E

The number of tours for 25 cities: Too Many Tours There is a problem with the exhaustive search strategy the number of possible tours of a map with n cities is (n − 1)! / 2 The number of tours grows incredibly quickly as we add cities to the map The number of tours for 25 cities: #cities #tours 5 12 6 60 7 360 8 2,520 9 20,160 10 181,440 310,224,200,866,619,719,680,000

Real-Life Applications The solution of several important “real world” problems is the same as finding a tour of a large number of cities transportation: school bus routes, service calls, delivering meals, ... manufacturing: an industrial robot that drills holes in printed circuit boards VLSI (microchip) layout communication: planning new telecommunication networks For many of these problems n (the number of “cities”) can be 1,000 or more

The Traveling Salesman The TSP is a famous problem first posed by Irish mathematician W. R. Hamilton in the 19th century intensely studied in operations research and other areas since 1930 This tour of 13,500 US cities was generated by an advanced algorithm that used several “tricks” to limit the number of possible tours http://www.tsp.gatech.edu/ Required 5 “CPU-years”

TSP Some visualizations: http://www.math.uwaterloo.ca/tsp/index.html http://www.math.uwaterloo.ca/tsp/concorde/downloads/

Data Structures to Represent Graphs Matrix representation 2-dimensional array, A, adjacency matrix. For each edge (u, v), set A [u] [v] = 1; otherwise the entry is 0. If the edge has a weight associated with it, set A [u] [v] to the weight. Space requirement is (|V|2); alright if the graph is dense, i.e., |E| = (|V|2).

Adjacency matrix example The graph at right has the following adjacency matrix: How do we figure out the degree of a given vertex? How do we find out whether an edge exists from A to B? 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7

Pros/cons of Adj. matrix Advantage: fast to tell whether edge exists between any two vertices i and j (and to get its weight) Disadvantage: consumes a lot of memory on sparse graphs (ones with few edges)

Adjacency List Adjacency list representation For each vertex, keep a list of all adjacent vertices. For sparse graphs. Space requirement is (|E|+|V|).

Adjacency list example The graph at right has the following adjacency list: How do we figure out the degree of a given vertex? How do we find out whether an edge exists from A to B? 1 2 3 4 5 6 7 1 2 3 4 5 6 7

Pros/cons of adjacency list Advantage: New nodes can be added to the graph easily, and they can be connected with existing nodes simply by adding elements to the appropriate arrays Disadvantage: Determining whether an edge exists between two nodes requires O(n) time, where n is the average number of incident edges per node

Some code Graph.py TSP_Playground.py

For Next Class, Wednesday Homework 3 due next tonight!