0

What is the asymptotic worst-case running time for the following dynamic-set operations ?

Successor(L,x) for unsorted singly & doubly linked lists

Predecessor(L,x) for unsorted doubly linked list

L: list , x: pointer to an entry

(Actually this is part of the question 10-1 of the book : "Introduction to Algorithms, third edition" , I searched for the answer , the answer is O(n) but I couldn't find any explanation for it)

Arian
  • 7,397
  • 21
  • 89
  • 177

1 Answers1

0

With "predecessor" and "successor", I suppose you mean in sorted order.

It is indeed O(n) because you need to look at each element of the list to find it.

Dino
  • 1,576
  • 12
  • 12
  • But I guess that in Linked List the Predecessor and Successor means the elements which are right after/before the current element , the value does not matter – Arian Feb 17 '13 at 17:32
  • 1
    Yeah, I considered that too but if that is really the case, then this entire exercise is completely trivial (and the "sample solution" would make no sense). – Dino Feb 18 '13 at 12:45