DIGIT-ARC read-only archive · snapshot: July 23, 2026

A Simple C Question

6 posts · originally from https://geek.digit.in/community/threads/a-simple-c-question.103339/

Ecko
Ecko Original post #1
Dec 1, 2008 at 7:24 PM
We'll a very simple C question here related with data structures

I want to know if Binary Search can be done in Linked List :confused:
An explanation will be highly appreciated :D:D
I
iq6886 #2
Dec 1, 2008 at 7:42 PM
Yes Binary search can be done using linked list...

but we simply don't coz the complexity of binary search using linked list is O(nlgn) and not O(lgn ) as in arrays..
let me explain you why this..

basically the increase in complexity is because of the added complexity to seeking to any element which is constant when using array( when we need to reach middle we just index it in array , but in linked list we need to reach it by traversing the linked list ).

so we need to tranverse linked list for every step of binary search or log n times.

I guess i explained it properly enough....
Ecko
Ecko #3
Dec 1, 2008 at 8:21 PM
Thanx a lot dude
Got it :D
BTW what's this
the complexity of binary search using linked list is O(nlgn) and not O(lgn ) as in arrays..
Faun
Faun #4
Dec 1, 2008 at 8:28 PM
that big O notation :D Scary stuff, not anymore.
S
Dec 4, 2008 at 9:28 AM
How is the complexity (n log n)? Its still linear - O(n). The worst case complexity of even linear search is O(n). This cannot be any worse! Basically, the search will not be called "binary search" if its done on lists
I
iq6886 #6
Dec 7, 2008 at 1:50 PM
^ it will still be called binary search beacoz of the concept whtr done using arrays or linked list or any other data type of ur choice..

and about the complexity , you can easily find it out to be O(nlgn) by solving the equation
T(n)=T(n/2) + O(n) ( not so sure about the equation though.. need to chk tht)