2079 12

BIT201 · 2079 · 5 marks

Write short notes on: a) Linear Search Write short notes on: b) Minimum Spanning Tree [2.5+2.5]

Write short notes on: a) Linear Search Write short notes on: b) Minimum Spanning Tree [2.5+2.5]

Data Structures and AlgorithmsChapter 7: Searching and HashingSequential search algorithm

Quick answer

MST selects edges: A-B (1), B-C (2), C-D (3) → Total weight = 6

Short Notes

Definition: Linear search (also called sequential search) is the simplest searching algorithm that checks each element of a list one by one, from the beginning to the end, until the desired element (key) is found or the list is exhausted.

Algorithm:

LinearSearch(A[], n, key):
1. for i = 0 to n-1 do
2.     if A[i] == key then
3.         return i        // element found at index i
4. return -1               // element not found

Working:

  • Start from the first element.
  • Compare each element with the search key.
  • If a match is found, return the position.
  • If the end of the array is reached without a match, return -1 (not found).

Example: Array: [5, 3, 8, 1, 9], Key = 8

  • Compare 5 != 8, Compare 3 != 8, Compare 8 == 8 → Found at index 2.

Complexity:

CaseTime Complexity
Best CaseO(1)
Worst CaseO(n)
Average CaseO(n)

Space Complexity: O(1)

Advantages:

  • Simple to implement.
  • Works on both sorted and unsorted arrays.
  • No preprocessing required.

Disadvantage:

  • Inefficient for large datasets compared to binary search.

b) Minimum Spanning Tree (MST)

Definition: A Minimum Spanning Tree of a connected, undirected, weighted graph G = (V, E) is a spanning tree that connects all vertices with the minimum possible total edge weight, containing exactly |V| - 1 edges and no cycles.

Key Properties:

  • It spans all vertices (all n vertices are included).
  • It is acyclic (no cycles).
  • It has exactly n - 1 edges for n vertices.
  • The sum of edge weights is minimum among all possible spanning trees.

Example:

Consider a graph with 4 vertices and edges:

A --1-- B
|       |
4       2
|       |
D --3-- C

Algorithms to Find MST:

AlgorithmApproachTime Complexity
Kruskal'sSort edges by weight; add edge if no cycle (greedy)O(E log E)
Prim'sGrow tree from a starting vertex by adding minimum weight edgeO(E log V)

Applications:

  • Network design (telephone, electrical, road networks).
  • Cluster analysis.
  • Approximation algorithms for NP-hard problems (e.g., Travelling Salesman Problem).
  • Designing least-cost communication networks.

Significance: MST provides the most cost-effective way to connect all nodes in a network, making it fundamental in graph theory and network optimization.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.