Monday, December 24, 2007

IBM PLACEMENTS FOR FRESHERS 2007

Posted: Wed, 05 Dec 2007 01:32:47 -0600

  • Write a C program to count bits set in an integer?
  • What purpose do the bitwise and, or, xor and the shift operators serve?
  • How to reverse the bits in an integer?
  • Check if the 20th bit of a 32 bit integer is on or off?
  • How to reverse the odd bits of an integer?
  • How would you count the number of bits set in a floating point number?

The answers shall be posted in one or two days. In the meanwhile you guys try out these questions. I will post answers to my previous post "" today.



Now check the value of flag to say whether it is a BST or not.If it is not then it is already taken care by the code.

15.You are given a small sorted list of numbers, and a very very long sorted list of numbers - so long that it had to be put on a disk in different blocks. How would you find those short list numbers in the bigger one?

Solution:For each chunk of sorted list which occupies a block,make a note of the first and last elements.Thus we have lookup table giving the first and last elements of each of the blocks.Now associate an empty list with each of the blocks.
Now try to find the block which might contain the first entry A[1]of the small sorted list(say)A given.Since we knew the first and last elements of all the blocks,we can identify the block Bi ,which only can contain the desired number.Now add A[1] to the empty list associated with Bi.Now we need to identify the candidate block for A[2].As A is also sorted,A[2] should lie either in Bi or its successors.So we simultaneously traverse
A as well as lookup table.When we are done with finding the probable blocks of all the numbers in A,we have also finished the look up table. We also have in the lists associated with each block,all those entries of A to search for, in that particular block.Now for each block Bi,search for all the entries in its list using binary search.This way we have minimized the number of disk block accesses,which is the bottleneck .