C-Dynamic Memory Allocation and Data Structure Questions and Answers
Practice ModeShowing 10 of 104 questions
Q31
How many shifting is required to sort the elements in insertation sort in non decresing order of the given list below:
int A[ ]={2,3, 7, 1, 6, 8, 9};
Answer: Option A
Q32
How many comparison is required to search a number on a given sorted list by using binary search.
int L[ ]={1, 3, 7, 9, 12, 15, 19, 21, 27, 30};
The key value is 3
Answer: Option A
Q33
The minimum number of comparisons required to determine if an integer apears more than n/2 times in a sorted array of n integer is
Answer: Option A
Q34
A program P reads in 500 integers in the range 1 to 100 representing the score of 500 students. If then prints the frequencies of each score above 50. What would be thebest way for P to store the frequencies ?
Answer: Option A
Q35
In the following C function, let n e"m,
int gcd (n,x)
{
if (n%m==0)
return m;
n=n%m;
return gcd (m,n);
}
How many recursive calls re made by this function ?
Answer: Option A
Q36
Consider the code fragment written in C below
void f(int n)
{
if (n<=1)
{
printf("%d", n);
}
else
{
f (n/2);
printf("%d", n%2);
}
}
what does f(173 print?
Answer: Option D
Q37
Which of the following implementations will produce the same output for f(173) as theone from previous question?
P1:
void f(int n)
{
if (n/2)
{
f (n/2);
}
printf("%d:,n%2);
}
P2:
void f(int n)
{
if (n<=1)
{
printf("%d",n);
}
else
{
printf('%d",%2);
f(n/2);
}
}
Answer: Option A
Q38
A single array A[MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables top1 and top2 (top1<top2) point to the location of the topmost element in each of the stacks. If the space is to be used efficiently, the condition for "stack full" is
Answer: Option D
Q39
The following postfix expression with single digit opeands is evaluated using a stack:
8 2 3^ / 2 3 * + 5 1*-
Note that ^ is the exponentiation operator. The top two elements of the stack after the first * is evaluated are:
Answer: Option A
Q40
The best data structure to check whether an arithmetic expression has balanced parenthesis is a
Answer: Option B