In pointer implementation of linked lists, which operation can be performed in…

2025

In pointer implementation of linked lists, which operation can be performed in constant time (O(1)) when inserting or deleting nodes?

  1. A.

    Inserting at the beginning

  2. B.

    Inserting at the end

  3. C.

    Inserting at a specific position

  4. D.

    Deleting a specific node

Attempted by 466 students.

Show answer & explanation

Correct answer: A

Explanation of Time Complexity in Linked Lists

In a pointer-based linked list, the time complexity of operations depends on whether traversal is required.

1. Inserting at the Beginning (O(1))

This operation is performed in constant time. We simply create a new node, point its next pointer to the current head, and update the head pointer to the new node. No traversal is needed.

2. Inserting at the End (O(n) or O(1) with tail)

Without a tail pointer, we must traverse the entire list to find the last node, taking O(n) time. Even with a tail pointer, this is a special case, but the general standard linked list operation is O(n).

3. Inserting at a Specific Position (O(n))

We must traverse the list from the head to reach the desired position before inserting. This traversal makes the time complexity linear, O(n).

4. Deleting a Specific Node (O(n))

Locating the specific node requires traversing the list, which takes O(n) time. The actual deletion is O(1) once found, but the total time is dominated by the search.

हिन्दी में व्याख्या

पॉइंटर-आधारित लिंक्ड लिस्ट में, ऑपरेशन का समय जटिलता इस बात पर निर्भर करती है कि क्या लिस्ट को ट्रैवर्स (traverse) करना आवश्यक है।

1. शुरुआत में सम्मिलित करना (O(1))

यह ऑपरेशन स्थिर समय में किया जाता है। हमें केवल एक नया नोड बनाना है, उसका अगला पॉइंटर वर्तमान हेड पर सेट करना है, और हेड पॉइंटर को नए नोड पर अपडेट करना है। लिस्ट को ट्रैवर्स करने की आवश्यकता नहीं है।

2. अंत में सम्मिलित करना (O(n) या O(1) टेल पॉइंटर के साथ)

टेल पॉइंटर के बिना, हमें अंतिम नोड खोजने के लिए पूरी लिस्ट को ट्रैवर्स करना पड़ता है, जिसमें O(n) समय लगता है।

3. एक विशिष्ट स्थान पर सम्मिलित करना (O(n))

सम्मिलित करने से पहले, हमें हेड से शुरू करके वांछित स्थान तक पहुंचने के लिए लिस्ट को ट्रैवर्स करना होता है। यह ट्रैवर्सल समय जटिलता को रैखिक (linear) बनाता है।

4. एक विशिष्ट नोड को हटाना (O(n))

विशिष्ट नोड को खोजने के लिए लिस्ट को ट्रैवर्स करना पड़ता है, जिसमें O(n) समय लगता है।

Explore the full course: Bpsc