3. Hashing - Introduction
• • Hashing maps data of arbitrary size to fixed-
size values.
• • Used for efficient storage and retrieval.
• • Hash function converts input into a hash
value (index).
• • Common in databases, caches, and data
structures.
4. Hashing Key
• • Key is the input to the hash function.
• • Hash function maps the key to an index in a
table.
• • Good keys minimize collisions.
5. Types of Hashing Key
• 1. Simple Modular Hashing: index = key %
table_size
• 2. Multiplicative Hashing: index =
floor(table_size * (key * A % 1))
• 3. Folding Method: Break key and combine
parts
• 4. Mid-Square Method: Square key and take
middle digits
• 5. Universal Hashing: Random hash functions
to avoid worst cases
6. Applications of Hashing
• • Hash Tables
• • Symbol Tables in compilers
• • Caching (e.g., DNS Cache)
• • Cryptography (SHA, MD5)
• • Database Indexing
7. Graph - Introduction
• • Graph = Set of nodes (vertices) + edges
• • Directed or Undirected
• • Weighted or Unweighted
8. Graph Terminology
• • Vertex (Node): Graph unit
• • Edge: Connects two nodes
• • Degree: Number of edges per node
• • Path: Sequence of edges
• • Cycle: Path that starts and ends at same
node
9. Graph Representation
• 1. Adjacency Matrix:
• - matrix[i][j] = 1 if edge exists from i to j
• - Space: O(V^2)
• 2. Adjacency List:
• - List of connected nodes
• - Space: O(V + E)