Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack (1) Thread Tools Display Modes
Old 01-12-2008, 07:24 PM   1 links from elsewhere to this Post. Click to view. #1 (permalink)
Wandering In Tecno Land
 
Ecko's Avatar
 
Join Date: Feb 2005
Location: 127.0.0.1
Posts: 724
Exclamation A Simple C Question


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
An explanation will be highly appreciated
__________________
Born in Windows Die In Linux © 2009-10 All Rights Reserved.
Learn Linux : www.linoob.com (Official WebSite)
Ecko is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 01-12-2008, 07:42 PM   #2 (permalink)
Right Off the Assembly Line
 
Join Date: Oct 2007
Posts: 40
Default Re: A Simple C Question

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....
iq6886 is offline  
Old 01-12-2008, 08:21 PM   #3 (permalink)
Wandering In Tecno Land
 
Ecko's Avatar
 
Join Date: Feb 2005
Location: 127.0.0.1
Posts: 724
Default Re: A Simple C Question

Thanx a lot dude
Got it
BTW what's this
Quote:
the complexity of binary search using linked list is O(nlgn) and not O(lgn ) as in arrays..
__________________
Born in Windows Die In Linux © 2009-10 All Rights Reserved.
Learn Linux : www.linoob.com (Official WebSite)
Ecko is offline  
Old 01-12-2008, 08:28 PM   #4 (permalink)
Wahahaha~!
 
Faun's Avatar
 
Join Date: Dec 2006
Location: Pune/there
Posts: 7,676
Default Re: A Simple C Question

that big O notation Scary stuff, not anymore.
__________________
Blog | Flickr | Battlelog
Spoiler:
Asus Z68 V-Pro|i5 2500k|TRUE Black|Ripjaws X|U2311H|N560GTX|D7000|XONAR STX|RE272|RE0|CC51|XE200PRO Walnut| TD II V2| Ultraphile|N5800

Mono
Faun is offline  
Old 04-12-2008, 09:28 AM   #5 (permalink)
Right Off the Assembly Line
 
Join Date: Nov 2008
Location: Bangalore
Posts: 6
Default Re: A Simple C Question

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
srinivasa.s is offline  
Old 07-12-2008, 01:50 PM   #6 (permalink)
Right Off the Assembly Line
 
Join Date: Oct 2007
Posts: 40
Default Re: A Simple C Question

^ 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)
iq6886 is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


LinkBacks (?)
LinkBack to this Thread: http://www.thinkdigit.com/forum/programming/103339-simple-c-question.html
Posted By For Type Date
A Simple C Question Programming Question This thread Refback 09-07-2010 11:53 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
a rather simple question mightyboosh Software Q&A 6 22-08-2007 04:54 PM
A Simple Question ... bongourav Mobiles and Tablets 19 18-04-2007 12:50 AM
Simple question but big irritant for me. harpoon Open Source 6 16-08-2006 12:18 AM
simple question... vandit Hardware Q&A 4 16-07-2006 03:22 PM
A simple question ? perk_bud QnA (read only) 11 08-01-2005 12:36 PM

 
Latest Threads
- by gforz
- by soumya
- by Sujeet
- by icebags
- by Charan

Advertisement




All times are GMT +5.5. The time now is 03:01 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2