Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

31
Oct

Questions asked in various job interviews (in Programming)

Related Blog Items

Programming
===========

-> Write a program to search a list of unsorted elements with only one condition
Ans:
  Normal routine: for(i=0;i Manage an array efficiently to implement two stacks on it
Ans:
  manage like this:

   ————————————
   |1st stack–>  <–2nd stack|

  ————————————-

 no explicit bounds

Write a program to traverse a n-ary tree and store the nodes in disk in such way that
tree is reconstructable from the storage

Ans: like java’s serialise data structures

-> Write a program to traverse an array spirally
Ans: write this using directions and maintaining states

-> Write a program to find sub-array of any number of elements with optimum
sum-value in an array (array elements may be -ve)

-> Reverse a double linked list

-> Reverse a single linked list
Ans: use a stack to reverse it

-> Write a recursive program to print a linked list reversely

print(Node *node)
  {
    if(node->next)
     print(node->next)
   else
    return;
  printf(node->info)
 }

-> How do you find loops in a single linked list
  1) use flags
  2) use two or three pointers and increment them at different levels
      like one ptr with ptr=ptr->next , another with second_ptr=second_ptr->next->next.
  if these pointers meet, then it got loops

-> Write a program to find x^n in O(log n)

 

  xpown(x,n)
  {
    val = x;

    do {
      if(n % 2)
        val *= x;
      else
        val *= val;
    }while(n /= 2);
 }

 

 

-> Write a program for preorder traversal without using recursion
ans: use stack

-> Write a program to traverse a binary tree in level by level manner
ans: its just BFS… use queue

-> finding a number is power of 2 or not
ans:
if(!(n & n-1)) printf(”power of 2″);
better answer like this “count number of 1’s… if(count==1) power of 2)

->In an unsorted array find the sum of 3 maximum numbers in less than O(n) time
ans: 1)do bubble sort until u sort 3 elemnts then stop it, sum the nums
   2) build heap (O(n)), delete_max 3 elements (O(logn))

-> in a sorted array only two elements are misplaced, find the desired element still
  maintaining the o(logn) time

-> basics of all data structres

Popularity: 32%

You need to log on to convert this article into PDF


Related Blog Items

3 Comments

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image