DS2
DS2
A linear data structure organizes elements sequentially, where each element has a unique
successor and predecessor (except the first and last elements).
Examples:
5. Deques – A double-ended queue that supports insertions and deletions from both ends.
A non-linear data structure does not store data in a sequential manner. Instead, it forms
hierarchical or interconnected relationships.
Examples:
A tree is a hierarchical data structure that consists of nodes connected by edges. It is a special
type of graph with no cycles.
Key Characteristics:
Types of Trees:
2. Binary Search Tree (BST) – A binary tree where the left subtree contains smaller
values and the right subtree contains larger values.
3. Balanced Tree – A tree where the height is minimized (e.g., AVL Tree, Red-Black Tree).
5. Trie – Used for string searching (e.g., in dictionaries, autocomplete features).
B. Graph Theory
A graph is a collection of nodes (vertices) and connections (edges). Graphs can be used to
model relationships in networks, social media, and navigation systems.
Types of Graphs:
3. Weighted Graph – Edges have weights (e.g., representing distances or costs).
5. Cyclic and Acyclic Graphs – Acyclic graphs have no cycles (e.g., Trees are acyclic
graphs).
Graph Algorithms:
1. Depth-First Search (DFS) – Explores as far as possible along each branch before
backtracking.
2. Breadth-First Search (BFS) – Explores all neighbors before moving deeper.
4. Kruskal’s and Prim’s Algorithm – Used to find the Minimum Spanning Tree (MST).
5. Floyd-Warshall Algorithm – Computes shortest paths between all pairs of vertices.
Example:
For a graph G = (V, E) where V = {a, b, c, d} and E = {{a, b}, {a, c}, {b,
c}, {c, d}}:
● Vertices: a, b, c, d
● Edges: {a, b}, {a, c}, {b, c}, {c, d}
For DFS, starting from vertex a, you would visit the vertices as a -> b -> c -> d.
3. Computational Geometry
A. Basics of Computational Geometry
Key Characteristics:
B. Applications:
Example:
● Convex Hull Algorithm:
A convex hull is the smallest convex polygon that contains all the points. It is important
in areas like robotics and pathfinding.
○ For a set of points in 2D, you can use the Graham Scan algorithm to find the
convex hull in O(n log n) time.
4. Network Models
A. Basics of Network Models
A Network Model defines how data is structured, transmitted, and managed in a computer
network. The two primary models are:
1. PAN (Personal Area Network) – Small-scale, like Bluetooth, smart devices.
Network Topologies: