Question

In: Computer Science

What is an array-based list? What is a resizable list? What is the difference between a...

What is an array-based list?


What is a resizable list?


What is the difference between a list’s capacity and its size?


When a list is expanded, is the size changed or is its capacity changed?

Solutions

Expert Solution

Answer:-

What is an array-based list?

The array-based list, also known as array list, is a resizable array implementation. Thus, as more elements are added to the linked list, its size increases dynamically. The array-based list assigns an element to the assigned array; however, if a new element is assigned some data, and there is no space in the array, then it allocates a new array, and moves all the data to the newly allocated array

What is a resizable list?

Resizable array" means that the size of the array can dynamically increase or decrease when you are adding or deleting elements to/from the array(in this case ArrayList). As opposed to the primitive arrays, ArrayList don't require you to specify the size of the data structure while creating an ArrayList object i.e. the ArrayList grows/shrink as you start adding/removing elements from the ArrayList.

For example

  • int[] a = new int[5];

The above line is an example of primitive array in which you have to specify the size of the array(in this case, 5) which means you can't resize the array.

  •    ArrayList<Integer> a = new ArrayList<Integer>()

           The above line is an example of an ArrayList object of type Integer. We haven't defined the size of the ArrayList while creating it, the ArrayList takes care of increasing/decreasing(resizing) the data structure and hence it is an resizable-array implementation.

What is the difference between a list’s capacity and its size?

The size of the list is the number of elements in it. The capacity of the list is the number of elements the backing data structure can hold at this time. The size will change as elements are added to or removed from the list. The capacity will change when the implementation of the list you're using needs it to. (The size, of course, will never be bigger than the capacity.)

(BTW, for fixed size containers the size is frequently called length, thus arrays have a property length and strings have a method length(). Different languages - sometimes even the same language - use "size" and "length" inconsistently, but they always mean size, and the term "capacity" is always used for the size/length of the underlying data structure.)

When a list is expanded, is the size changed or is its capacity changed?

capacity changed

why:-

Each ArrayList instance has a capacity. The capacity is the size of the array used to store the elements in the list. It is always at least as large as the list size. As elements are added to an ArrayList, its capacity grows automatically.

Also, for an ArrayList, size can not be set while initializing. However the initial capacity can be set. Size is the number of elements in the list


Related Solutions

Create a method that gets the difference for a linked bag and a resizable array: Also,...
Create a method that gets the difference for a linked bag and a resizable array: Also, implement the methods in the interface and test out that the program works in the main class //please comment what you are doing for the difference method for the linked bag and the array bag (also explain its time complexity in terms of Big O EX: Bag 1 has : ABC EX: Bag 2 has : ARC the difference is "R" BagInterface public boolean...
please do all parts a.For resizable array based implementation, what is the time complexity in the...
please do all parts a.For resizable array based implementation, what is the time complexity in the worst and base case scenario? Explain. b. For linked implementation of a list, what is the time complexity in the wort and best case scenario? Explain. remove(givenPosition: integer)
In C++ write an implementation of the ADT sorted list that uses a resizable array (vector...
In C++ write an implementation of the ADT sorted list that uses a resizable array (vector class of C++ STL) to represent the list items.
1. With respect to resizable arrays, establish the relationship between the size of the array and...
1. With respect to resizable arrays, establish the relationship between the size of the array and the time it takes to perform random access (read a the value stored at a given position somewhere in the array). Provide empirical evidence to support your answer.
Question: Write an implementation of the ADT sorted list that uses a resizable array (vector class...
Question: Write an implementation of the ADT sorted list that uses a resizable array (vector class of C++ STL) to represent the list items. Anytime the list becomes full, double the size of the array.
What is the difference between Array and Linkedlist. What is Array with example? What is Linkedlist...
What is the difference between Array and Linkedlist. What is Array with example? What is Linkedlist with example? What is the difference?
Explain the difference between array and structure based on their usage in C++ programming. Declare a...
Explain the difference between array and structure based on their usage in C++ programming. Declare a structure called studentScore which contains name of student, registration number of students, course code and marks. Declare structure variable named studentCS680 based on the structure in (b) to store fifty (50) students’ data. Write a program that prompts a user to enter data for 50 students in a structure variable declared in (b) and calculate the average mark.
Write an array-based implementation of the ADT list that expands the size of the array of...
Write an array-based implementation of the ADT list that expands the size of the array of list entries as needed so that the list can always accommodate a new entry. Also reduce the size of the array as needed to accommodate several removals. When the size of the array is greater than 20 and the number of entries in the list is less than half the size of the array, reduce the size of the array so that it is...
What is the difference between afferent and efferent neurons? List the 6 glial cells and list...
What is the difference between afferent and efferent neurons? List the 6 glial cells and list at least one function for each. Name two functions of Cerebrospinal Fluid (CSF). The modified blood vessels that are lined with ependymal cells and produce CSF are called ______. The spaces/chambers within the brain that allow CSF to flow internally are called ________. What are the differences between White matter and Gray matter? Which lobe of the cerebral cortex is responsible for voluntary motor...
what is the difference between asset backed and asset based and what is the consequences to...
what is the difference between asset backed and asset based and what is the consequences to the ownership if sukuk is default
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT