31 / 76
<b>I.</b> 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;
}
<b>II.</b> 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;
}
<b>III.</b> 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;
}
<b>IV.</b> 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
32 / 76
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
33 / 76
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
34 / 76
<b>I.</b> 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);
}
<b>II.</b> 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);
}
<b>III.</b> 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);
}
<b>IV.</b> 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
35 / 76
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
36 / 76
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
37 / 76
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
38 / 76
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
39 / 76
Choose the correct function from the following which determines the number of inversions in an array?
<b>I.</b> int InvCount(int arr[], int n)
{
int count = 0;
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (arr[i] < arr[j])
count++;
return count + 1;
}
<b>II.</b> int InvCount(int arr[], int n)
{
int count = 0;
for (int i = 0; i < n - 1; i++)
for (int j = i ; j < n; j++)
if (arr[i] >= arr[j])
count++;
return count;
}
<b>III.</b> int InvCount(int arr[], int n)
{
int count = 0;
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (arr[i] > arr[j])
count++;
return count;
}
<b>IV.</b> int InvCount(int arr[], int n)
{
int count = 0;
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (arr[i] > arr[j])
count++;
return count + 1;
}
AI
BII
CIII
DIV
Answer: Option C
Explanation:To determine the number of inversions we apply a nested loop and compare the value of each element with all the elements present after it. Then the count of number of inversions is counted and returned to the main function.
Workspace
40 / 76
What will be the suffix array of the string “engineering”?
A5 0 6 10 2 3 8 4 9 1 7
B2 3 8 4 9 1 7 5 0 6 10
C5 0 6 1 4 9 1 7 0 2 3 8
D5 0 6 10 2 4 9 1 7 3 8
Answer: Option A
Explanation:Correct choice is : 5 0 6 10 2 3 8 4 9 1 7.
Because the suffix array formed will be: 5 eering 0 engineering 6 ering 10 g 2 gineering 3 ineering 8 ing 4 neering 9 ng 1 ngineering 7 ring.
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.