21 / 68
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
22 / 68
I. 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;
}
II. 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;
}
III. 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;
}
IV. 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
23 / 68
I. public Object fetch(int index)
{
List cur = this.next;
Object val = null;
while (cur != null && cur.index != index)
{
cur = cur.index;
}
if (cur != null)
{
val = cur.val;
}
else
{
val = null;
}
return val;
}
II. public Object fetch(int index)
{
List cur = this.next;
Object val = null;
while (cur != null && cur.index != index)
{
cur = cur.next;
}
if (cur != null)
{
val = cur.val;
} else
{
val = null;
}
return val;
}
III. public Object fetch(int index)
{
List cur = this;
Object val = null;
while (cur != null && cur.index != index)
{
cur = cur.next;
}
if (cur != null)
{
val = cur.val;
} else
{
val = null;
}
return val;
}
IV. public Object fetch(int index)
{
List cur = this;
Object val = null;
while (cur != null && cur.index != index)
{
cur = cur.index;
}
if (cur != null)
{
val = cur.val;
} else
{
val = null;
}
return val;
}
AI
BII
CIII
DIV
Answer: Option C
Explanation:You travers through the array until the end is reached or the index is found and return the element at that index, null otherwise.
Workspace
24 / 68
Suppose the contents of an array A are, A = {1, null, null, null, null, 10};
What would be the size of the array considering it as a normal array and a sparse array?
A2 and 2
B6 and 6
C6 and 2
D2 and 6
Answer: Option C
Explanation:A normal array considers null also as an element, but in the sparse array only a non-zero or a non-null element is considered.
Workspace
25 / 68
What is sparsity of a matrix?
AThe fraction of total number of elements over the non-zero elements
BThe fraction of zero elements over the total number of elements
CThe fraction of non-zero elements over the total number of elements
DThe fraction of total number of elements over the zero elements
Answer: Option B
Explanation:Sparsity of a matrix is the fraction of number of zero elements over the total number of zero elements.
Workspace
26 / 68
I. public void store(int row_index, int col_index, Object val)
{
if (row_index < 0 && row_index > N)
{
System.out.println("column index out of bounds");
return;
}
if (col_index < 0 && col+index > N)
{
System.out.println("row index out of bounds");
return;
}
sparse_array[row_index].store(col_index, val);
}
II. public void store(int row_index, int col_index, Object val)
{
if (row_index < 0 || row_index > N)
{
System.out.println("row index out of bounds");
return;
}
if (col_index < 0 || col+index > N)
{
System.out.println("column index out of bounds");
return;
}
sparse_array[row_index].store(col_index, val);
}
III. public void store(int row_index, int col_index, Object val)
{
if (row_index < 0 || row_index > N)
{
System.out.println("column index out of bounds");
return;
}
if (col_index < 0 || col+index > N)
{
System.out.println("row index out of bounds");
return;
}
sparse_array[row_index].store(col_index, val);
}
IV. public void store(int row_index, int col_index, Object val)
{
if (row_index < 0 && row_index > N)
{
System.out.println("row index out of bounds");
return;
}
if (col_index < 0 && col+index > N)
{
System.out.println("column index out of bounds");
return;
}
sparse_array[row_index].store(col_index, val);
}
AI
BII
CIII
DIV
Answer: Option B
Explanation:Each row in a sparse matrix acts as a sparse array, hence this row with the specified col_index is the array and the specified position where the element is stored.
Workspace
27 / 68
Which of the following is the disadvantage of sparse matrices over normal matrices?
AAlgorithm complexity
BSize
CSpeed
DEasily compressible
Answer: Option A
Explanation:As the sparse matrix contains zeroes we will compute operations only on non zero values. This increases the complexity of algorithm as we need to identify index of zero elements first and during computation we should not take those index. It is a disadvantage. Sparse matrix is easily compressible by not storing the zero/null elements, they require less memory space, also only the non zero elements have to be computed, hence computational speed increases.
Workspace
28 / 68
Suffix array is space efficient and faster than the suffix tree.
ATRUE
BFALSE
Answer: Option B
Explanation:Suffix arrays are more space efficient than the suffix trees as they just store the original string and an array of integer. But working with suffix tree is faster than that of the suffix array.
Workspace
29 / 68
If comparison based sorting algorithm is used construct the suffix array, then what will be time required to construct the suffix array?
AO(n2) + O(logn)
BO(nlogn)
CO(n2)
DO(n2logn)
Answer: Option D
Explanation:On average comparison based sorting algorithms require O(nlogn) comparisons. But comparing a suffix takes O(n). So, overall time to construct the suffix array will be O(nlogn) * O(n) = O(n2logn).
Workspace
30 / 68
How many inversions does a sorted array have?
A1
B2
Ccannot be determined
Answer: Option A
Explanation:When an array is sorted then there cannot be any inversion in the array. As the necessary condition for an inversion is arr[i]>arr[j] and i
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.