Question 21
main()
{
int x, y, m, n;
scanf (\"%d %d\", &x, &y);
/* Assume x > 0 and y > 0 */
m = x;
n = y;
while (m! = n)
{
if (m > n)
m = m - n;
else
n = n - m;
}
print f (\"% d\", n);
}
Question 22
x = m;
y = 1;
while (x - y > e)
{
x = (x + y)/2;
y = m/x;
}
print(x);
Question 23
Huffman coding is a lossless data compression algorithm. The most frequent character gets the smallest code and the least frequent character gets the largest code. Consider the following statements regarding Huffman coding algorithm?
S1 : The time complexity of the Huffman algorithm is O(nlogn). Using a heap to store the weight of each tree, each iteration requires O(logn) time to determine the cheapest weight and insert the new weight. There are O(n) iterations, one for each item.
S2 : If the input array is sorted, there exists a linear time algorithm.
S3 : A divide-and-conquer approach might have us asking which characters should appear in the left and right subtrees and trying to build the tree from the top down. As with the optimal binary search tree, this will lead to to an exponential time algorithm.
Which of the following option is correct?
Question 24
Question 25
Question 26
In the following C program fragment, j, k n and TwoLog_n are integer variables, and A is an array of integers. The variable n is initialized to an integer ≥ 3, and TwoLog_n is initialized to the value of 2*⌈log2(n)⌉
for (k = 3; k < = n; k++)
A[k] = 0;
for (k = 2; k < = TwoLog_n; k++)
for (j = k + 1; j < = n; j++)
A[j] = A[j] || (j % k);
for (j = 3; j < = n; j++)
if (!A[j]) printf(\"%d\", j);
The set of numbers printed by this program fragment is
Question 27
v[i, j] = i-j for all i, j, 1 <= i <= n, 1 <= j <= nThe sum of the elements of the array v is
Question 28
Question 29
reverse(s, 1, k) ; reverse(s, k + 1, n); reverse(s, l, n);
Question 30
void fun(int arr[], int n)
{
for (int i = 0; i < n; i+=2)
{
if (i>0 && arr[i-1] > arr[i] )
swap(&arr[i], &arr[i-1]);
if (i<n-1 && arr[i] < arr[i+1] )
swap(&arr[i], &arr[i + 1]);
}
}
There are 49 questions to complete.