Question

Analysis In java, a List can be implemented in a number of ways. Compare and contrast...

Analysis
In java, a List can be implemented in a number of ways. Compare and contrast an ArrayList and a LinkedLists. In which situations would you use one to implement a List over another?

(explain in runtime on add and remove, memory usage, and get/set.)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ArrayList and LinkedLists both implements list interface . They both are used to store large amount of data of similar type like marks of 1000 students. All operations they provide are same , difference lies in the performance of various operations , so according to the problem ,operations required frequently are identified and a decision is made between ArrayList and LinkedList.

While deciding which one to use , following points must be kept in mind :

Difference between Arraylist and LinkedList
ArrayList LinkedList
It uses dynamic array to store elements. It uses doubly linked list to store elements.
Manipulation with ArrayList is slow because it internally uses an array. If any element is removed from the array, all the bits are shifted in memory. Manipulation with LinkedList is faster than ArrayList because it uses a doubly linked list, so no bit shifting is required in memory.
Get/Set operations can be done in O(1) , since they are directly accessed using indexes.
Get/Set operations are done in O(n). LinkedList has to be travelled to the required positions.
ArrayList requires resizing which makes insertion and deletion slow , whenever arraylist gets full , it resize itself to make space for newer elements and this operation is O(n) in time complexity in worst case. Adding data or removing data in Linked list is O(1) if adding at the beginning or end , but if to be added in middle somewhere, time complexity will be O(n).
In arrayList , each index always holds actual object (actual data) .So , memory required is less. In linkedList, each node holds actual object(data) , as well address of previous and next node. Therefore , memory required is more per node in linked List.
Finding an element requires O(n) time but here data may be sorted and binary search can be applied , reducing the time complexity to O(log n). Finding an element requires O(n) time .

So , we can say ArrayList is better for storing and accessing data but linked list is better for manipulating data.

Add a comment
Know the answer?
Add Answer to:
Analysis In java, a List can be implemented in a number of ways. Compare and contrast...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Compare and contrast a theory, conceptual framework, and model. How might these three ways of thinking...

    Compare and contrast a theory, conceptual framework, and model. How might these three ways of thinking abstractly fit together? How is a road map like a framework or model? You are having coffee with a fellow student or colleague who thinks that theory, frameworks, and models are a waste of time and have nothing to do with practical nursing care. How might you argue that they can help you in daily nursing practice? Can you imagine different situations or contexts...

  • Skip list, needs to be implemented in Java: - Implement the class NodeSkipList with two components,...

    Skip list, needs to be implemented in Java: - Implement the class NodeSkipList with two components, namely key node and array of successors. You can also add a constructor, but you do not need to add any method. - In the class SkipList implement a constructor SkipList(long maxNodes). The parameter maxNodes determines the maximal number of nodes that can be added to a skip list. Using this parameter we can determine the maximal height of a node, that is, the...

  • In Java, the List interface provides the following methods (including those inherited from Collection): add, addAll,...

    In Java, the List interface provides the following methods (including those inherited from Collection): add, addAll, clear, contains, containsAll, equals, isEmpty, remove, removeAll, retain, size, toArray, get, indexOf, lastIndexOf, listIterator, set. Of these, which would you select to implement if you were going to implement your own ordered list? Specifically, the list will be used to insert, delete and search for items as well as being able to traverse the list to output the entire thing. Only make reference to...

  • // Java Queue LinkedList Assignment // A queue is implemented using a singly linked list. //...

    // Java Queue LinkedList Assignment // A queue is implemented using a singly linked list. // the variable: back "points" at the first node in the linked list // new elements ( enqueued) are added at the back // the variable: front "points" at the last node in the linked list. // elements are removed (dequeued) from the front // // Several queue instance methods are provided for you; do not change these // Other instance methods are left for...

  • Write a Java program to work with a generic list ADT using a fixed size array,...

    Write a Java program to work with a generic list ADT using a fixed size array, not ArrayList. Create the interface ListInterface with the following methods a) add(newEntry): Adds a new entry to the end of the list. b) add(newPosition, newEntry): Adds a new entry to the list at a given position. c) remove(givenPosition): Removes the entry at a given position from the list. d) clear( ): Removes all entries from the list . e) replace(givenPosition, newEntry): Replaces the entry...

  • 10.3 Example. When you first declare a new list, it is empty and its length is...

    10.3 Example. When you first declare a new list, it is empty and its length is zero. If you add three objects—a, b, and c—one at a time and in the order given, to the end of the list, the list will appear as a b c The object a is first, at position 1, b is at position 2, and c is last at position 3.1 To save space here, we will sometimes write a list’s contents on one...

  • JAVA - Circular Doubly Linked List Does anybody could help me with this method below(previous)? public...

    JAVA - Circular Doubly Linked List Does anybody could help me with this method below(previous)? public E previous() { // Returns the previous Element return null; } Explanation: We have this class with these two implemented inferfaces: The interfaces are: package edu.ics211.h04; /** * Interface for a List211. * * @author Cam Moore * @param the generic type of the Lists. */ public interface IList211 { /** * Gets the item at the given index. * @param index the index....

  • I need help with the Implementation of an Ordered List (Template Files) public interface Ordered...

    I need help with the Implementation of an Ordered List (Template Files) public interface OrderedStructure { public abstract int size(); public abstract boolean add( Comparable obj ) throws IllegalArgumentException; public abstract Object get( int pos ) throws IndexOutOfBoundsException; public abstract void remove( int pos ) throws IndexOutOfBoundsException; public abstract void merge( OrderedList other ); } import java.util.NoSuchElementException; public class OrderedList implements OrderedStructure { // Implementation of the doubly linked nodes (nested-class) private static class Node { private Comparable value; private...

  • please explain how to code using java -. Implement the ListNode and LinkedIntList as we did...

    please explain how to code using java -. Implement the ListNode and LinkedIntList as we did in class (you can add other methods if needed). You can reference the coxle in powerpoint slides of LinkedList and your textbook. 2. Implement a LinkedIntList class with the following public operations. a. add(int value) - Adds the given value to the end of the list b.get(int index) - Retums value in list at given index. C.add( int index, int value) - Inserts the...

  • Create a Java code that includes all the methods from the Lecture slides following the ADTs...

    Create a Java code that includes all the methods from the Lecture slides following the ADTs LECTURE SLIDE Collect/finish the Java code (interface and the complete working classes) from lecture slides for the following ADTS 2) ArrayList ADT that uses a linked list internally (call it LArrayList) Make sure you keep the same method names as in the slides (automatic testing will be performed)! For each method you develop, add comments and estimate the big-O running time of its algorithm....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT