CPS 1: Introduction to Graph Theory Instructor: Nihshanka Debroy ([email protected]) What is a Graph ? ● ● Means of representation Set of vertices and edges ● Vertices (blue circles) ● Edges (black lines) ● ● Vertices (also called nodes) connected to each other by edges Largest example: the Internet! Internet and Graphs ● Vertices/Nodes: machines/servers/routers ● Edges: physical connections (wires) Internet ● Packets of information (bits) get routed on the Internet - Message gets divided into packets on client (your machine) - Packets sent out towards destination - Packets may take different routes to destination Another example: Computer File System ● ● A tree (type of graph) Each file contained within only 1 folder ● Purple nodes: folders ● Blue nodes: files ● ● Parent node of a node X: node just above X Child node: node just below Navigating through the File System ● ● ● Referencing pictures in our HTML code -> located files by file path File path: how to start from one file, go through the folders , and reach another file index.html to page2.html: index.html -> public_html -> cps1 -> page2.html Oracle of Bacon: another example Concept: Link an actor/actress with Kevin Bacon in the following manner: • Pick any film actor in history. • Link the actor you've chosen to Bacon via the films they've shared with other actors until you end up with Kevin Bacon himself. ● Finding smallest number of links can be difficult ● Can be modeled using a graph Let's try it out! Social Networks: Examples ● Friendship Networks (Facebook) - vertices: people in the world - edges/links: have met in person/on friends list ● Scientific Collaboration - vertices: Math and Comp. Sci. researchers - edges/links: b/w coauthors on a published paper - Erdos number: distance to Paul Erdos - Erdos was a hub: 507 coauthors! Terminology A ● B ● ● ● C ● Path: sequence of vertices (v0, v1, v2, ...,vn) such that vertices vk and vk+1 are connected by an edge (For eg., A-B-C) Cycle: path of vertices and edges that forms a connected loop (is there one here ?) Trees: do not have cycles Degree of a node: number of edges adjacent to it Connected Graphs: Path b/w any pair of vertices Is this Connected ? Is it a Graph ? A B C Directed Graphs ● ● ● ● Directed Edge: has direction Directed Graph: edges are all directed Path: can only have directed edges in this case Is there a cycle ? Edge weights ● ● Edges could have weights Mailman example Two Standard Traversals ● BFT (breadth-first): explore neighboring nodes first 1 ● DFT (depth-first): explore as far as possible before backtracking 4 2 8 7 11 3 6 5 9 10 12 Interesting questions ● ● ● ● Shortest path from A to any other vertex ? Color each circles in the graph,in such a way that if two circles have a line between them then they do not have the same color. What is the fewest number of colors you can use to do this? Visit all vertices without repeating ? Edges ? Given 2 vertices, A and B, is there more than one way of getting from A to B ?
© Copyright 2026 Paperzz