MNC Based Technical Questions and Answers

Started by Kalyan, Jan 02, 2009, 06:50 AM

Previous topic - Next topic

Kalyan

MNC Based Technical Questions and Answers

Networks and Security

1. How do you use RSA for both authentication and secrecy?

2. What is ARP and how does it work?

3. What's the difference between a switch and a router?

4. Name some routing protocols? (RIP,OSPF etc..)

5. How do you do authentication with message digest(MD5)? (Usually MD is used for finding tampering of data)

6. How do you implement a packet filter that distinguishes following cases and selects first case and rejects second case.

i) A host inside the corporate n/w makes a ftp request to outside host and the outside host sends reply.

ii) A host outside the network sends a ftp request to host inside. for the packet filter in both cases the source and destination feilds will look the same.

7. How does traceroute works? Now how does traceroute makes sure that the packet follows the same path that a previous (with ttl - 1) probe packet went in?

8. Explain Kerberos Protocol ?

9. What are digital signatures and smart cards?

10. Difference between discretionary access control and mandatory access control?

Java

1. How do you find the size of a java object (not the primitive type) ?

ANS. type cast it to string and find its s.length()

2. Why is multiple inheritance not provided in Java?

3. Thread t = new Thread(); t.start(); t = null; now what will happen to the created thread?

4. How is garbage collection done in java?

5. How do you write a "ping" routine in java?

6. What are the security restrictions on applets?

Linked lists

* 0. Under what circumstances can one delete an element from a singly linked list in constant time?

* 1. Given a singly linked list, determine whether it contains a loop or not.

2. Given a singly linked list, print out its contents in reverse order. Can you do it without using any extra space?

3. Given a binary tree with nodes, print out the values in pre-order/in-order/post-order without using any extra space.

4. Reverse a singly linked list recursively. The function prototype is node * reverse (node *) ;

5. Given a singly linked list, find the middle of the list.

Hints and Answers

0. If the list is circular and there are no references to the nodes in the list from anywhere else! Just copy the contents of the next node and delete the next node. If the list is not circular, we can delete any but the last node using this idea. In that case, mark the last node as dummy!

1. (a) Start reversing the list. If you reach the head, gotcha! there is a loop!

But this changes the list. So, reverse the list again.

(b) Maintain two pointers, initially pointing to the head. Advance one of them one node at a time. And the other one, two nodes at a time. If the latter overtakes the former at any time, there is a loop!

p1 = p2 = head;

do {
p1 = p1->next;
p2 = p2->next->next;
} while (p1 != p2);

2. Start reversing the list. Do this again, printing the contents.

3. [Yet to think about]

4. node * reverse (node * n)
{
node * m ;

if (! (n && n -> next))
return n ;

m = reverse (n -> next) ;
n -> next -> next = n ;
n -> next = NULL ;
return m ;
}

5. Use the single and double pointer jumping. Maintain two pointers, initially pointing to the head. Advance one of them one node at a time. And the other one, two nodes at a time. When the double reaches the end, the single is in the middle. This is not asymptotically faster but seems to take less steps than going through the list twice.

Bit-manipulation
* 1. Reverse the bits of an unsigned integer.

* 2. Compute the number of ones in an unsigned integer.

3. Compute the discrete log of an unsigned integer.

* 4. How do we test most simply if an unsigned integer is a power of two?

5. Set the highest significant bit of an unsigned integer to zero.

6. Let f(k) = y where k is the y-th number in the increasing sequence of non-negative integers with the same number of ones in its binary representation as y, e.g. f(0) = 1, f(1) = 1, f(2) = 2, f(3) = 1, f(4) = 3, f(5) = 2, f(6) = 3 and so on. Given k >= 0, compute f(k).

Hints and Answers

1. #define reverse(x) \
(x=x>>16|(0×0000ffff&x)<<16, x="(0xff00ff00&x)">>8|(0×00ff00ff&x)<<8, x="(0xf0f0f0f0&x)">>4|(0×0f0f0f0f&x)<<4, x="(0xcccccccc&x)">>2|(0×33333333&x)<<2, x="(0xaaaaaaaa&x)">>1|(0×55555555&x)<<1)>

2. #define count_ones(x) \
(x=(0xaaaaaaaa&x)>>1+(0×55555555&x), \
x=(0xcccccccc&x)>>2+(0×33333333&x), \
x=(0xf0f0f0f0&x)>>4+(0×0f0f0f0f&x), \
x=(0xff00ff00&x)>>8+(0×00ff00ff&x), \
x=x>>16+(0×0000ffff&x))

3. #define discrete_log(h) \
(h=(h>>1)|(h>>2), \
h|=(h>>2), \
h|=(h>>4), \
h|=(h>>8), \
h|=(h>>16), \
h=(0xaaaaaaaa&h)>>1+(0×55555555&h), \
h=(0xcccccccc&h)>>2+(0×33333333&h), \
h=(0xf0f0f0f0&h)>>4+(0×0f0f0f0f&h), \
h=(0xff00ff00&h)>>8+(0×00ff00ff&h), \
h=(h>>16)+(0×0000ffff&h))
If I understand it right, log2(2) =1, log2(3)=1, log2(4)=2..... But this macro does not work out log2(0) which does not exist! How do you think it should be handled?

4. #define power_of_two(x) \ ((x)&&(~(x&(x-1))))

5. (from Denis Zabavchik) Set the highest significant bit of an unsigned integer to zero
#define zero_most_significant(h) \
(h&=(h>>1)|(h>>2), \
h|=(h>>2), \
h|=(h>>4), \
h|=(h>>8), \
h|=(h>>16))

Graphics

1. Write a function to check if two rectangles defined as below overlap or not. struct rect { int top, bot, left, right; } r1, r2;

2. Write a SetPixel(x, y) function, given a pointer to the bitmap. Each pixel is represented by 1 bit. There are 640 pixels per row. In each byte, while the bits are numbered right to left, pixels are numbered left to right. Avoid multiplications and divisions to improve performance.

Databases

* 1. You, a designer want to measure disk traffic i.e. get a histogram showing the relative frequency of I/O/second for each disk block. The buffer pool has b buffers and uses LRU replacement policy. The disk block size and buffer pool block sizes are the same. You are given a routine int lru_block_in_position (int i) which returns the block_id of the block in the i-th position in the list of blocks managed by LRU. Assume position 0 is the hottest. You can repeatedly call this routine. How would you get the histogram you desire?

Hints and Answers

1. Simply do histogram [lru_block_in_position (b-1)] ++ at frequent intervals... The sampling frequency should be close to the disk I/O rate. It can be adjusted by remembering the last block seen in position b. If same, decrease frequency; if different, increase, with exponential decay etc. And of course, take care of overflows in the histogram.

Semaphores

1. Implement a multiple-reader-single-writer lock given a compare-and-swap instruction. Readers cannot overtake waiting writers.

Others

1. A character set has 1 and 2 byte characters. One byte characters have 0 as the first bit. You just keep accumulating the characters in a buffer. Suppose at some point the user types a backspace, how can you remove the character efficiently. (Note: You cant store the last character typed because the user can type in arbitrarily many backspaces)

2. What is the simples way to check if the sum of two unsigned integers has resulted in an overflow.

3. How do you represent an n-ary tree? Write a program to print the nodes of such a tree in breadth first order.

4. Write the 'tr' program of UNIX. Invoked as

tr -str1 -str2. It reads stdin and prints it out to stdout, replacing every occurance of str1 with str2.

e.g. tr -abc -xyz
to be and not to be <- input to ye xnd not to ye <- output

source : interviewquestionsadda