Results 1 to 10 of 10
Thread: Efficiency of searching a list
- 06-29-2011, 02:26 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 78
- Rep Power
- 0
Efficiency of searching a list
I need some help with these homework questions.
What is the avg # of nodes accessed in search for a particular element in an unordered list? ordered list? In an unordered array? In an ordered array? Note that a list could be implemented as a linked structure or with an array.
I would think that the number of nodes accessed in an ordered or unordered list would be the same, On, and for an ordered or unordered array would be Ologn
- 06-29-2011, 02:43 AM #2
Senior Member
- Join Date
- Feb 2011
- Location
- Georgia, USA
- Posts
- 122
- Rep Power
- 0
Why do you think that arrays can be searched faster than lists? and why do you think that sorted and unsorted lists can be searched with the same efficiency? same question as previous for arrays?
- 06-29-2011, 02:49 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 78
- Rep Power
- 0
I thought both arrays and lists had random access capability (meaning I can get to the ith element at any time), so Im not sure?
- 06-29-2011, 03:09 AM #4
Member
- Join Date
- Feb 2011
- Posts
- 78
- Rep Power
- 0
any ideas?
- 06-29-2011, 03:13 AM #5
I have plenty of ideas. However in regards to your question it would seem it is your homework and as such you need to provide the answers not just copy and paste what we say, hand it in and get a mark you do not deserve. If you cannot answer these questions then take an F and wait for the teacher to explain the answers. Or you can read your course material and/or search online for discussions on searching. I'm sure Wiki would provide sufficient info on various searching algorithms.
- 06-29-2011, 03:20 AM #6
Member
- Join Date
- Feb 2011
- Posts
- 78
- Rep Power
- 0
If you saw my first post, I added what I thought the correct answer was. yellowledbet asked me a question, and I responded, and my response left me with another question. I'm not sure why you feel the need to be so negative. Its a homework question, I have questions about it, and was looking for help on it, that simple. Im also not sure why you think I would 'copy and paste' anything.
- 06-29-2011, 03:21 AM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
First what are you searching for: the value at some given index? or the index of some given value?
I am not completely sure of what you are getting at here. But if it relates to accessing the element at a particular index then there are lists and there are lists. (Read the API docs for ArrayList and LinkedList for instance.) As far as I know there are no guarantees made about instances of array: you might guess, but that's not the same thing.I thought both arrays and lists had random access capability (meaning I can get to the ith element at any time),
-----
Any questions about how many nodes will be accessed seem to depend on what algorithm you are using.
- 06-29-2011, 03:23 AM #8
If you had an unsorted list then how many elements would you have to look at before knowing that the search term was not present? Given 6 1 8 3 9 when would you know 2 is not present.
If you had a sorted list then how many elements would you have to look at before knowing that the search term was not present? Given 1 3 6 8 9 when would you know 2 is not present.
There! Is that better? Was that negative?
- 06-29-2011, 03:30 AM #9
Member
- Join Date
- Feb 2011
- Posts
- 78
- Rep Power
- 0
thank you
-.gif)
I see what you are getting at, BUT if I had a list with 1 2 3 4 5, I would only have to search 2 elements to know if 2 was present, and in your example, you had to search the whole list because the element wasn't present.
- 06-29-2011, 03:34 AM #10
Similar Threads
-
what code for searching in drop down list?
By Harmesh Goyal in forum Advanced JavaReplies: 1Last Post: 03-03-2011, 04:43 AM -
URLConnection Efficiency
By Lil_Aziz1 in forum New To JavaReplies: 22Last Post: 08-19-2010, 06:27 PM -
An Efficiency Question
By Revenna in forum Java 2DReplies: 0Last Post: 06-25-2010, 07:22 AM -
Searching for a String within an linked list
By phil128 in forum Advanced JavaReplies: 5Last Post: 04-13-2009, 02:18 AM -
Searching through a list.
By wethekings in forum New To JavaReplies: 3Last Post: 02-24-2009, 12:43 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks