wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Given a circular doubly linked list whose content are sorted in ascending order, what is the run time complexity for inserting a new element into the list so that it remains correctly sorted? (Including the time required to search for the elements correct position)

A
O(s)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
O(logn)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
O(n)
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
D
O(n2)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is C O(n)
For inserting the element in the sorted circular doubly linked list, we must find the appropriate position for the element. For finding the position of the element we must do the linear search because random access is not possible in the linked list. Binary search does not work well with the linked list. So it will take O(n).

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
DLL-Insertion
OTHER
Watch in App
Join BYJU'S Learning Program
CrossIcon