One Pager Cheat Sheet
- The
graphdata structure, though often intimidating to students, is a crucial tool for modeling information, allowing for complex abilities like social networking, and is used by companies like LinkedIn and Google to understand networks and relationships through various graph algorithms. - A
graphis a programmatic representation of connected things or entities, which uses nodes (dots) to represent items and connections (lines) between them known as edges, allowing us to model and document structures or relationships, such as those in social networks or internet web pages. - In graph terminology, dots are referred to as
nodesorvertices, lines are callededges, and the graph itself is a data structure representing relationships;edgescan be ordered or unordered depending on if the graph isdirectedorundirected, and may have weights signifying the link strength between vertices. - A graph in computer science and mathematics consists of two essential components,
nodes/verticesrepresenting distinct entities, andedgesdepicting the relationships or interactions between these entities, with attributes likedirectionandweightindicating specific aspects of these relationships. - The concept of a social network can be modeled as a graph, where users are represented as vertices and friendship relations are represented as edges, as demonstrated with a graph containing
Peter,Kevin,Jake, andDaniel. - Undirected graphs represent two-way relationships with edges that can be traversed in both directions, while directed graphs represent one-way relations with edges that can be traversed in a single direction.
- In graph theory, there are two types of graphs:
undirectedgraphs, which represent two-way relationships and can be traversed in both directions, anddirectedgraphs, which represent one-way relationships and can only be traversed in one direction. - The applications of
graphs include finding the shortest path, finding the best starting point, breadth-first and depth-first traversal, searching, inserting, deleting from a tree or linked list, graph classification, finding missing relationships through link prediction, and node classification. - The statement affirms that breadth-first and depth-first traversals are search algorithms used for navigating 'tree' and 'graph'
data structuresin ahorizontalandvertical mannerrespectively. - An
edge listis an implementation strategy for graphs where all the edges are stored in asingle list of pairs, each pair representing an edge through the two unique IDs of the nodes involved. - To find something in an edge list, an array-like data structure, one needs to iterate through it which is a linear time operation (
O(E)), leading to increased complexity in the case of larger arrays. - An adjacency matrix is a type of
matrixused to represent the vertices/nodes and connection/links in a graph, where1indicates an existing edge and0indicates a non-existing one, enabling lookup, insertion, and removal of an edge inO(1)orconstant time, but consumesO(V^2)space, whereVis the number of vertices. - The
get()method, used in the context of the adjacency matrix graph representation, takes anindexas a parameter to return thevertexat that particularindexin theverticeslist, representing eachvertexornodein the graph as alist. - This provides a complete implementation of an
adjacency matrix. - The
toString()method in Java, overridden in the Matrix class definition, creates a readable string representation of an object by returning aStringthat contains all attributes of the object, such as the size and values of a matrix, thereby providing an efficient way to view all data related to the object. - An
adjacency listis a hybrid of an edge list and an adjacency matrix, serving as the most common representation of agraphdue to its linked list structure that makes it easy to identify neighboring vertices, which is crucial for graph traversal problems. - The illustration depicts an adjacency list where each
vertexhas an index in itslistwith neighboring vertices stored as a linked list or array, enabling quick determination of a node's neighbors and their connections, taking aconstantorO(1)time to retrieve. - Understanding the basics of implementing graphs is fundamental to solving complex computer science problems, since graphs are likely utilized in any complex
computation.


