Question

both single and double?

There should be a big O for inserting and finding elements in a linked list.

According to Columbia notes, for a single linked list, it is:

Singly Linked List ( SSL ) An SLL is a series of nodes. Each node contains data and a reference to the next node. An SSL can grow and shrink as needed. Adding an element to the list is O (1). Finding an element in the list is O (n).

Was it helpful?

Solution

insert() takes O(1) as you can add an element to the head of the linked list in constant time

find() takes O(n) time as in the worst case you need to traverse the list till you reach the tail

These apply for both single and doubly linked lists

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top