C-Dynamic Memory Allocation and Data Structure

C-Dynamic Memory Allocation and Data Structure
31. 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};

  • 4
  • 5
  • 6
  • None of these
Show Answer
32. 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
  • 3
  • 4
  • 5
  • 6
Show Answer
33. 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
  • O(n)
  • O(logn)
  • O(log*n)
  • O(1)
Show Answer
34. 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 ?
  • An aray of 50 numbers
  • An array of 100 numbers.
  • An aray of 500 numbers.
  • A dynamically allocated array of 550 numbers
Show Answer
35. 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 ?
  • O (logn)
  • O(n)
  • O(log logn)
  • O("n)
Show Answer
36. 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?


  • 010110101
  • 010101101
  • 10110101
  • 10101101
Show Answer
37. 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);
}
}

  • Both P1 and P2
  • P2 only
  • P1 only
  • Neither P1 nor P2
Show Answer
38. 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
  • (top1=(MAXSIZE-1)/2) and (top2=(MAXSIZE-1)/2 + 1)
  • top1 + top2=MAXSIZE
  • (top1=(MAXSIZE-1)/2 or (top2=MAXSIZE-1)
  • top1=top2-1
Show Answer
39. 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:

  • 6, 1
  • 5, 7
  • 3, 2
  • 1, 5
Show Answer
40. The best data structure to check whether an arithmetic expression has balanced parenthesis is a
  • Queue
  • Stack
  • Tree
  • List
Show Answer
Questions and Answers for Competitive Exams Various Entrance Test