Dynamic Array

Question 1
Marks : +2 | -2
Pass Ratio : 100%
What is the time complexity for inserting/deleting at the beginning of the array?
O(1)
O(n)
O(logn)
O(nlogn)
Explanation:
All the other elements will have to be moved, hence O(n).
Question 2
Marks : +2 | -2
Pass Ratio : 100%
The size of the dynamic array is deallocated if the array size is less than _________% of the backend physical size.
30
40
10
20
Explanation:
The size of the dynamic array is decreased/deallocated if the actual size of the array is less than 30% of the backend physical size. This is used to avoid memory wastage.
Question 3
Marks : +2 | -2
Pass Ratio : 100%
Which of the following is a disadvantage of dynamic arrays?
Locality of reference
Data cache utilization
Random access
Memory leak
Explanation:
Dynamic arrays share the advantage of arrays, added to it is the dynamic addition of elements to the array. Memory can be leaked if it is not handled properly during allocation and deallocation. It is a disadvantage.
Question 4
Marks : +2 | -2
Pass Ratio : 100%
Dynamic arrays overcome the limit of static arrays.
True
False
Explanation:
Static arrays have fixed capacity. The capacity must be specified during memory allocation. Dynamic arrays don’t require to specify their capacity during memory allocation. Dynamic arrays have fixed physical size at backend and its capacity increases if required. Thus, Dynamic arrays overcome the limit of static arrays.
Question 5
Marks : +2 | -2
Pass Ratio : 100%
What is a dynamic array?
A variable size data structure
An array which is created at runtime
The memory to the array is allocated at runtime
An array which is reallocated everytime whenever new elements have to be added
Explanation:
It is a varying-size list data structure that allows items to be added or removed, it may use a fixed sized array at the back end.
Question 6
Marks : +2 | -2
Pass Ratio : 100%
Which of the following is the correct syntax to declare an ArrayList in Java?
ArrayList al = new ArrayList();
ArrayList al = new ArrayList[];
ArrayList al() = new ArrayList();
ArrayList al[] = new ArrayList[];
Explanation:
This is a non-generic way of creating an ArrayList.
Question 7
Marks : +2 | -2
Pass Ratio : 100%
The number of items used by the dynamic array contents is its __________
Physical size
Capacity
Logical size
Random size
Explanation:
The number of items used by the dynamic array contents is called logical size. Physical size is the size of the underlying array, which is the maximum size without reallocation of data.
Question 8
Marks : +2 | -2
Pass Ratio : 100%
How will you implement dynamic arrays in Java?
Set
Map
HashMap
List
Explanation:
ArrayList is used to implement dynamic arrays in Java.
Question 9
Marks : +2 | -2
Pass Ratio : 100%
Array is divided into two parts in ____________
Hashed Array Tree
Geometric Array
Bounded-size dynamic array
Sparse Array
Explanation:
The first part stores the items of the dynamic array and the second part is reserved for new allocations.
Question 10
Marks : +2 | -2
Pass Ratio : 100%
What is meant by physical size in a dynamic array?
The size allocated to elements
The size extended to add new elements
The size of the underlying array at the back-end
The size visible to users
Explanation:
Physical size, also called array capacity is the size of the underlying array, which is the maximum size without relocation of data.