cse 21 - lecture 3: graphs · cse 21: lecture3. graphs help us to visualize in a room there are 2n...
TRANSCRIPT
![Page 1: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/1.jpg)
CSE 21Lecture 3: Graphs
CSE 21: Lecture3
![Page 2: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/2.jpg)
Course Website
Course details is available online:http://cseweb.ucsd.edu/classes/wi14/cse21-a/
Regular announcements will be made on the webpage
First Assignment is uploaded
Solutions to the assignment will be uploaded onMonday
Discussion forum set up in Piazza
CSE 21: Lecture3
![Page 3: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/3.jpg)
Quizes
There will be around 6 quizes (5% each)
Most of them will be in class.
Some online quizes will be given on WeBWork.
Total marks for online quizes will be 5%.
First quiz will be on Wednesday (15th January) inclass.
CSE 21: Lecture3
![Page 4: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/4.jpg)
Representation of data
Numbers - represented over any base. In particular onecan represent a number over binary.
Sets - binary vectors.
Functions - Truth table.
Relationship among elements -
CSE 21: Lecture3
![Page 5: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/5.jpg)
Representation of relation among elements
Vertices - set of elements.
V = {v1, . . . , vn}
Edges - set of pairs of vertices.
E = {e1, . . . , em}
ek = (vi, vj)
Given the set of vertices and edges we have a graph
G = (V,E)
CSE 21: Lecture3
![Page 6: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/6.jpg)
Representation of relation among elements
Vertices - set of elements.
V = {v1, . . . , vn}
Edges - set of pairs of vertices.
E = {e1, . . . , em}
ek = (vi, vj)
Given the set of vertices and edges we have a graph
G = (V,E)
CSE 21: Lecture3
![Page 7: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/7.jpg)
Representation of relation among elements
Vertices - set of elements.
V = {v1, . . . , vn}
Edges - set of pairs of vertices.
E = {e1, . . . , em}
ek = (vi, vj)
Given the set of vertices and edges we have a graph
G = (V,E)
CSE 21: Lecture3
![Page 8: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/8.jpg)
Basic Definitions
Let G = (V,E) be a graph.
If (u, v) ∈ E implies (v, u) ∈ E then it is called anundirected graph.
An weight can be assigned to each edge. In that case itis called an weighted graph.
CSE 21: Lecture3
![Page 9: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/9.jpg)
Basic Definitions
Let G = (V,E) be a graph.
If (u, v) ∈ E implies (v, u) ∈ E then it is called anundirected graph.
An weight can be assigned to each edge. In that case itis called an weighted graph.
CSE 21: Lecture3
![Page 10: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/10.jpg)
Basic Definitions
Let G = (V,E) be a graph.
If (u, v) ∈ E implies (v, u) ∈ E then it is called anundirected graph.
An weight can be assigned to each edge. In that case itis called an weighted graph.
CSE 21: Lecture3
![Page 11: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/11.jpg)
Basic Definitions
Let G = (V,E) be a graph.
If there is an edge from vertex u to v we say v is aneighbor of u
For an undirected graph the total number of u suchthat (u, v) ∈ E is called degree of v.
CSE 21: Lecture3
![Page 12: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/12.jpg)
Basic Definitions
Let G = (V,E) be a graph.
If there is an edge from vertex u to v we say v is aneighbor of u
For an undirected graph the total number of u suchthat (u, v) ∈ E is called degree of v.
CSE 21: Lecture3
![Page 13: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/13.jpg)
Basic Definitions
Let G = (V,E) be a graph.
If there is an edge from vertex u to v we say v is aneighbor of u
For an undirected graph the total number of u suchthat (u, v) ∈ E is called degree of v.
CSE 21: Lecture3
![Page 14: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/14.jpg)
Example of a graph
a
b c
d e
f g
Vertices
7
85
9
7
515
6
8
9
11
CSE 21: Lecture3
![Page 15: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/15.jpg)
Example of a graph
a
b c
d e
f g
Undirected Graph
7
85
9
7
515
6
8
9
11
CSE 21: Lecture3
![Page 16: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/16.jpg)
Example of a graph
a
b c
d e
f g
7
85
9
7
515
6
8
9
11
Weighted Undirected Graphs
CSE 21: Lecture3
![Page 17: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/17.jpg)
Example of a graph
a
b c
d e
f g
7
85
9
7
515
6
8
9
11
Weighted Directed Graphs
CSE 21: Lecture3
![Page 18: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/18.jpg)
How many edges can be there?
How many edges can be there is a simple undirected graphon n vertices?
CSE 21: Lecture3
![Page 19: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/19.jpg)
Advantages of a graph
Mathematical way of expressing relations amongobjects.
Very simple.
Very general.
CSE 21: Lecture3
![Page 20: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/20.jpg)
Example: Friendship graph
Each person is a vertex.
If two person are friends then there is an edge betweenthe respective vertices.
Used for understanding social networks, like facebook.
CSE 21: Lecture3
![Page 21: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/21.jpg)
Example: Friendship graph
CSE 21: Lecture3
![Page 22: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/22.jpg)
Example: Internet Graph
Every website is a vertex.
If a website has a link to another website then there isa directed edge from the first vertex to the second.
Used for web crawls by google.
CSE 21: Lecture3
![Page 23: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/23.jpg)
Example: Internet Graph
CSE 21: Lecture3
![Page 24: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/24.jpg)
Example: Road Network
Vertices are the cities
Edges are the roads
CSE 21: Lecture3
![Page 25: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/25.jpg)
Example: Road Network
CSE 21: Lecture3
![Page 26: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/26.jpg)
Other Examples
Many other problems in real life can be designed as aproblem in graph theory.
So studying the structure of graphs and designingalgorithms for graph problems is an important field.
CSE 21: Lecture3
![Page 27: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/27.jpg)
Graphs help us to visualize
In a room there are 2n people. Some of the people shakehand with each other in such a way that if persons A andB shake hand and persons B and C shake hand thenperson A and C does not shake hand.
What is the maximum number of handshakes possible inthis case?
Ans: n2
CSE 21: Lecture3
![Page 28: CSE 21 - Lecture 3: Graphs · CSE 21: Lecture3. Graphs help us to visualize In a room there are 2n people. Some of the people shake hand with each other in such a way that if persons](https://reader033.vdocuments.us/reader033/viewer/2022050313/5f7554af97d3202e773431ef/html5/thumbnails/28.jpg)
Graphs help us to visualize
In a room there are 2n people. Some of the people shakehand with each other in such a way that if persons A andB shake hand and persons B and C shake hand thenperson A and C does not shake hand.
What is the maximum number of handshakes possible inthis case?
Ans: n2
CSE 21: Lecture3