![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2007
Posts: 2
Rep Power: 0
![]() |
Search method for singly linked list
Hi,
Is there any effective search method for a singly linked list? linear search is too costly. |
|
|
|
|
|
#2 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,034
Rep Power: 5
![]() |
Linear search is all you've got, boy. If you want a more efficient search, use a different data structure.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2006
Posts: 14
Rep Power: 0
![]() |
couldn't you sort the linked list, then use a binary search
|
|
|
|
|
|
#4 |
|
Professional Programmer
|
Thats what a binary tree is for, is it not?
__________________
JG-Webdesign |
|
|
|
|
|
#5 | |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,034
Rep Power: 5
![]() |
Quote:
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Oct 2007
Posts: 2
Rep Power: 0
![]() |
Thanks for the update.
I have tried binary search, but is not efficient for a singly linked list. |
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You got a primo answer in response #1. Resonse #2 should never have been posted. You should be Googling for data structures and searching/sorting thereof by now....
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#8 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
>I have tried binary search, but is not efficient for a singly linked list.
Duh. Binary search relies on random access (or a suitable data structure) for its speed. Linked lists are notoriously bad at random access unless you want to go for broke and write something ridiculously complicated. If a sorted linear search is too slow, you're not using the right data structure. Do some research on skip lists, and consider using a binary search tree or hash table.
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#9 |
|
Programmer
Join Date: Feb 2008
Location: India
Posts: 58
Rep Power: 1
![]() |
Re: Search method for singly linked list
I will suggest you to use indexd search even for singly linked list! just create a array of structure for linked list. also for this you have to keep the linked list sorted. the code for that is also easy and this method is usefull if heavy searching is there and less insertions are to be done.insertion can be done in sorted manner!
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| linked list problems | bl00dninja | C++ | 6 | Feb 17th, 2008 10:30 AM |
| dev c++ software, template problem | cairo | C++ | 11 | Jun 2nd, 2006 12:42 PM |
| Singly Linked List Help | Firebar | Java | 3 | May 22nd, 2005 10:56 AM |
| User-defined creatNode and deleteNode functions for a doubly-linked list | jgs | C | 2 | Apr 28th, 2005 8:53 AM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 4:12 PM |