DSA - Adjacency List

What is an Adjacency List? An Adjacency List helps store a list of connections between each vertex in a finite graph. Vertex Connects with 0 1 1 0, 2, 3 2 1, 3 3 1, 2 Implementation The addEdge method takes vertices as input and adds an edge to the adjacency list. In this example, the adjacency list is represented as a dictionary that maps vertices to a set of all connected vertices....

September 17, 2024 · 1 min · Dmytro Chumakov

DSA - Graph

What is a graph? A graph is an abstract data type that represents vertices and edges that connect those vertices. Source Implementation A graph can be represented as a matrix with edges connecting each pair of vertices. For example, a graph with vertices 0, 1, 2, 3, 4 and edges between them can be represented as a matrix: 0 1 2 3 4 0 false true false false true 1 true false true true true 2 false true false true false 3 false true true false true 4 true true false true false In Swift, you can use a list of lists (2D array) to represent the matrix:...

September 14, 2024 · 2 min · Dmytro Chumakov