PadhaikoAll subjects

Past exam question: 2063 Baishakh (Regular / Back), Q5(b)

Data Structure and Algorithms · 5 marks

Open in the Padhaiko app

Topic: Searching Algorithms

Question

If you want to search in the unsorted record in linear date structure, which searching algorithm will you choose? Discuss.

Solution

Choice of Algorithm: Sequential (Linear) Search: For an unsorted linear data structure (array or linked list), Sequential (Linear) Search must be chosen because binary search requires pre-sorted random-access data (sorting first costs , which is slower than a single linear scan).

Algorithm LINEAR_SEARCH(A, n, key):
1. For i = 0 to n - 1:
       If A[i] == key: Return i
2. Return -1
Answer:

Sequential (Linear) Search is chosen for unsorted linear structures because it requires no sorting precondition, works on arrays and linked lists, and runs in worst-case time and space.

All past exam questions for Data Structure and Algorithms