One Pager Cheat Sheet
- The
graph
data 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
graph
is 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
nodes
orvertices
, lines are callededges
, and the graph itself is a data structure representing relationships;edges
can be ordered or unordered depending on if the graph isdirected
orundirected
, and may have weights signifying the link strength between vertices. - A graph in computer science and mathematics consists of two essential components,
nodes/vertices
representing distinct entities, andedges
depicting the relationships or interactions between these entities, with attributes likedirection
andweight
indicating 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:
undirected
graphs, which represent two-way relationships and can be traversed in both directions, anddirected
graphs, which represent one-way relationships and can only be traversed in one direction. - The applications of
graph
s 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 structures
in ahorizontal
andvertical manner
respectively. - An
edge list
is 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
matrix
used to represent the vertices/nodes and connection/links in a graph, where1
indicates an existing edge and0
indicates a non-existing one, enabling lookup, insertion, and removal of an edge inO(1)
orconstant time
, but consumesO(V^2)
space, whereV
is the number of vertices. - The
get()
method, used in the context of the adjacency matrix graph representation, takes anindex
as a parameter to return thevertex
at that particularindex
in thevertices
list, representing eachvertex
ornode
in 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 aString
that 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 list
is a hybrid of an edge list and an adjacency matrix, serving as the most common representation of agraph
due 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
vertex
has an index in itslist
with neighboring vertices stored as a linked list or array, enabling quick determination of a node's neighbors and their connections, taking aconstant
orO(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
.