Array
Question 1 
A program P reads in 500 integers in the range [0..100] exepresenting the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies? (GATE CS 2005)
An array of 50 numbers  
An array of 100 numbers  
An array of 500 numbers  
A dynamically allocated array of 550 numbers 
Discuss it
Question 1 Explanation:
See question 1 of http://www.geeksforgeeks.org/datastructuresandalgorithmsset22/
Question 2 
Which of the following operations is not O(1) for an array of sorted data. You may assume that array elements are distinct.
Find the ith largest element  
Delete an element  
Find the ith smallest element  
All of the above 
Discuss it
Question 2 Explanation:
The worst case time complexity for deleting an element from array can become O(n).
Question 3 
The minimum number of comparisons required to determine if an integer appears more than n/2 times in a sorted array of n integers is
Θ(n)  
Θ(logn)  
Θ(log*n)  
Θ(1) 
Discuss it
Question 3 Explanation:
The Best way to find out whether an integer appears more than n/2 times in a sorted array(Ascending Order) of n integers, would be binary search approach.
 The First occurence of an element can be found out in O(log(n)) time using divide and conquer technique,lets say it is i.
 The Last occurrence of an element can be found out in O(log(n)) time using divide and conquer technique,lets say it is j.
 Now number of occuerence of that element(count) is (ji+1). Overall time complexity = log n +log n +1 = O(logn)
Question 4 
Let A be a square matrix of size n x n. Consider the following program. What is the expected output?
C = 100 for i = 1 to n do for j = 1 to n do { Temp = A[i][j] + C A[i][j] = A[j][i] A[j][i] = Temp  C } for i = 1 to n do for j = 1 to n do Output(A[i][j]);
The matrix A itself  
Transpose of matrix A  
Adding 100 to the upper diagonal elements and subtracting 100 from diagonal elements of A  
None of the above 
Discuss it
Question 4 Explanation:
If we take look at the inner statements of first loops, we can notice that the statements swap A[i][j] and A[j][i] for all i and j. Since the loop runs for all elements, every element A[l][m] would be swapped twice, once for i = l and j = m and then for i = m and j = l. Swapping twice means the matrix doesn’t change.
Source: http://www.geeksforgeeks.org/datastructuresalgorithmsset34/
Question 5 
An algorithm performs (logN)^{1/2} find operations, N insert operations, (logN)^{1/2} operations, and (logN)^{1/2} decreasekey operations on a set of data items with keys drawn from a linearly ordered set. For a delete operation, a pointer is provided to the record that must be deleted. For the decreasekey operation, a pointer is provided to the record that has its key decreased. Which one of the following data structures is the most suited for the algorithm to use, if the goal is to achieve the best total asymptotic complexity considering all the operations?
Unsorted array  
Minheap  
Sorted array  
Sorted doubly linked list 
Discuss it
Question 5 Explanation:
The time complexity of insert in unsorted array is O(1), O(Logn) in MinHeap, O(n) in sorted array and sorted DLL.
 For unsorted array, we can always insert an element at end and do insert in O(1) time
 For Min Heap, insertion takes O(Log n) time. Refer Binary Heap operations for details.
 For sorted array, insert takes O(n) time as we may have to move all elements worst case.
 For sorted doubly linked list, insert takes O(n) time to find position of element to be inserted.
Question 6 
Consider an array consisting of –ve and +ve numbers. What would be the worst time comparisons an algorithm can take in order to segregate the numbers having same sign altogether i.e all +ve on one side and then all ve on the other ?
N1
 
N  
N+1  
(N*(N1))/2

Discuss it
Question 6 Explanation:
Here we can use the partition algorithm of quick sort for segregation and answer will be N1.
Choose the first element as pivot whatever may be its sign we don’t care and keep an extra index at pivot position .
Choose the first element as pivot whatever may be its sign we don’t care and keep an extra index at pivot position .
Question 7 
Let A[1...n] be an array of n distinct numbers. If i < j and A[i] > A[j], then the pair (i, j) is called an inversion of A. What is the expected number of inversions in any permutation on n elements ?
θ(n)  
θ(lgn)  
θ(nlgn)  
θ(n^{2}) 
Discuss it
Question 7 Explanation:
The expected number of inversions in any permutation on n elements is θ(n^{2}).
For more information on number of inversions Refer:Count Inversions in an array  Set 1 (Using Merge Sort)
Option (D) is correct.
Question 8 
A three dimensional array in ‘C’ is declared as int A[x][y][z]. Here, the address of an item at the location A[p][q][r] can be computed as follows (where w is the word length of an integer):
&A[0][0][0] + w(y * z * q + z * p + r)  
&A[0][0][0] + w(y * z * p + z*q + r)  
&A[0][0][0] + w(x * y * p + z * q+ r)  
&A[0][0][0] + w(x * y * q + z * p + r) 
Discuss it
Question 9 
Which of the following is an illegal array definition?
Type COLONGE : (LIME, PINE, MUSK, MENTHOL); var a : array [COLONGE] of REAL;  
var a : array [REAL] of REAL;  
var a : array [‘A’…’Z’] of REAL;  
var a : array [BOOLEAN] of REAL; 
Discuss it
Question 10 
Consider an array A[20, 10], assume 4 words per memory cell and the base address of array A is 100. What is the address of A[11, 5] ? Assume row major storage.
560  
565  
570  
575 
Discuss it
There are 11 questions to complete.