Question:

Consider a procedure LIST-SEARCH (L, K) finds the first element with key K in list L by simple linear search, returning a pointer to its element. Arrange the following according to correct order of execution.
• [A.] x = L.head
• [B.] while x $\neq$ NIL and x.key $\neq$ K
• [C.] return x
• [D.] x = x.next
Choose the correct answer from the options given below:

Show Hint

Traversal always follows: Initialize → Check → Move → Return.
Updated On: Jun 5, 2026
  • A, B, D, C
  • B, C, D, A
  • A, D, B, C
  • A, B, C, D
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Concept: Linear search in a linked list involves sequential traversal.

Step 1:
Initialize pointer. \[ x = L.head \] \[ \Rightarrow A \]

Step 2:
Check condition.
• Continue until:
• End of list OR element found \[ \text{while } x \neq NIL \text{ and } x.key \neq K \] \[ \Rightarrow B \]

Step 3:
Move to next node. \[ x = x.next \] \[ \Rightarrow D \]

Step 4:
Return result. \[ \text{return } x \] \[ \Rightarrow C \]

Step 5:
Final sequence. \[ A \rightarrow B \rightarrow D \rightarrow C \] \[ \boxed{(1)} \]
Was this answer helpful?
0
0

Top CUET PG Time Complexity Questions