Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 380: Design and Analysis of Algorithms

Similar presentations


Presentation on theme: "CSC 380: Design and Analysis of Algorithms"— Presentation transcript:

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

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

3 Today Traveling Salesman Problem Homework 3 due tonight!

4 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.

5 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.

6 Example B 3 A 8 2 2 2 C 4 E

7 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

8 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

9 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 Required 5 “CPU-years”

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

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

12 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

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

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

15 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

16 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

17 Some code Graph.py TSP_Playground.py

18 For Next Class, Wednesday
Homework 3 due next tonight!


Download ppt "CSC 380: Design and Analysis of Algorithms"

Similar presentations


Ads by Google