Arrays In Data Structures

Name: _____________________

Date: _____________________

Instructions: Answer all questions. Write your answers clearly in the space provided.

Question 1:

Which of the following data structures is best suited for implementing an array list in Java?

A. ArrayList
B. LinkedList
C. Stack
D. Queue
Answer: _________
Question 2:

How do you find the maximum element in an array in Python?

A. max(array)
B. array.max()
C. max(array[])
D. array.maximum()
Answer: _________
Question 3:

What happens when you access an array element out of bounds in C++?

A. The program crashes
B. The compiler throws an error
C. The runtime throws an error
D. Undefined behavior
Answer: _________
Question 4:

How do you copy an array in C++?

A. std::copy
B. copyArray
C. memcpy
D. copy()
Answer: _________
Question 5:

Which matrix has most of the elements (not all) as Zero?

A. Identity Matrix
B. Unit Matrix
C. Sparse Matrix
D. Zero Matrix
Answer: _________
Question 6:

It is not possible to find the minimum number of steps to reach the end of an array in linear time.

A. true
B. false
Answer: _________
Question 7:

If column-major order is used, how is the following matrix stored in memory? a b c d e f g h i

A. ihgfedcba
B. abcdefghi
C. cfibehadg
D. adgbehcfi
Answer: _________
Question 8:

What is the time complexity of the juggling algorithm to rotate an array?

A. O(1)
B. O(n)
C. O(d)
D. O(n*d)
Answer: _________
Question 9:

Which of the following don't use matrices?

A. In solving linear equations
B. Image processing
C. Graph theory
D. Sorting numbers
Answer: _________
Question 10:

How many swaps are required for reversing an array having n elements where n is an odd number?

A. (n-1) / 2
B. n/2
C. (n/2) - 1
D. (n+1)/2
Answer: _________
Question 11:

What is the space complexity of the code that uses merge sort for determining the number of inversions in an array?

A. O(n)
B. O(log n)
C. O(1)
D. O(n log n)
Answer: _________
Question 12:

What will be the auxiliary space complexity of the code to rotate an array by using the reversal algorithm (d = number of rotations)?

A. O(1)
B. O(n)
C. O(d)
D. O(n*d)
Answer: _________
Question 13:

What is the time complexity of the code that uses self balancing BST for determining the number of inversions in an array?

A. O(n 2 )
B. O(n)
C. O(log n)
D. O(n log n)
Answer: _________
Question 14:

Array is divided into two parts in . . . . . . . .

A. Hashed Array Tree
B. Geometric Array
C. Bounded-size dynamic array
D. Sparse Array
Answer: _________
Question 15:

To search for an element in a sorted array, which searching technique can be used?

A. Linear Search
B. Jump Search
C. Binary Search
D. Fibonacci Search
Answer: _________
Question 16:

Run-Length encoding is used to compress data in bit arrays.

A. True
B. False
Answer: _________
Question 17:

In how many different ways we can reach the end of the array arr[]={1,3,5,8,9}?

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 18:

In special case, the time complexity of inserting/deleting elements at the end of dynamic array is . . . . . . . .

A. O (n)
B. O (n 1/2 )
C. O (log n)
D. O (1)
Answer: _________
Question 19:

Suffix array can be created by performing . . . . . . . . traversal of a suffix tree.

A. breadth-first
B. level order
C. depth-first
D. either breadth-first or level order
Answer: _________
Question 20:

If comparison based sorting algorithm is used construct the suffix array, then what will be time required to construct the suffix array?

A. O(nlogn)
B. O(n 2 )
C. O(n 2 logn)
D. O(n 2 ) + O(logn)
Answer: _________
Question 21:

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

A. Only I
B. All I, II and III
C. Only I and III
D. Only II and III
Answer: _________
Question 22:

Which of the following bitwise operations will you use to toggle a particular bit?

A. OR
B. AND
C. XOR
D. NOT
Answer: _________
Question 23:

Which of the following is a disadvantage of dynamic arrays?

A. Locality of reference
B. Data cache utilization
C. Random access
D. Memory leak
Answer: _________
Question 24:

Which of the following is/are not applications of bit arrays?

A. Used by the Linux kernel
B. For the allocation of memory pages
C. Bloom filter
D. Implementation of Vectors and Matrices
Answer: _________
Question 25:

Under what condition the number of inversions in an array are maximum?

A. when the array is sorted
B. when the array is reverse sorted
C. when the array is half sorted
D. depends on the given array
Answer: _________
Question 26:

It is not possible to reach the end of an array if starting element of the array is 0.

A. true
B. false
Answer: _________
Question 27:

Which of the following is an advantage of using variable-length arrays?

A. Deciding the length of an array at the time of execution
B. Memory allocation at compile time
C. Initializing array at compile time
D. Faster execution of code
Answer: _________
Question 28:

Which of the following is not the method to represent Sparse Matrix?

A. Dictionary of Keys
B. Linked List
C. Array
D. Heap
Answer: _________
Question 29:

What is the condition for two elements arr[i] and arr[j] to form an inversion?

A. arr[i]<arr[j]
B. i < j
C. arr[i] < arr[j] and i < j
D. arr[i] > arr[j] and i < j
Answer: _________
Question 30:

When array reversal and rotation is applied to the same array then the output produced will also be the same every time.

A. true
B. false
Answer: _________
Question 31:

Which one of the following operations returns the first occurrence of bit 1 in bit arrays?

A. Find First Zero
B. Find First One
C. Counting lead Zeroes
D. Counting lead One
Answer: _________
Question 32:

How do you access the last element of an array in JavaScript?

A. array[length]
B. array[-1]
C. array[array.length - 1]
D. array.getLast()
Answer: _________
Question 33:

What is the time complexity of merging two sorted arrays?

A. O(n)
B. O(n log n)
C. O(n 2 )
D. O(m + n)
Answer: _________
Question 34:

Which of the following statements is true about dynamic arrays?

A. They have a fixed size
B. They can change size during runtime
C. They do not allow random access
D. They are implemented using linked lists
Answer: _________
Question 35:

In which language do arrays have a fixed size and cannot be resized?

A. Java
B. Python
C. JavaScript
D. C
Answer: _________
Question 36:

Which function is used to sort an array in C++?

A. sortArray()
B. qsort()
C. sort()
D. array_sort()
Answer: _________
Question 37:

How do you reverse an array in Java?

A. Collections.reverse(array)
B. array.reverse()
C. Arrays.reverse(array)
D. ArrayUtils.reverse(array)
Answer: _________
Question 38:

What is the best way to find the largest element in an unsorted array?

A. Sort the array and pick the first element
B. Iterate through the array and track the largest element
C. Use a binary search
D. Use a hash table
Answer: _________
Question 39:

How many swaps are required for reversing an array having n elements where n is an even number?

A. (n-1) / 2
B. n/2
C. (n/2) - 1
D. (n+1)/2
Answer: _________
Question 40:

Suffix array is space efficient than the suffix tree.

A. True
B. Fasle
Answer: _________
Question 41:

Predefined function reverse() in C++ is available under which header file?

A. math
B. stdio
C. stdlib
D. algorithm
Answer: _________
Question 42:

Which of the following is a disadvantage of parallel array over the traditional arrays?

A. When a language does not support records, parallel arrays can be used
B. Increased locality of reference
C. Ideal cache behaviour
D. Insertion and Deletion becomes tedious
Answer: _________
Question 43:

What will be the resulting array after rotating arr[]={1, 2, 3, 4, 5} by 2?

A. 2, 1, 3, 4, 5
B. 3, 4, 5, 1, 2
C. 4, 5, 1, 2, 3
D. 1, 2, 3, 5, 4
Answer: _________
Question 44:

Which of the following bitwise operator will you use to invert all the bits in a bit array?

A. OR
B. NOT
C. XOR
D. NAND
Answer: _________
Question 45:

In which of the following cases dynamic arrays are not preferred?

A. If the size of the array is unknown
B. If the size of the array changes after few iterations
C. If the memory reallocation takes more time i.e. expensive
D. If the array holds less number of elements
Answer: _________
Question 46:

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}?

A. 1
B. 2
C. 3
D. not possible to reach the end
Answer: _________
Question 47:

What is the order of a matrix?

A. number of rows X number of columns
B. number of columns X number of rows
C. number of rows X number of rows
D. number of columns X number of columns
Answer: _________
Question 48:

Reversal algorithm and juggling algorithm for array rotation have the same time complexity.

A. True
B. False
Answer: _________
Question 49:

How many arguments are required by the predefined function rotate() in C++?

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 50:

Who coined the term Sparse Matrix?

A. Harry Markowitz
B. James Sylvester
C. Chris Messina
D. Arthur Cayley
Answer: _________
Question 51:

What is the relation between Sparsity and Density of a matrix?

A. Sparsity = 1 - Density
B. Sparsity = 1 + Density
C. Sparsity = Density*Total number of elements
D. Sparsity = Density/Total number of elements
Answer: _________
Question 52:

Arbitrary expressions can be used while declaring variable-length arrays.

A. True
B. False
Answer: _________
Question 53:

How many inversions does a sorted array have?

A. 0
B. 1
C. 2
D. cannot be determined
Answer: _________
Question 54:

Which of the following can be called a parallel array implementation?

A. firstName = ['Joe','Bob','Frank','Hans'] lastName = ['Smith','Seger','Sinatra','Schultze'] heightInCM = [169,158,201,199] for i in xrange(len(firstName)): print "Name:",firstName[i], lastName[i] print "Height in CM:,",heightInCM[i]
B. firstName = ['Joe','Bob','Frank','Hans'] lastName = ['Smith','Seger'] heightInCM = [169,158] for i in xrange(len(firstName)): print "Name:",firstName[i], lastName[i] print "Height in CM:,",heightInCM[i]
C. firstName = ['Joe','Bob'] lastName = ['Smith','Seger','Sinatra','Schultze'] heightInCM = [169,158] for i in xrange(len(firstName)): print "Name:",firstName[i], lastName[i] print "Height in CM:,",heightInCM[i]
D. firstName = ['Joe','Bob'] lastName = ['Smith','Seger' ,'Schultze'] heightInCM = [169,158] for i in xrange(len(firstName)): print "Name:",firstName[i], lastName[i] print "Height in CM:,",heightInCM[i]
Answer: _________
Question 55:

Which of the following is the disadvantage of sparse matrices over normal matrices?

A. Size
B. Speed
C. Easily compressible
D. Algorithm complexity
Answer: _________
Question 56:

Which of the following is a method to find the length of an array in C++?

A. size()
B. length()
C. sizeof(array)/sizeof(array[0])
D. array.size()
Answer: _________
Question 57:

Which of the following is true about array-based lists?

A. They allow for easy insertion/deletion
B. They offer O(1) access time by index
C. They automatically resize
D. They do not require contiguous memory
Answer: _________
Question 58:

In which scenario would you prefer to use an array over a linked list?

A. When you need constant time access by index
B. When you need dynamic resizing
C. When you frequently insert elements
D. When you frequently delete elements
Answer: _________
Question 59:

What is the correct syntax to access the third element of an array in C?

A. array[2]
B. array[3]
C. array(2)
D. array.get(2)
Answer: _________
Question 60:

Which of the following languages does not support multidimensional arrays directly?

A. C
B. Java
C. Python
D. JavaScript
Answer: _________
Question 61:

What is a jagged array in C#?

A. An array with rows of different lengths
B. A multi-dimensional array
C. An array containing different data types
D. An array that can dynamically resize
Answer: _________
Question 62:

Which method is used to sort an array in Python?

A. array.sort()
B. sort(array)
C. array.order()
D. Arrays.sort(array)
Answer: _________
Question 63:

What is the time complexity of accessing an element in an array by index?

A. O(n)
B. O(1)
C. O(log n)
D. O(n log n)
Answer: _________
Question 64:

What is the default value of an integer array in Java?

A. 0
B. null
C. -1
D. undefined
Answer: _________
Question 65:

What is the time complexity of inserting an element at the end of an array?

A. O(1)
B. O(n)
C. O(log n)
D. O(n log n)
Answer: _________
Question 66:

Which of the following statements is true about arrays?

A. Arrays are dynamic in size
B. Arrays have a fixed size
C. Arrays cannot store primitive data types
D. Arrays elements are always initialized
Answer: _________
Question 67:

What is a multidimensional array?

A. An array with multiple data types
B. An array containing multiple arrays
C. An array with a flexible size
D. An array with elements of different types
Answer: _________
Question 68:

How are elements stored in a 2D array in memory?

A. Row-major order
B. Column-major order
C. Random order
D. Both row-major and column-major order
Answer: _________
Question 69:

What is the correct way to access the third element of an array?

A. array[2]
B. array[3]
C. array(2)
D. array.get(2)
Answer: _________
Question 70:

Which of the following methods can be used to copy an array in Java?

A. System.copy()
B. Arrays.copyOf()
C. Collections.copy()
D. System.arraycopy()
Answer: _________
Question 71:

What is the time complexity of searching for an element in an unsorted array?

A. O(1)
B. O(log n)
C. O(n)
D. O(n log n)
Answer: _________
Question 72:

Which of the following is a disadvantage of arrays?

A. Random access
B. Fixed size
C. Cache friendliness
D. Ease of use
Answer: _________
Question 73:

How do you declare a 2D array in Python?

A. array = [[0]*m]*n
B. array = array([[0]*m]*n)
C. array = [[0 for i in range(m)] for j in range(n)]
D. array = [0, 0, 0, 0]
Answer: _________
Question 74:

What is the advantage of using arrays over linked lists?

A. Dynamic size
B. Better cache locality
C. Easier insertion and deletion
D. Lower memory usage
Answer: _________
Question 75:

What is the time complexity of deleting an element from an array?

A. O(1)
B. O(n)
C. O(log n)
D. O(n log n)
Answer: _________
Question 76:

Which of the following is true about array indexes?

A. They start from 1
B. They can be negative
C. They start from 0
D. They start from a user-defined value
Answer: _________
Question 77:

What is the correct way to initialize an array of size 5 in Python?

A. array = [0] * 5
B. array = {0, 0, 0, 0, 0}
C. array = (0, 0, 0, 0, 0)
D. array = new array[5]
Answer: _________
Question 78:

How can you pass an array to a function in C?

A. By value
B. By reference
C. By copying
D. By pointer
Answer: _________
Question 79:

Which of the following is an advantage of using arrays?

A. Dynamic size
B. Random access
C. Ease of insertion and deletion
D. Lower memory usage
Answer: _________
Question 80:

Predefined function rotate() in C++ is available under which header file?

A. math
B. stdio
C. stdlib
D. algorithm
Answer: _________
Question 81:

Which among the following is the worst-case time complexity for appending an element in a variable-length array?

A. O(n)
B. O(1)
C. O(n 2 )
D. O(log n)
Answer: _________
Question 82:

Which of the following is not an advantage of bit array?

A. Exploit bit level parallelism
B. Maximal use of data cache
C. Can be stored and manipulated in the register set for long periods of time
D. Accessing Individual Elements is easy
Answer: _________
Question 83:

Suffix array can be created in O(nlogn) time.

A. True
B. False
Answer: _________
Question 84:

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?

A. O(nm)
B. O(n 2 )
C. O(mnlogn)
D. O(mlogn)
Answer: _________
Question 85:

How many inversions are there in the array arr = {1,5,4,2,3}?

A. 0
B. 3
C. 4
D. 5
Answer: _________
Question 86:

Bit fields and Bit arrays are same.

A. True
B. False
Answer: _________
Question 87:

What will be the resulting array after reversing arr[]={3,5,4,2}?

A. 2,3,5,4
B. 4,2,3,5
C. 5,4,2,3
D. 2,4,5,3
Answer: _________
Question 88:

What is a sparse array?

A. Data structure for representing arrays of records
B. Data structure that compactly stores bits
C. An array in which most of the elements have the same value
D. An array in which memory is allocated in run time
Answer: _________
Question 89:

How will you implement dynamic arrays in Java?

A. Set
B. Map
C. HashMap
D. List
Answer: _________
Question 90:

Which of the following bitwise operations will you use to set a particular bit to 0?

A. OR
B. AND
C. XOR
D. NAND
Answer: _________
Question 91:

Which of the following arrays are used in the implementation of list data type in python?

A. Bit array
B. Dynamic arrays
C. Sparse arrays
D. Parallel arrays
Answer: _________
Question 92:

In what way the Symmetry Sparse Matrix can be stored efficiently?

A. Heap
B. Binary tree
C. Hash table
D. Adjacency List
Answer: _________
Question 93:

What is the time complexity of the code that uses merge sort for determining the number of inversions in an array?

A. O(n 2 )
B. O(n)
C. O(log n)
D. O(n log n)
Answer: _________
Question 94:

The number of items used by the dynamic array contents is its . . . . . . . .

A. Physical size
B. Capacity
C. Logical size
D. Random size
Answer: _________
Question 95:

Matrix A when multiplied with Matrix C gives the Identity matrix I, what is C?

A. Identity matrix
B. Inverse of A
C. Square of A
D. Transpose of A
Answer: _________
Question 96:

What is meant by physical size in a dynamic array?

A. The size allocated to elements
B. The size extended to add new elements
C. The size of the underlying array at the back-end
D. The size visible to users
Answer: _________
Question 97:

What is the difference between a normal(naive) array and a sparse array?

A. Sparse array can hold more elements than a normal array
B. Sparse array is memory efficient
C. Sparse array is dynamic
D. A naive array is more efficient
Answer: _________
Question 98:

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}?

A. 1
B. 2
C. 3
D. not possible to reach the end
Answer: _________
Question 99:

Which one of the following is a Special Sparse Matrix?

A. Band Matrix
B. Skew Matrix
C. Null matrix
D. Unit matrix
Answer: _________
Question 100:

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.

A. true
B. false
Answer: _________
Question 101:

What does the number of inversions in an array indicate?

A. mean value of the elements of array
B. measure of how close or far the array is from being sorted
C. the distribution of values in the array
D. median value of the elements of array
Answer: _________
Question 102:

Which of the following is the predefined function for array reversal in C++ ?

A. reverse()
B. arr_reverse()
C. array_reverse()
D. rev()
Answer: _________
Question 103:

LCP array and . . . . . . . . is used to construct suffix tree.

A. Hash tree
B. Hash trie
C. Suffix array
D. Balanced tree
Answer: _________
Question 104:

The size of the dynamic array is deallocated if the array size is less than . . . . . . . .% of the backend physical size.

A. 30
B. 40
C. 10
D. 20
Answer: _________
Question 105:

If row-major order is used, how is the following matrix stored in memory? a b c d e f g h i

A. ihgfedcba
B. abcdefghi
C. cfibehadg
D. adgbehcfi
Answer: _________
Question 106:

Which of the following property does not hold for matrix multiplication?

A. Associative
B. Distributive
C. Commutative
D. Additive Inverse
Answer: _________
Question 107:

What is a dynamic array?

A. A variable size data structure
B. An array which is created at runtime
C. The memory to the array is allocated at runtime
D. An array which is reallocated everytime whenever new elements have to be added
Answer: _________
Question 108:

Is O(n) the Worst case Time Complexity for addition of two Sparse Matrix?

A. True
B. False
Answer: _________
Question 109:

The growth factor of ArrayList in Java is . . . . . . . .

A. 1
B. 1.5
C. 2
D. 0
Answer: _________
Question 110:

To rotate an array by using the algorithm of rotating its elements one by one is an in place algorithm.

A. true
B. false
Answer: _________
Question 111:

What is a sorted array?

A. Arrays sorted in numerical order
B. Arrays sorted in alphabetical order
C. Elements of the array are placed at equally spaced addresses in the memory
D. All of the mentioned
Answer: _________
Question 112:

When do you use a sparse array?

A. When there are unique elements in the array
B. When the array has more occurrence of zero elements
C. When the data type of elements differ
D. When elements are sorted
Answer: _________
Question 113:

What is the minimum possible time complexity to find the number of steps to reach the end of an array?

A. O(n)
B. O(n 2 )
C. O(n 3/2 )
D. O(1)
Answer: _________
Question 114:

Under what condition the number of inversions in an array are minimum?

A. when the array is sorted
B. when the array is reverse sorted
C. when the array is half sorted
D. depends on the given array
Answer: _________
Question 115:

What does Hamming weight/population count mean in Bit arrays?

A. Finding the number of 1 bit in a bit array
B. Finding the number of 0 bit in a bit array
C. Finding the sum of bits in a bit array
D. Finding the average number of 1's and 0's in bit arrays
Answer: _________
Question 116:

Dynamic arrays overcome the limit of static arrays.

A. True
B. False
Answer: _________
Question 117:

Is Sparse Matrix also known as Dense Matrix?

A. True
B. False
Answer: _________
Question 118:

What will be the suffix array of the string "engineering"?

A. 2 3 8 4 9 1 7 5 0 6 10
B. 5 0 6 1 4 9 1 7 0 2 3 8
C. 5 0 6 10 2 4 9 1 7 3 8
D. 5 0 6 10 2 3 8 4 9 1 7
Answer: _________
Question 119:

Where does the GNU C compiler allocates memory for variable-length arrays?

A. Tree
B. Stack
C. Linked List
D. Queue
Answer: _________
Question 120:

Which of the following is not an application of sorted array?

A. Commercial computing
B. Priority Scheduling
C. Discrete Mathematics
D. Hash Tables
Answer: _________
Question 121:

What is a bit array?

A. Data structure for representing arrays of records
B. Data structure that compactly stores bits
C. An array in which most of the elements have the same value
D. Array in which elements are not present in continuous locations
Answer: _________
Question 122:

Which of the following bitwise operations will you use to set a particular bit to 1?

A. OR
B. AND
C. XOR
D. NOR
Answer: _________
Question 123:

What are parallel arrays?

A. Arrays of the same size
B. Arrays allocated one after the other
C. Arrays of the same number of elements
D. Arrays allocated dynamically
Answer: _________
Question 124:

Which of the following is an advantage of parallel arrays?

A. Poor locality of reference for non-sequential access
B. Very little direct language support
C. Expensive to shrink or grow
D. Increased Locality of Reference
Answer: _________
Question 125:

Which of the following is an advantage of matrices?

A. Internal complexity
B. Searching through a matrix is complex
C. Not space efficient
D. Graph Plotting
Answer: _________
Question 126:

Which of the following is not a disadvantage of bit array?

A. Without compression, they might become sparse
B. Accessing individual bits is expensive
C. Compressing bit array to byte/word array, the machine also has to support byte/word addressing
D. Storing and Manipulating in the register set for long periods of time
Answer: _________
Question 127:

What is sparsity of a matrix?

A. The fraction of zero elements over the total number of elements
B. The fraction of non-zero elements over the total number of elements
C. The fraction of total number of elements over the zero elements
D. The fraction of total number of elements over the non-zero elements
Answer: _________
Question 128:

Which class in Java can be used to represent bit array?

A. BitSet
B. BitVector
C. BitArray
D. BitStream
Answer: _________
Question 129:

What will be the minimum number of jumps required to reach the end of the array arr[] = {1,3,6,3,6,8,5}?

A. 1
B. 2
C. 3
D. not possible to reach the end
Answer: _________
Question 130:

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.

A. true
B. false
Answer: _________
Question 131:

Which of the following form inversion in the array arr = {1,5,4,2}?

A. (5,4), (5,2)
B. (5,4), (5,2), (4,2)
C. (1,5), (1,4), (1,2)
D. (1,5)
Answer: _________
Question 132:

What is the time complexity for inserting/deleting at the beginning of the array?

A. O(1)
B. O(n)
C. O(logn)
D. O(nlogn)
Answer: _________
Question 133:

What is the worst case time complexity of inserting an element into the sorted array?

A. O(nlogn)
B. O(logn)
C. O(n)
D. O(n 2 )
Answer: _________
Question 134:

Which of the following algorithm to rotate an array has the maximum time complexity?

A. rotate elements one by one
B. juggling algorithm
C. reversal algorithm
D. using a temporary array
Answer: _________
Question 135:

Which of the following is false?

A. Suffix array is always sorted
B. Suffix array is used in string matching problems
C. Suffix array is always unsorted
D. Suffix array contains all the suffixes of the given string
Answer: _________
Question 136:

Suffix array of the string "statistics" is . . . . . . . .

A. 2 8 7 4 9 0 5 1 6 3
B. 2 7 4 9 8 0 5 1 6 3
C. 2 4 9 0 5 7 8 1 6 3
D. 2 8 7 0 5 1 6 9 4 3
Answer: _________
Question 137:

The matrix contains m rows and n columns. The matrix is called Sparse Matrix if . . . . . . . .

A. Total number of Zero elements > (m*n)/2
B. Total number of Zero elements = m + n
C. Total number of Zero elements = m/n
D. Total number of Zero elements = m-n
Answer: _________
Question 138:

Both Dynamic array and Dynamically memory allocated array are same.

A. True
B. False
Answer: _________
Question 139:

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

}

A. Variable-length array
B. Fixed-size array
C. Dynamic memory allocation
D. Error
Answer: _________
Question 140:

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

}

A. O(d)
B. O(n)
C. O(n 2 )
D. O(n*d)
Answer: _________
Question 141:

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

}

A. 4 5 1 2 3
B. 3 4 5 1 2
C. 5 4 3 1 2
D. error
Answer: _________
Question 142:

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

}

A. 3 2 1 4 5
B. 5 4 3 2 1
C. 1 2 5 4 3
D. error
Answer: _________
Question 143:

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

}

A. 3 2 1 4 5
B. 3 4 5 1 2
C. 5 4 3 2 1
D. error
Answer: _________
Question 144:

Which of the following is the correct syntax to declare an ArrayList in Java?

A. ArrayList al = new ArrayList()
B. ArrayList al = new ArrayList[]
C. ArrayList al() = new ArrayList()
D. ArrayList al[] = new ArrayList[]
Answer: _________
Question 145:

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)

A. Normal of a matrix
B. Trace of a matrix
C. Square of a matrix
D. Transpose of a matrix
Answer: _________
Question 146:

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
}

A. O(1)
B. O(n)
C. O(d)
D. O(n*d)
Answer: _________
Question 147:

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
}

A. O(n*d)
B. O(n)
C. O(d)
D. O(n 2 )
Answer: _________
Question 148:

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
}

A. O(n 1/2 )
B. O(n)
C. O(n 3/2 )
D. O(n 2 )
Answer: _________
Question 149:

Select the code snippet which performs matrix multiplication.(a and b are the two given matrices, resultant marix is c)

A. for (int i = 0 i < n i++) { for (int j = 0 j < n j++) { for (int k = 0 k < n k++) { c[i][j] = c[i][j] + a[i][k] * b[k][j] } } }
B. for (int i = 0 i < n i++) { for (int j = 0 j < n j++) { for (int k = 0 k < n k++) { c[i][j] = c[i][j] * a[i][k] * b[k][j] } } }
C. for (int i = 0 i < n i++) { for (int j = 0 j < n j++) { for (int k = 0 k < n k++) { c[i][j] = c[i][j] + a[i][k] + b[k][j] } } }
D. for (int i = 0 i < n i++) { for (int j = 0 j < n j++) { for (int k = 0 k < n k++) { c[i][j] = c[i][j] + a[i][j] + b[k][j] } } }
Answer: _________
Question 150:

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?

A. 6 and 6
B. 6 and 2
C. 2 and 6
D. 2 and 2
Answer: _________
Question 151:

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
}

A. 1
B. 2
C. 3
D. error
Answer: _________
Question 152:

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
}

A. 5 1 4 3
B. 3 5 1 4
C. 5 3 4 1
D. error
Answer: _________
Question 153:

Which of the following is the correct way to declare an array in C?

A. int array[]
B. array{int}
C. int array[10]
D. int array()
Answer: _________
Question 154:

How do you find the length of an array in Java?

A. array.size()
B. array.length
C. array.length()
D. array.size
Answer: _________
Question 155:

Which of the following correctly initializes an array in C++?

A. int array[3] = {1, 2, 3}
B. int array = new int[3]
C. int array(3) = {1, 2, 3}
D. int array[] = new int[3]
Answer: _________
Question 156:

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
}

A. O(k)
B. O(n)
C. O(k log k)
D. O(n log n)
Answer: _________
Question 157:

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))
}

A. Store the element in the specified position
B. Get the element from the specified position
C. Alter the element in the specified position
D. Removes the element from the specified position
Answer: _________
Question 158:

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
}

A. O(n log n)
B. O(n)
C. O(n 1/2 )
D. O(n 2 )
Answer: _________
Question 159:

What is the output of the following C code: int array[5] = {1, 2, 3, 4, 5}
printf("%d", array[2])

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 160:

How do you dynamically allocate an array in C++?

A. int* array = new int[size]
B. int array = new int[size]
C. int array[size]
D. int* array = malloc(size * sizeof(int))
Answer: _________
Question 161:

Which of the following is the correct way to declare a 3D array in Java?

A. int[][][] array = new int[3][3][3]
B. int array[][][] = new int[3][3][3]
C. int array[3][3][3]
D. int[] array = new int[3][3][3]
Answer: _________
Question 162:

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]
}

A. 30
B. 40
C. 50
D. 60
Answer: _________
Question 163:

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
}

A. 5 6 1 2 3 4
B. 6 5 4 3 1 2
C. 3 4 5 6 1 2
D. error
Answer: _________
Question 164:

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
}

A. O(n)
B. O(log n)
C. O(1)
D. O(n log n)
Answer: _________
Question 165:

What is the output of the following Python code: array = [1, 2, 3]
print(array[-1])

A. 1
B. 2
C. 3
D. IndexError
Answer: _________
Question 166:

How do you initialize an array in Java with specific values?

A. int[] array = new int[5]
B. int[] array = {1, 2, 3, 4, 5}
C. int array[] = new int[5]
D. int array[] = {1, 2, 3, 4, 5}
Answer: _________
Question 167:

How do you remove an element from an array in JavaScript?

A. array.remove(index)
B. array.delete(index)
C. array.splice(index, 1)
D. array.pop(index)
Answer: _________
Question 168:

Which of the following is a correct way to declare a constant array in JavaScript?

A. const array = [1, 2, 3]
B. constant array = [1, 2, 3]
C. array = constant [1, 2, 3]
D. array.constant = [1, 2, 3]
Answer: _________
Question 169:

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
}

A. O(n)
B. O(n log n)
C. O(n 2 )
D. O(log n)
Answer: _________
Question 170:

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
}

A. 3
B. 4
C. 4 4 2 1 0
D. 4 2 2 0 1
Answer: _________
Question 171:

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
}

A. O(1)
B. O(n)
C. O(log n)
D. O(n log n)
Answer: _________
Question 172:

Choose the appropriate code that counts the number of non-zero(non-null) elements in the sparse array.

A. public int count() { int count = 0 for (List cur = this.next (cur != null) cur = cur.next) { count++ } return count }
B. public int count() { int count = 0 for (List cur = this (cur != null) cur = cur.next) { count++ } return count }
C. public int count() { int count = 1 for (List cur = this.next (cur != null) cur = cur.next) { count++ } return count }
D. public int count() { int count = 1 for (List cur = this.next (cur != null) cur = cur.next.next) { count++ } return count }
Answer: _________
Question 173:

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
}

A. O(1)
B. O(n)
C. O(log n)
D. O(n log n)
Answer: _________
Question 174:

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
}

A. O(1)
B. O(n)
C. O(d)
D. O(n*d)
Answer: _________
Question 175:

How do you allocate a matrix using a single pointer in C?(r and c are the number of rows and columns respectively)

A. int *arr = malloc(r * c * sizeof(int))
B. int *arr = (int *)malloc(r * c * sizeof(int))
C. int *arr = (int *)malloc(r + c * sizeof(int))
D. int *arr = (int *)malloc(r * c * sizeof(arr))
Answer: _________
Question 176:

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
}

A. 1 2 3 4
B. 4 3 2 1
C. 1 4 2 3
D. 4 1 2 3
Answer: _________

Answer Key

1: A
2: A
3: D
4: C
5: C
6: B
7: D
8: B
9: D
10: A
11: A
12: A
13: D
14: C
15: C
16: A
17: D
18: A
19: C
20: C
21: B
22: C
23: D
24: D
25: B
26: A
27: A
28: D
29: D
30: B
31: B
32: C
33: D
34: B
35: D
36: C
37: A
38: B
39: B
40: B
41: D
42: D
43: B
44: B
45: D
46: D
47: A
48: A
49: C
50: A
51: A
52: A
53: A
54: A
55: D
56: C
57: B
58: A
59: A
60: D
61: A
62: A
63: B
64: A
65: A
66: B
67: B
68: A
69: A
70: D
71: C
72: B
73: C
74: B
75: B
76: C
77: A
78: D
79: B
80: D
81: A
82: D
83: A
84: D
85: D
86: B
87: D
88: C
89: D
90: B
91: B
92: B
93: D
94: C
95: B
96: C
97: B
98: D
99: A
100: A
101: B
102: A
103: C
104: A
105: B
106: C
107: A
108: A
109: B
110: A
111: D
112: B
113: A
114: A
115: A
116: A
117: B
118: D
119: B
120: D
121: B
122: A
123: C
124: D
125: D
126: D
127: A
128: A
129: C
130: A
131: B
132: B
133: C
134: A
135: C
136: A
137: A
138: B
139: A
140: B
141: A
142: A
143: B
144: A
145: B
146: C
147: A
148: D
149: A
150: B
151: C
152: C
153: C
154: B
155: A
156: A
157: B
158: D
159: C
160: A
161: B
162: C
163: A
164: A
165: C
166: B
167: C
168: A
169: C
170: C
171: B
172: A
173: A
174: A
175: B
176: B