algo note
algo note
Hashing :
Hashing is a technique used to uniquely iden fy a
specific object from a group of similar objects. It
involves conver ng an input (or 'key') into a fixed-size Time Complexity
string of bytes, typically by using a hash func on. This Minimum Spanning Tree (MST)
A Minimum Spanning Tree (MST) is a subset of edges
Prim's Algorithm: O(E log V) using a priority
output, known as a hash code or hash value, is queue (where E is the number of edges and
typically a numeric string. Hashing is widely used in in a weighted, connected graph that connects all the
V is the number of ver ces).
various applica ons, especially in computer science. ver ces together without any cycles and with the
minimum possible total edge weight. MSTs are used in Kruskal's Algorithm: O(E log E) due to
various applica ons, such as network design, sor ng edges, which simplifies to O(E log V)
defina on of Directed Acyclic Graph (DAG) :
clustering, and more. because E is at most V^2.
A Directed Acyclic Graph (DAG) is a graph that is both
directed and acyclic. Here's what that means: Prim's Algorithm
1. Directed: The edges between the ver ces Prim's Algorithm is a greedy algorithm that constructs
have a direc on, indica ng the rela onship an MST by star ng from a single vertex and adding the
flows in one direc on. For example, if smallest edge that connects a vertex in the MST to a
there's an edge from vertex A to vertex B, vertex outside the MST.
you can go from A to B, but not from B to A. Steps:
2. Acyclic: The graph contains no cycles. This 1. Ini alize the MST with a single vertex
means that you cannot start at a vertex, (usually the star ng vertex).
follow a sequence of edges, and return to 2. While there are ver ces not included in the
the same vertex. MST:
Example o Select the smallest edge that
Consider this simple DAG: connects a vertex in the MST to
a vertex outside the MST.
o Add the selected edge and
vertex to the MST.
3. Repeat un l all ver ces are included in the
MST.
In this graph: Numerical Example of Prim's Algorithm:
There are directed edges from A to B, A to Let's consider a graph with ver ces A, B, C, D, E and
C, B to D, and B to E. the following edges:
There are no cycles, meaning there's no
way to start at any vertex and return to it by
following the directed edges.