Results 1 to 6 of 6
  1. #1
    bdario1 is offline Member
    Join Date
    Mar 2010
    Posts
    46
    Rep Power
    0

    Default Question about linked implementation

    Assume you have a container, and you must be able to quickly access data in the container in any order you want. Would an array-based implementation or a linked implementation be better? Why?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Sometimes a hash (such as a HashMap would be better). But given your two choices, which do you think would be better, and then let's discuss it. :)

  3. #3
    bdario1 is offline Member
    Join Date
    Mar 2010
    Posts
    46
    Rep Power
    0

    Default

    Well I think linked implementation would be better since you can do like list.add or remove or get indexOf size() to the List ADT - and things like that to it.
    Last edited by bdario1; 04-23-2010 at 03:29 AM.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Think of how you'd access random items on a linked list -- starting at the head and then walking through the list til you reach the item of interest, vs how you'd access a random item in an array -- get an index and then use it to scoop up the item of interest.

  5. #5
    bdario1 is offline Member
    Join Date
    Mar 2010
    Posts
    46
    Rep Power
    0

    Default

    So basically array seems to be better right? it seems faster since you can check left and right of the index and move the way you want and keep doing it until you get to your desired location. As with list you would have to go through every element before you get to it right?

  6. #6
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by bdario1 View Post
    So basically array seems to be better right? it seems faster since you can check left and right of the index and move the way you want and keep doing it until you get to your desired location. As with list you would have to go through every element before you get to it right?

    can you please tell how many elements you will have in your array?

Similar Threads

  1. array-based implementation question
    By intelli in forum New To Java
    Replies: 1
    Last Post: 04-18-2009, 05:18 PM
  2. n00b: linked list question
    By ankitmcgill in forum New To Java
    Replies: 2
    Last Post: 03-13-2009, 04:15 AM
  3. [SOLVED] Linked list question
    By ztrath in forum New To Java
    Replies: 8
    Last Post: 03-11-2009, 11:38 PM
  4. Linked List Question
    By CirKuT in forum New To Java
    Replies: 4
    Last Post: 12-10-2008, 06:56 PM
  5. question about linked lists
    By jkurth in forum Advanced Java
    Replies: 1
    Last Post: 11-11-2007, 08:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •