Download presentation
Presentation is loading. Please wait.
1
Week 6 - Wednesday CS 113
2
Last time What did we talk about last time? Exam 1 post-mortem
Programming practice
3
Project 2
4
Graph a sine curve We can show a sine curve
Using a while loop, we can make a lot of x values between -10 and 10 We can use the sin() function to find the corresponding y location Then we put a small red sphere at each location
5
Graph Theory A completely different kind of graph than what we just talked about!
6
What is a graph? Vertices (Nodes) Edges
7
What can graphs represent?
Friendships on Facebook Steps in a task Nodes: Subtasks Nodes: People Edges: Decisions Edges: Friendship Routes between cities 6 degrees of Kevin Bacon Nodes: Cities Edges: Streets Nodes: Actors Edges: Whether or not they've been in a movie together
8
Lots of flavors of graphs
Labeled Weighted Colored Multigraphs E A D B F C A 5 6 4 3 2 3 E 5 B D F C 7 1
9
No Triangle Inequality
When a weighted graph obeys the triangle inequality, the direct route to a node is always fastest 1 4 2 3 5 No Triangle Inequality 1 2 4 3 5 Triangle Inequality
10
Directed graphs Some graphs have edges with direction
Example: One way streets Reachability? ONE WAY E A D B F C
11
Connected graphs Often we talk about connected graphs
But, not all graphs have to be connected
12
The other extreme Complete graphs
Every node is connected to every other How many edges? |E| = ½(n(n – 1)) = ½(n2 – n) is O(n2)
13
Subgraphs We can talk about a part of a graph
For example, what is the largest complete subgraph in this graph? A E B D F C
14
Paths A path is a sequence of connected nodes
The cost or weight of the path is usually the sum of the edge weights This path from A to C costs 5 A 5 6 4 3 2 3 E B D 3 F 7 C
15
Cycles A cycle is a path that starts at a node and comes back to the same node How many cycles of length 3 does this graph have? What about 4? 5? 6? A D B A E B D F C
16
Tours A tour is a path that visits every node and (usually) returns to its starting node In other words, it's a cycle that visits every node This tour costs 24 A 5 6 4 3 2 3 E B D 3 F 7 C
17
Matching
18
Bipartite graphs A bipartite graph is one whose nodes can be divided into two disjoint sets X and Y There can be edges between set X and set Y There are no edges inside set X or set Y A graph is bipartite if and only if it contains no odd cycles
19
Bipartite graph X A B C D E F Y A B C D E F
20
Maximum matching A perfect matching is when every node in set X and every node in set Y is matched It is not always possible to have a perfect matching We can still try to find a maximum matching in which as many nodes are matched up as possible
21
Matching algorithm Come up with a legal, maximal matching
Take an augmenting path that starts at an unmatched node in X and ends at an unmatched node in Y If there is such a path, switch all the edges along the path from being in the matching to being out and vice versa If there is another augmenting path, go back to Step 2
22
X Y Match the graph Anna Becky Caitlin Daisy Erin Fiona A B C D E F A
Adam Ben Carlos Dan Evan Fred
23
Quiz
24
Upcoming
25
Next time… Stable marriage Euler paths and tours
Minimum spanning trees Lab 6
26
Reminders Start working on Project 2 Read Python Chapter 5
Think about what you want to do for your Final Project Proposal due by 3/31
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.