Aspire's Library

A Place for Latest Exam wise Questions, Videos, Previous Year Papers,
Study Stuff for MCA Examinations - NIMCET

Previous Year Question (PYQs)



The statements of pseudocode for searching the first element with key k in the linked list L are given below. 
Arrange them in the correct order. 

(A) while (x!=NIL and x.key != k) 

(B) x=L.head 

(C) x=x.next 

(D) return x 

Choose the correct answer from the options given below: 





Solution

Given statements:
(A) \(\; \text{while }(x \neq NIL \;\wedge\; x.key \neq k)\)
(B) \(\; x = L.head\)
(C) \(\; x = x.next\)
(D) \(\; \text{return } x\)

Correct order:
1. Initialize pointer: \((B)\) → \(x = L.head\)
2. Loop until end or key found: \((A)\) → \(\text{while}(x \neq NIL \;\wedge\; x.key \neq k)\)
3. Move to next node: \((C)\) → \(x = x.next\)
4. Return result: \((D)\) → \(\text{return }x\)

✅ Therefore, the correct sequence is: \[ (B), (A), (C), (D) \]


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

Ask Your Question or Put Your Review.

loading...