Arrays In Data Structures
Name: _____________________
Date: _____________________
Instructions: Answer all questions. Write your answers clearly in the space provided.
Which of the following data structures is best suited for implementing an array list in Java?
How do you find the maximum element in an array in Python?
What happens when you access an array element out of bounds in C++?
How do you copy an array in C++?
Which matrix has most of the elements (not all) as Zero?
It is not possible to find the minimum number of steps to reach the end of an array in linear time.
If column-major order is used, how is the following matrix stored in memory? a b c d e f g h i
What is the time complexity of the juggling algorithm to rotate an array?
Which of the following don't use matrices?
How many swaps are required for reversing an array having n elements where n is an odd number?
What is the space complexity of the code that uses merge sort for determining the number of inversions in an array?
What will be the auxiliary space complexity of the code to rotate an array by using the reversal algorithm (d = number of rotations)?
What is the time complexity of the code that uses self balancing BST for determining the number of inversions in an array?
Array is divided into two parts in . . . . . . . .
To search for an element in a sorted array, which searching technique can be used?
Run-Length encoding is used to compress data in bit arrays.
In how many different ways we can reach the end of the array arr[]={1,3,5,8,9}?
In special case, the time complexity of inserting/deleting elements at the end of dynamic array is . . . . . . . .
Suffix array can be created by performing . . . . . . . . traversal of a suffix tree.
If comparison based sorting algorithm is used construct the suffix array, then what will be time required to construct the suffix array?
Which of the following is/are advantages suffix array one suffix tree? I. Lesser space requirement II. Improved cache locality III. Easy construction in linear time
Which of the following bitwise operations will you use to toggle a particular bit?
Which of the following is a disadvantage of dynamic arrays?
Which of the following is/are not applications of bit arrays?
Under what condition the number of inversions in an array are maximum?
It is not possible to reach the end of an array if starting element of the array is 0.
Which of the following is an advantage of using variable-length arrays?
Which of the following is not the method to represent Sparse Matrix?
What is the condition for two elements arr[i] and arr[j] to form an inversion?
When array reversal and rotation is applied to the same array then the output produced will also be the same every time.
Which one of the following operations returns the first occurrence of bit 1 in bit arrays?
How do you access the last element of an array in JavaScript?
What is the time complexity of merging two sorted arrays?
Which of the following statements is true about dynamic arrays?
In which language do arrays have a fixed size and cannot be resized?
Which function is used to sort an array in C++?
How do you reverse an array in Java?
What is the best way to find the largest element in an unsorted array?
How many swaps are required for reversing an array having n elements where n is an even number?
Suffix array is space efficient than the suffix tree.
Predefined function reverse() in C++ is available under which header file?
Which of the following is a disadvantage of parallel array over the traditional arrays?
What will be the resulting array after rotating arr[]={1, 2, 3, 4, 5} by 2?
Which of the following bitwise operator will you use to invert all the bits in a bit array?
In which of the following cases dynamic arrays are not preferred?
What will be the minimum number of jumps required to reach the end of the array arr[] ={0,1,3,6,3,6,8,5}?
What is the order of a matrix?
Reversal algorithm and juggling algorithm for array rotation have the same time complexity.
How many arguments are required by the predefined function rotate() in C++?
Who coined the term Sparse Matrix?
What is the relation between Sparsity and Density of a matrix?
Arbitrary expressions can be used while declaring variable-length arrays.
How many inversions does a sorted array have?
Which of the following can be called a parallel array implementation?
Which of the following is the disadvantage of sparse matrices over normal matrices?
Which of the following is a method to find the length of an array in C++?
Which of the following is true about array-based lists?
In which scenario would you prefer to use an array over a linked list?
What is the correct syntax to access the third element of an array in C?
Which of the following languages does not support multidimensional arrays directly?
What is a jagged array in C#?
Which method is used to sort an array in Python?
What is the time complexity of accessing an element in an array by index?
What is the default value of an integer array in Java?
What is the time complexity of inserting an element at the end of an array?
Which of the following statements is true about arrays?
What is a multidimensional array?
How are elements stored in a 2D array in memory?
What is the correct way to access the third element of an array?
Which of the following methods can be used to copy an array in Java?
What is the time complexity of searching for an element in an unsorted array?
Which of the following is a disadvantage of arrays?
How do you declare a 2D array in Python?
What is the advantage of using arrays over linked lists?
What is the time complexity of deleting an element from an array?
Which of the following is true about array indexes?
What is the correct way to initialize an array of size 5 in Python?
How can you pass an array to a function in C?
Which of the following is an advantage of using arrays?
Predefined function rotate() in C++ is available under which header file?
Which among the following is the worst-case time complexity for appending an element in a variable-length array?
Which of the following is not an advantage of bit array?
Suffix array can be created in O(nlogn) time.
What is the time required to locate the occurrences of a pattern P of length m in a string of length n using suffix array?
How many inversions are there in the array arr = {1,5,4,2,3}?
Bit fields and Bit arrays are same.
What will be the resulting array after reversing arr[]={3,5,4,2}?
What is a sparse array?
How will you implement dynamic arrays in Java?
Which of the following bitwise operations will you use to set a particular bit to 0?
Which of the following arrays are used in the implementation of list data type in python?
In what way the Symmetry Sparse Matrix can be stored efficiently?
What is the time complexity of the code that uses merge sort for determining the number of inversions in an array?
The number of items used by the dynamic array contents is its . . . . . . . .
Matrix A when multiplied with Matrix C gives the Identity matrix I, what is C?
What is meant by physical size in a dynamic array?
What is the difference between a normal(naive) array and a sparse array?
What will be the minimum number of jumps required to reach the end of the array arr[] = {1,2,0,0,3,6,8,5}?
Which one of the following is a Special Sparse Matrix?
The time complexity of the code that determines the number of inversions in an array using self balancing BST is lesser than that of the code that uses loops for the same purpose.
What does the number of inversions in an array indicate?
Which of the following is the predefined function for array reversal in C++ ?
LCP array and . . . . . . . . is used to construct suffix tree.
The size of the dynamic array is deallocated if the array size is less than . . . . . . . .% of the backend physical size.
If row-major order is used, how is the following matrix stored in memory? a b c d e f g h i
Which of the following property does not hold for matrix multiplication?
What is a dynamic array?
Is O(n) the Worst case Time Complexity for addition of two Sparse Matrix?
The growth factor of ArrayList in Java is . . . . . . . .
To rotate an array by using the algorithm of rotating its elements one by one is an in place algorithm.
What is a sorted array?
When do you use a sparse array?
What is the minimum possible time complexity to find the number of steps to reach the end of an array?
Under what condition the number of inversions in an array are minimum?
What does Hamming weight/population count mean in Bit arrays?
Dynamic arrays overcome the limit of static arrays.
Is Sparse Matrix also known as Dense Matrix?
What will be the suffix array of the string "engineering"?
Where does the GNU C compiler allocates memory for variable-length arrays?
Which of the following is not an application of sorted array?
What is a bit array?
Which of the following bitwise operations will you use to set a particular bit to 1?
What are parallel arrays?
Which of the following is an advantage of parallel arrays?
Which of the following is an advantage of matrices?
Which of the following is not a disadvantage of bit array?
What is sparsity of a matrix?
Which class in Java can be used to represent bit array?
What will be the minimum number of jumps required to reach the end of the array arr[] = {1,3,6,3,6,8,5}?
The time complexity of the code that determines the number of inversions in an array using merge sort is lesser than that of the code that uses loops for the same purpose.
Which of the following form inversion in the array arr = {1,5,4,2}?
What is the time complexity for inserting/deleting at the beginning of the array?
What is the worst case time complexity of inserting an element into the sorted array?
Which of the following algorithm to rotate an array has the maximum time complexity?
Which of the following is false?
Suffix array of the string "statistics" is . . . . . . . .
The matrix contains m rows and n columns. The matrix is called Sparse Matrix if . . . . . . . .
Both Dynamic array and Dynamically memory allocated array are same.
Consider the following piece of code in C++. What does the following code implement? #include <iostream>
using namespace std
int main()
{
int *arr_vla
int size
cout<<"Enter the size of variable length array: "
cin>>size
arr_vla = new int [size]
for (int i = 0
i < size
i++)
{
cout<<"Enter the integers to be inserted in the variable length array: "
cin>>arr_vla[i]
}
for(int i = 0
i < size
i++)
{
cout<<arr_vla[i]<<" "
}
cout<<endl
return 0
}
What will be the time complexity of the following code? #include <iostream>
using namespace std
int main()
{
int arr[] = {1,2,3,4,5,6}
int n = sizeof(arr)/sizeof(arr[0])
int d=4
int temp[10]
for(int i=0
i<d
i++)
temp[i]=arr[i]
int j=0
for(int i=d
i<n
i++,j++)
arr[j]=arr[i]
int k=0
for(int i=n-d
i<n
i++,k++)
arr[i]=temp[k]
for(int i=0
i<n
i++)
cout<<arr[i]<<" "
return 0
}
What will be the output of the following code? #include <bits/stdc++.h>
using namespace std
void func1(int arr[], int n)
{
int k = arr[0], i
for (i = 0
i < n - 1
i++)
arr[i] = arr[i + 1]
arr[i] = k
}
void func(int arr[], int d, int n)
{
for (int i = 0
i < d
i++)
func1(arr, n)
}
void printArray(int arr[], int n)
{
for (int i = 0
i < n
i++)
cout << arr[i] << " "
}
int main()
{
int arr[] = { 1, 2, 3, 4, 5}
int n = sizeof(arr) / sizeof(arr[0])
func(arr, 3, n)
printArray(arr, n)
return 0
}
What will be the output of the following code? #include <bits/stdc++.h>
using namespace std
void func(int a[], int n, int k)
{
if (k <= n)
{
for (int i = 0
i < k/2
i++)
swap(a[i], a[k-i-1])
}
}
int main()
{
int a[] = {1, 2, 3, 4, 5}
int n = sizeof(a) / sizeof(int), k = 3
func(a, n, k)
for (int i = 0
i < n
++i)
cout << a[i]<<" "
return 0
}
What will be the output of the following code? #include <bits/stdc++.h>
using namespace std
void func1(int arr[], int left, int right)
{
while (left < right)
{
int temp = arr[left]
arr[left] = arr[right]
arr[right] = temp
left++
right--
}
}
void func(int arr[], int d, int n)
{
func1(arr, 0, d-1)
func1(arr, d, n-1)
func1(arr, 0, n-1)
}
void printArray(int arr[], int size)
{
for (int i = 0
i < size
i++)
cout << arr[i] << " "
}
int main()
{
int arr[] = {1, 2, 3, 4, 5}
int n = sizeof(arr)/sizeof(arr[0])
int d = 2
func(arr, d, n)
printArray(arr, n)
return 0
}
Which of the following is the correct syntax to declare an ArrayList in Java?
What does the following piece of code do? for(int i = 0
i < row
i++)
{
for(int j = 0
j < column
j++)
{
if(i == j)
sum = sum + (array[i][j])
}
}
System.out.println(sum)
What will be the auxiliary space complexity of the following code? #include <iostream>
using namespace std
int main()
{
int arr[] = {1,2,3,4,5,6}
int n = sizeof(arr)/sizeof(arr[0])
int d=4
int temp[10]
for(int i=0
i<d
i++)
temp[i]=arr[i]
int j=0
for(int i=d
i<n
i++,j++)
arr[j]=arr[i]
int k=0
for(int i=n-d
i<n
i++,k++)
arr[i]=temp[k]
for(int i=0
i<n
i++)
cout<<arr[i]<<" "
return 0
}
What will be the time complexity of the following code? #include <bits/stdc++.h>
using namespace std
void func1(int arr[], int n)
{
int k = arr[0], i
for (i = 0
i < n - 1
i++)
arr[i] = arr[i + 1]
arr[i] = k
}
void func(int arr[], int d, int n)
{
for (int i = 0
i < d
i++)
func1(arr, n)
}
void printArray(int arr[], int n)
{
for (int i = 0
i < n
i++)
cout << arr[i] << " "
}
int main()
{
int arr[] = { 1, 2, 3, 4, 5}
int n = sizeof(arr) / sizeof(arr[0])
int d = 3
func(arr, d, n)
printArray(arr, n)
return 0
}
What will be the worst case time complexity of the following code? #include <bits/stdc++.h>
using namespace std
void func(int arr[], int n)
{
int count[n]
memset(count, 0, sizeof(count))
for (int i=n-2
i>=0
i--)
{
if (arr[i] >= n - i - 1)
count[i]++
for (int j=i+1
j < n-1 && j <= arr[i] + i
j++)
if (count[j] != -1)
count[i] += count[j]
if (count[i] == 0)
count[i] = -1
}
for (int i=0
i<n
i++)
cout << count[i] << " "
}
int main()
{
int arr[] = {1, 3, 5, 8, 9}
int n = sizeof(arr) / sizeof(arr[0])
func(arr, n)
return 0
}
Select the code snippet which performs matrix multiplication.(a and b are the two given matrices, resultant marix is c)
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?
What will be the output of the following code? #include <bits/stdc++.h>
using namespace std
int func(int arr[], int s, int e)
{
if (s == e)
return 0
if (arr[s] == 0)
return INT_MAX
int min = INT_MAX
for (int i = s + 1
i <= e && i <= s + arr[s]
i++)
{
int jumps = func(arr, i, e)
if(jumps != INT_MAX && jumps + 1 < min)
min = jumps + 1
}
return min
}
int main()
{
int arr[] = {1, 3, 6, 3, 8, 5}
int n = sizeof(arr)/sizeof(arr[0])
cout << func(arr, 0, n-1)
return 0
}
What will be the output of the following code? #include <bits/stdc++.h>
using namespace std
void func(int arr[], int left, int right)
{
while (left < right)
{
int temp = arr[left]
arr[left] = arr[right]
arr[right] = temp
left++
right--
}
}
void printArray(int arr[], int size)
{
for (int i = 0
i < size
i++)
cout << arr[i] << " "
}
int main()
{
int arr[] = {1,4,3,5}
int n = sizeof(arr) / sizeof(arr[0])
func(arr, 0, n-1)
printArray(arr, n)
return 0
}
Which of the following is the correct way to declare an array in C?
How do you find the length of an array in Java?
Which of the following correctly initializes an array in C++?
What will be the time complexity of the following code? #include <bits/stdc++.h>
using namespace std
void func(int a[], int n, int k)
{
if (k <= n)
{
for (int i = 0
i < k/2
i++)
swap(a[i], a[k-i-1])
}
}
int main()
{
int a[] = {1, 2, 3, 4, 5}
int n = sizeof(a) / sizeof(int), k = 3
func(a, n, k)
for (int i = 0
i < n
++i)
cout << a[i]<<" "
return 0
}
What is the functionality of the following piece of code? public Object function(int row_index, int col_index)
{
if (row_index < 0 || col_index > N)
{
System.out.println("column index out of bounds")
return
}
return (sparse_array[row_index].fetch(col_index))
}
What will be the time complexity of the following code? #include <bits/stdc++.h>
using namespace std
int min(int x, int y)
{ return (x < y)? x: y
}
int func(int arr[], int n)
{
int *jump = new int[n]
int i, j
if (n == 0 || arr[0] == 0)
return INT_MAX
jump[0] = 0
for (i = 1
i < n
i++)
{
jump[i] = INT_MAX
for (j = 0
j < i
j++)
{
if (i <= j + arr[j] && jumps[j] != INT_MAX)
{
jump[i] = min(jump[i], jump[j] + 1)
break
}
}
}
return jump[n-1]
}
int main()
{
int arr[] = {1, 3, 6, 1, 9,7}
int size = sizeof(arr)/sizeof(int)
cout<< func(arr,size)
return 0
}
What is the output of the following C code: int array[5] = {1, 2, 3, 4, 5}
printf("%d", array[2])
How do you dynamically allocate an array in C++?
Which of the following is the correct way to declare a 3D array in Java?
Consider the following piece of code in C++, how many elements will be stored in the array 'arr' if the user enters the values of a, b, c and d as 10, 20, 30, and 40 respectively? #include<iostream>
using namespace std
int main()
{
int a, b, c, d
cout<<”Enter the value of a, b, c, d: “
cin>>a>>b>>c>>d
int arr[a - b/c + d]
}
What will be the output of the following code? #include <iostream>
using namespace std
int main()
{
int arr[] = {1,2,3,4,5,6}
int n = sizeof(arr)/sizeof(arr[0])
int d=4
int temp[10]
for(int i=0
i<d
i++)
temp[i]=arr[i]
int j=0
for(int i=d
i<n
i++,j++)
arr[j]=arr[i]
int k=0
for(int i=n-d
i<n
i++,k++)
arr[i]=temp[k]
for(int i=0
i<n
i++)
cout<<arr[i]<<" "
return 0
}
What will be the time complexity of the following code? #include <bits/stdc++.h>
using namespace std
void func(int arr[], int left, int right)
{
while (left < right)
{
int temp = arr[left]
arr[left] = arr[right]
arr[right] = temp
left++
right--
}
}
void printArray(int arr[], int size)
{
for (int i = 0
i < size
i++)
cout << arr[i] << " "
}
int main()
{
int arr[] = {1,4,3,5}
int n = sizeof(arr) / sizeof(arr[0])
func(arr, 0, n-1)
printArray(arr, n)
return 0
}
What is the output of the following Python code: array = [1, 2, 3]
print(array[-1])
How do you initialize an array in Java with specific values?
How do you remove an element from an array in JavaScript?
Which of the following is a correct way to declare a constant array in JavaScript?
What is the time complexity of the following code that determines the number of inversions in an array? 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
}
What will be the output of the following code? #include <bits/stdc++.h>
using namespace std
void func(int arr[], int n)
{
int count[n]
memset(count, 0, sizeof(count))
for (int i=n-2
i>=0
i--)
{
if (arr[i] >= n - i - 1)
count[i]++
for (int j=i+1
j < n-1 && j <= arr[i] + i
j++)
if (count[j] != -1)
count[i] += count[j]
if (count[i] == 0)
count[i] = -1
}
for (int i=0
i<n
i++)
cout << count[i] << " "
}
int main()
{
int arr[] = {1, 3, 5, 8, 9}
int n = sizeof(arr) / sizeof(arr[0])
func(arr, n)
return 0
}
What will be the time complexity of the following code? #include <bits/stdc++.h>
using namespace std
void func(int arr[], int left, int right)
{
if (left >= right)
return
int temp = arr[left]
arr[left] = arr[right]
arr[right] = temp
func(arr, left + 1, right - 1)
}
void printArray(int arr[], int size)
{
for (int i = 0
i < size
i++)
cout << arr[i] << " "
}
int main()
{
int arr[] = {1,2,3,4}
int n = sizeof(arr) / sizeof(arr[0])
func(arr, 0, n-1)
printArray(arr, n)
return 0
}
Choose the appropriate code that counts the number of non-zero(non-null) elements in the sparse array.
What will be the auxiliary space requirement of the following code? #include <bits/stdc++.h>
using namespace std
void func(int arr[], int left, int right)
{
while (left < right)
{
int temp = arr[left]
arr[left] = arr[right]
arr[right] = temp
left++
right--
}
}
void printArray(int arr[], int size)
{
for (int i = 0
i < size
i++)
cout << arr[i] << " "
}
int main()
{
int arr[] = {1,4,3,5}
int n = sizeof(arr) / sizeof(arr[0])
func(arr, 0, n-1)
printArray(arr, n)
return 0
}
What will be the auxiliary space complexity of the following code? #include <bits/stdc++.h>
using namespace std
void func1(int arr[], int n)
{
int k = arr[0], i
for (i = 0
i < n - 1
i++)
arr[i] = arr[i + 1]
arr[i] = k
}
void func(int arr[], int d, int n)
{
for (int i = 0
i < d
i++)
func1(arr, n)
}
void printArray(int arr[], int n)
{
for (int i = 0
i < n
i++)
cout << arr[i] << " "
}
int main()
{
int arr[] = { 1, 2, 3, 4, 5}
int n = sizeof(arr) / sizeof(arr[0])
int d = 3
func(arr, d, n)
printArray(arr, n)
return 0
}
How do you allocate a matrix using a single pointer in C?(r and c are the number of rows and columns respectively)
What will be the output of the following code ? #include <bits/stdc++.h>
using namespace std
void func(int arr[], int left, int right)
{
if (left >= right)
return
int temp = arr[left]
arr[left] = arr[right]
arr[right] = temp
func(arr, left + 1, right - 1)
}
void printArray(int arr[], int size)
{
for (int i = 0
i < size
i++)
cout << arr[i] << " "
}
int main()
{
int arr[] = {1,2,3,4}
int n = sizeof(arr) / sizeof(arr[0])
func(arr, 0, n-1)
printArray(arr, n)
return 0
}