21 / 76
In special case, the time complexity of inserting/deleting elements at the end of dynamic array is __________
AO (1)
BO (n)
CO (n1/2)
DO (log n)
Answer: Option D
Explanation:In general, the time complexity of inserting or deleting elements at the end of dynamic array is O (1). Elements are added at reserved space of dynamic array. If this reserved space is exceeded, then the physical size of the dynamic array is reallocated and every element is copied from original array. This will take O(n) time to add new element at the end of the array.
Workspace
22 / 76
Which of the following arrays are used in the implementation of list data type in python?
AParallel arrays
BBit array
CDynamic arrays
DSparse arrays
Answer: Option C
Explanation:Dynamic arrays are used in the implementation of list data type in python. Sparse arrays are used in the implementation of sparse matrix in Numpy module. All bit array operations are implemented in bitarray module.
Workspace
23 / 76
What are parallel arrays?
AArrays allocated dynamically
BArrays of the same size
CArrays allocated one after the other
DArrays of the same number of elements
Answer: Option D
Explanation:Different arrays can be of different data types but should contain same number of elements. Elements at corresponding index belong to a record.
Workspace
24 / 76
What is a sparse array?
AAn array in which memory is allocated in run time
BData structure for representing arrays of records
CData structure that compactly stores bits
DAn array in which most of the elements have the same value
Answer: Option D
Explanation:They are set to a default value, usually 0 or null.
Workspace
25 / 76
When do you use a sparse array?
AWhen elements are sorted
BWhen there are unique elements in the array
CWhen the array has more occurrence of zero elements
DWhen the data type of elements differ
Answer: Option C
Explanation:It need not necessarily be zero, it could be any default value, usually zero or null.
Workspace
26 / 76
What is the difference between a normal(naive) array and a sparse array?
AA naive array is more efficient
BSparse array can hold more elements than a normal array
CSparse array is memory efficient
DSparse array is dynamic
Answer: Option C
Explanation:A naive implementation allocates space for the entire size of the array, whereas a sparse array(linked list implementation) allocates space only for the non-default values.
Workspace
27 / 76
Which of the following is a disadvantage of parallel array over the traditional arrays?
AInsertion and Deletion becomes tedious
BWhen a language does not support records, parallel arrays can be used
CIncreased locality of reference
DIdeal cache behaviour
Answer: Option A
Explanation:Insertion and deletion of elements require to move every element from their initial positions. This will become tedious. For Record collection, locality of reference and Ideal Cache behaviour we can use parallel arrays.
Workspace
28 / 76
Which of the following is an advantage of parallel arrays?
AIncreased Locality of Reference
BPoor locality of reference for non-sequential access
CVery little direct language support
DExpensive to shrink or grow
Answer: Option A
Explanation:Elements in the parallel array are accessed sequentially as one arrays holds the keys whereas other holds the values. This sequential access generally improves Locality of Reference. It is an advantage.
Workspace
29 / 76
Which of the following is not an application of sorted array?
AHash Tables
BCommercial computing
CPriority Scheduling
DDiscrete Mathematics
Answer: Option A
Explanation:Sorted arrays have widespread applications as all commercial computing involves large data which is very useful if it is sorted. It makes best use of locality of reference and data cache. Linked lists are used in Hash Tables not arrays.
Workspace
30 / 76
<b>I.</b> public void store(int index, Object val)
{
List cur = this;
List prev = null;
List node = new List(index);
node.val = val;
while (cur != null && prev.index < index)
{
cur = cur.next;
prev = cur;
}
if (cur == null)
{
prev.next = node;
}
else
{
if (cur.index == index)
{
System.out.println("DUPLICATE");
return;
}
prev.next = cur;
node.next = node;
}
return;
}
<b>II.</b> public void store(int index, Object val)
{
List cur = this;
List prev = null;
List node = new List(index);
node.val = val;
while (cur != null && cur.index < index)
{
prev = cur;
cur = cur.next;
}
if (cur == null)
{
prev.next = node;
} else
{
if (cur.index == index)
{
System.out.println("DUPLICATE");
return;
}
prev.next = node;
node.next = cur;
}
return;
}
<b>III.</b> public void store(int index, Object val)
{
List cur = this;
List prev = null;
List node = new List(index);
node.val = val;
while (prev != null && prev.index < index)
{
prev = cur;
cur = cur.next;
}
if (cur == null)
{
prev.next = node;
} else
{
if (cur.index == index)
{
System.out.println("DUPLICATE");
return;
}
prev.next = node;
node.next = cur;
}
return;
}
<b>IV.</b> public void store(int index, Object val)
{
List cur = this;
List prev = null;
List node = new List(index);
node.val = val;
while (cur != null && cur.index < index)
{
cur = cur.next;
prev = cur;
}
if (cur == null)
{
prev.next = node;
} else
{
if (cur.index == index)
{
System.out.println("DUPLICATE");
return;
}
prev.next = node;
node.next = cur;
}
return;
}
AI
BII
CIII
DIV
Answer: Option B
Explanation:Create a new node and traverse through the list until you reach the correct position, check for duplicate and nullity of the list and then insert the node.
Workspace
In this practice section, you can practice Data Structures Questions based on "Arrays" and improve your skills in order to face the interview, competitive examination, IT companies Written exam, and various other entrance tests (CAT, GATE, GRE, MAT, Bank Exam, Railway Exam etc.) with full confidence.
Q4Interview provides you lots of fully solved Data Structures (Arrays) questions and answers with Explanation. Solved examples with detailed answer description, explanation are given and it would be easy to understand. You can download Data Structures Arrays quiz questions with answers as PDF files and eBooks.
Here you can find objective type Data Structures Arrays questions and answers for interview and entrance examination. Multiple choice and true or false type questions are also provided.