Skip to content
Exercises · Q1

Q.Using linear search determine the position of 8, 1, 99 and 44 in the list:
[1, -2, 32, 8, 17, 19, 42, 13, 0, 44]
Draw a detailed table showing the values of the variables and the decisions taken in each pass of linear search.

Rajasthan RbseTextbookSubjective· 3mImportance★★★★★
47% · 8/17 Questions
✓ Free question

Linear search checks each element sequentially until the target is found or the list ends; we trace the search for four values (8, 1, 99, 44) through the given list, showing index, comparison, and decision at each step.

Linear search is the simplest search algorithm: start at the beginning of the list and compare each element with the target value. If a match is found, return the position (index); if you reach the end without finding it, the element is not present. It requires no pre-sorting and works on any list, making it the natural choice when the data is unordered.

The list we are searching is:

data = [1, -2, 32, 8, 17, 19, 42, 13, 0, 44]

Positions (indices) run from 00 to 99.


Search for 8

PassIndexElementComparison (element == 8)Decision
1011 == 8 → FalseContinue
21-2-2 == 8 → FalseContinue
323232 == 8 → FalseContinue
4388 == 8 → TrueFound at index 3

Result: 8 is found at position 3.


Search for 1

PassIndexElementComparison (element == 1)Decision
1011 == 1 → TrueFound at index 0

Result: 1 is found at position 0 (first element, immediate match).


Search for 99

PassIndexElementComparison (element == 99)Decision
1011 == 99 → FalseContinue
21-2-2 == 99 → FalseContinue
323232 == 99 → FalseContinue
4388 == 99 → FalseContinue
541717 == 99 → FalseContinue
651919 == 99 → FalseContinue
764242 == 99 → FalseContinue
871313 == 99 → FalseContinue
9800 == 99 → FalseContinue
1094444 == 99 → FalseEnd of list reached

Result: 99 is not found in the list.


Search for 44

PassIndexElementComparison (element == 44)Decision
1011 == 44 → FalseContinue
21-2-2 == 44 → FalseContinue
323232 == 44 → FalseContinue
4388 == 44 → FalseContinue
541717 == 44 → FalseContinue
651919 == 44 → FalseContinue
764242 == 44 → FalseContinue
871313 == 44 → FalseContinue
9800 == 44 → FalseContinue
1094444 == 44 → TrueFound at index 9

Result: 44 is found at position 9 (last element, worst-case scenario for linear search).


Python Implementation

Here is the linear search function and the trace for all four values:

def linear_search(data, target):
    for index in range(len(data)):
        if data[index] == target:
            return index  # Found
    return -1  # Not found

data = [1, -2, 32, 8, 17, 19, 42, 13, 0, 44]

targets = [8, 1, 99, 44]
for target in targets:
    position = linear_search(data, target)
    if position != -1:
        print(f"{target} found at index {position}")
    else:
        print(f"{target} not found")

Output:

8 found at index 3
1 found at index 0
99 not found
44 found at index 9
Tip

Linear search has time complexity O(n)O(n) in the worst case (element at the end or absent) and O(1)O(1) in the best case (element at the start). For sorted data, binary search (O(log⁡n)O(\log n)) is far more efficient, but linear search works on any list without preprocessing.

✓Final answer

8 is at position 3, 1 is at position 0, 99 is not found, and 44 is at position 9.

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.