Past exam question: 2063 Baishakh (Regular / Back), Q5(b)
Open in the Padhaiko appQuestion
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
- Best Case: (found at index 0).
- Average / Worst Case: (element at end or absent).
- Space Complexity: . Works identically on both arrays and linked lists.
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.