OS: Synchronization, deadlock, page replacement, thrashing, context switching, IPC, Garbage collection, Process and threads, Direct Memory Access
DBMS: Normalization, Joins
Algorithms & DS: Linked List & arrays, MST algorithms, Djikstra Shortest Path, Bit manipulation algorithms (Geeksforgeeks)
Electronics: Computer organization(Pipelining), Microprocessors(IC 8241, 8251, 8085), Digital Electronics (minimization of expression, minimum no of NAND gates, etc), ADC, MOSFET, FET, BJT, MOS, K-map, thermal runaway, Voltage-current characteristics of diode, Mux, Flip-flops
Questions Networking:
1. Explain all the packets exchanged/transmitted by your system from the time of boot to the time you try to access google.com. Step 1: Hostname resolution (Get host by name) Generate a DNS query to the DNS server Check for the hostname in primary DNS list If present, return the IP address If not present, forward it to the DNS server who provides the IP address if reply successful, else No name found error occurs Step 2: Client must know how to reach IP by knowing its MAC address Checks the ARP table for MAC address corresponding to the IP address If present, returns the MAC address If not, sends an ARP request to get the MAC address which is added back to ARP table for later purpose Step 3: After MAC address is known, host can communicate for further data transfer
2. What are the various classes of IP addresses? What is sub-netting and super-netting? http://www.techrepublic.com/article/build-your-skills-subnetting-and-supernetting-ip-networks/ http://www.webopedia.com/TERM/S/subnet_mask.html
3. If I send a ping request from one host to another, what exactly happens in the network? The ping application generates ICMP echo packets from host 1 which when reaches host 2 checks for connectivity and returns with the result back to host 1. http://www.c-jump.com/CIS24/Slides/Networking/html_utils/ping.html
4. What are the stages through which OSPF converges? http://routing-bits.com/2009/08/06/ospf-convergence/
5. Explain any one routing protocols in detail. Eg. BGP , OSPF , RIP etc OSPF: http://technet.microsoft.com/en-us/library/cc957894.aspx RIP: http://www.inetdaemon.com/tutorials/internet/ip/routing/rip/ BGP: http://docwiki.cisco.com/wiki/Border_Gateway_Protocol
6. Which routing protocol will you use if you have 50 nodes in each area? Choose between OSPF, RIP and explain. 1. RIP will not work for network having hop count greater than 15 in any path because infinity is defined as 16 in RIP. 2. RIP is good for small, stable and High Speed Networks while OSPF is good for large Dynamic Networks. 3. RIP sends entire routing tale from router to router every 30 seconds (hence Consumes lot of bandwidth) while OSPF sends its link state info every 30 minutes. OSPF routers also send each other small update message when they detect a change in network, moreover when routers exchange updates that reflect changes in the network they converge on a new representation of the topology quickly and accurately. 4. RIP has slow convergence in large networks while it is faster in OSPF. The above reasons support OSPF over RIP.
7. Differentiate between IPv4 and IPv6 protocol, frame and packet, routing and switching, TCP and IP. IPv4 vs. IPv6: http://www.omnisecu.com/tcpip/ipv6/differences-between-ipv4-and-ipv6.php Frame vs. Packet: A frame is a PDU (Protocol Data Unit) in data link layer, whereas a packet is the PDU at the network layer. A data link header and footer are added to packet to create a frame .A frame is therefore said to encapsulate a packet. Routing vs. switching: http://www.lockergnome.com/windows/2005/04/29/what-is-the-difference- between-switching-and-routing/ TCP vs. IP: http://www.differencebetween.net/technology/internet/difference-between-tcp-and-ip/
8. Explain how a host A sends a message/packet to host B a) When both are on same network. b) When both are on different network. a) Host has IP routing table which matches destination host IP to be in same subnet, so Host makes an ARP request if it doesnt have MAC address of destination host and then sends packets to the destinations IP address. b) Hosts IP routing table would have default gateway IP to which the destination host packets would be routed and so on, until the network with destination host is found, and the above procedure is repeated.
9. What is TCP/UDP? How are they different? Explain how TCP handles reliable delivery (explain ACK mechanism), flow control (explain TCP sender/receiver window) and congestion control. TCP: http://condor.depaul.edu/jkristof/technotes/tcp.html UDP: http://ipv6.com/articles/general/User-Datagram-Protocol.htm Difference: http://www.diffen.com/difference/TCP_vs_UDP
10. Explain IP headers. http://www.thegeekstuff.com/2012/03/ip-protocol-header/
11. What is traceroute and ping? How are they different? http://www.cisco.com/c/en/us/support/docs/ios-nx-os-software/ios-software-releases-121-mainline/12778-ping- traceroute.html#traceroute
12. Differentiate between router, bridge, gateway, hub, switch, backbone. http://tech-lightenment.blogspot.in/2011/10/connecting-devices-hub-repeater-switch.html
13. How does a network ensure that all the packet reach in correct order? Which layer is responsible for it? If you were to do be made responsible for packet delivery in correct order how would you ensure without the help of any underlying layer? TCP handles the ordering of packets. (Transport Layer) http://www.informit.com/articles/article.aspx?p=131034&seqNum=5
14. NIC - How it works, internal implementation. http://howdoesinternetwork.com/2011/nic http://www.ece.rice.edu/~willmann/teng_nics_hownicswork.html
15. What is CSMA-CD? Refer Tanenbaum. Study other Multiple Access Protocols as well.
16. Explain the characteristics of socket binding. What are the steps in establishing socket connection in client & server side? http://alumni.cs.ucr.edu/~ecegelal/TAw/socketTCP.pdf
17. What happens in the background when you type the URL www.google.com? 1. Browser checks cache; if requested object is in cache and is fresh, skip to #9 2. Browser asks OS for server's IP address 3. OS makes a DNS lookup and replies the IP address to the browser 4. Browser opens a TCP connection to server (this step is much more complex with HTTPS) 5. Browser sends the HTTP request through TCP connection 6. Browser receives HTTP response and may close the TCP connection, or reuse it for another request 7. Browser checks if the response is a redirect (3xx result status codes), authorization request (401), error (4xx and 5xx), etc.; these are handled differently from normal responses (2xx) 8. If cacheable, response is stored in cache 9. Browser decodes response (e.g. if it's gzipped) 10. Browser determines what to do with response (e.g. is it a HTML page, is it an image, is it a sound clip?) 11. Browser renders response, or offers a download dialog for unrecognized types
18. How many hosts can you accommodate in 192.168.1.43/21? Sol: 2046 (Following video has a nice explanation of how to solve such problems) https://www.youtube.com/watch?v=rs39FWDhzDs
19. What are IP addresses, ARP, NAT? IP Addresses: http://www.tutorialspoint.com/ipv4/ipv4_address_classes.htm ARP: http://www.erg.abdn.ac.uk/~gorry/course/inet-pages/arp.html NAT: http://www.openbsdindia.org/faq/pf/nat.html
20. Flow control protocols. Automatic Repeat Request (Uses ACKs, timeout mechanism and sliding window protocol to determine which frame to retransmit on timeout for receipt of ACK) Stop and wait ARQ Go Back N ARQ Selective Repeat ARQ http://www.tutorialspoint.com/data_communication_computer_network/data_link_control_and_protocols.htm
22. Explain OSI & TCP/IP stack layers + protocols at each layer. http://www.buzzle.com/articles/tcpip-model-vs-osi-model.html
Data Structures and Algorithms:
1. What data structure would you use to implement a routing table? Discuss about optimizing it. Hash table for less number of entries. Paricia trie(radix tree) for large number of entries. Efficient in terms of searching. http://en.wikipedia.org/wiki/Radix_tree
2. Use FILO stack to implement FIFO queue. http://www.geeksforgeeks.org/queue-using-stacks/
3. Reverse a singly linked list. http://www.geeksforgeeks.org/write-a-function-to-reverse-the-nodes-of-a-linked-list/
4. Write a function to sort the linked list given the head as parameter. Do not use extra memory. You have to sort it in place. Try bubble sort.
5. Write a function which sets the bits in an integer when start bit position and end bit positions are passed as argument. For e.g., if I call function setbit(2,4) , it should return 14. (00001110) least significant bit on 1st position and so on. int setbits(int start, int end) { int no = 0; int i;
for (i = start -1; i <= end - 1; i++) { no |= (1 << i); }
return no; }
6. Given a Binary tree, you need to traverse and only print all nodes on given level L. http://www.geeksforgeeks.org/print-nodes-at-k-distance-from-root/
7. A singly linked list has integer as data in each node. Write a function to delete a node from the list given an integer as argument. (Assume all the nodes have unique integers). Find the node whose next node has the data to be deleted, modify the pointers and delete the node. If head has the data, modify head and delete the node.
8. How will you perform the preorder and inorder traversal of binary trees without using recursion? http://www.geeksforgeeks.org/iterative-preorder-traversal/ http://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion/
9. Given an array of numbers, find the subset whose sum is S. http://www.geeksforgeeks.org/dynamic-programming-subset-sum-problem/
10. How do you implement a 2D array dynamically in C? Get the row and column numbers as input from the user. http://www.geeksforgeeks.org/dynamically-allocate-2d-array-c/
11. Write a code to swap every two bits in a byte. (Using bit operators) eg: Input: 10 01 11 00 Output: 01 10 11 00. int y = ((x & 0xAAAAAAAA) >> 1 | (x & 0x55555555) << 1);
12. Implement int strcpy(char* des,char* src) that returns the # of chars copied. int n = 0; while (*src != \0) { *des++ = *src++; n++; } return n;
13. Insert a node in the sorted linked list. http://www.geeksforgeeks.org/given-a-linked-list-which-is-sorted-how-will-you-insert-in-sorted-way/
14. Given a pointer to node to be deleted and no other information (including head pointer), delete the node. http://www.geeksforgeeks.org/in-a-linked-list-given-only-a-pointer-to-a-node-to-be-deleted-in-a-singly-linked-list- how-do-you-delete-it/
15. Reverse the words in a sentence: "hello world" -> "world hello". http://www.geeksforgeeks.org/reverse-words-in-a-given-string/
16. Given a big string (str1) find (s1) and replace by (s2). Example : str = "Hi i am abc and i am in abc" s1 = "abc" s2 = "pqrstuv" So final o/p : str1 = "Hi i am pqrstuv and i am in pqrstuv" Find the number of occurrences of s1 in str (TC : O(n) using KMP algorithm). Say it occurs x times. Store the index at which s1 occurs. Resultant string would be of size strlen(str) + ((strlen(s2) strlen(s1)) * x) Use the stored indexes and start filling the resultant string. On encountering s1, add s2 to resulting string.
17. Each cell of an N x N grid is either a 0 or a 1. You are given two such N x N grids, the initial grid and the final grid. There is a button against each row and each column of the initial N x N grid. Pressing a row-button toggles the values of all the cells in that row, and pressing a column-button toggles the values of all the cells in that column. You are required to find the minimum number of button presses required to transform the grid from the initial configuration to the final configuration, and the buttons that must be pressed in order to make this transformation.
18. 12, 54, 86, 78, 13 How many swaps do you need if you sort this using bubble sort? Sol: 4
19. Find substring of a string. http://www.geeksforgeeks.org/searching-for-patterns-set-2-kmp-algorithm/
20. Given a sorted array a[] find the pairs of number that add up to x. For e.g.: a[]={1,2,4,5,8,15,18,22} x=20 Output: (2,18) , (5,15) http://www.geeksforgeeks.org/write-a-c-program-that-given-a-set-a-of-n-numbers-and-another-number-x- determines-whether-or-not-there-exist-two-elements-in-s-whose-sum-is-exactly-x/ Modify the function to continue search on encountering first pair.
21. How will you set a bit in a number? Eg. int i = 1110 0001. Set 3rd bit. Output: 1110 0101 number |= (1 << (x 1)); // sets x bit in number
22. Given a tree (not a BST), pointers to any 2 nodes in the tree, how will you find their least common ancestor? http://www.geeksforgeeks.org/lowest-common-ancestor-binary-tree-set-1/
23. Perform nibble wise swap in a byte of data. num = num >> 4 | num << 4;
24. Given a string which represents a decimal number, return its binary representation.
25. Count set bits in an integer. http://www.geeksforgeeks.org/count-set-bits-in-an-integer/
31. Explain the edgerank and pagerank algorithms. http://edgerank.net/ http://pr.efactory.de/e-pagerank-algorithm.shtml
32. You have been given 2 numbers, say A and B. How many minimum number of bits do you need to flip to make both equal? XOR the two numbers and count total number of set bits.
C/C++ Questions:
1. What are virtual destructors, multi-map, encapsulation and polymorphism? Virtual destructors: http://www.geeksforgeeks.org/g-fact-37/ Multi-map: http://www.cplusplus.com/reference/map/multimap/ Encapsulation: Binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Polymorphism: ability to present the same interface for differing underlying forms (data types).
2. Differentiate between encryption and encapsulation. Encryption modifies the data itself whereas encapsulation wraps up data, for e.g., using headers and trailers in networking.
3. How to identify memory leak? http://stackoverflow.com/questions/9074229/detecting-memory-leaks-in-c-programs
4. How is private access specifier implemented in memory? http://stackoverflow.com/questions/11486622/how-is-access-for-private-variables-implemented-in-c-under-the- hood
5. Macro definition for minimum of 2 numbers. #define min(a, b) ((a) < (b)) ? (a) : (b)) Brackets around a & b are there as a and b may be any expression, not just numbers.
6. What does the following program do? main () { unsigned int num ; int i ; scanf("%u ", &num); for(i=0;i<16;1++) printf("%d",(num<<i & 1<<15) ? 1:0); } Prints 16 bit binary representation Input : 12 Output: 0000000000001100
7. What is the output of: main() { printf(%x, -1 <<;4); } Sol: fffffff0
8. x = 3; y = 4; x = x++ + ++y; y = ++x + ++y; what are the values of x and y after these are executed ? Sol: x = 9, y = 15
9. What is address alignment? struct xx { int a; char b; }; printf(%d, sizeof(struct xx); What would be output of this printf statement and what would it be if it is union? http://www.geeksforgeeks.org/structure-member-alignment-padding-and-data-packing/ Structure size: 8 Union size: 4
10. Implement malloc() and free() functions. How is the allocation done? What data structures are used? How will you know how much memory has to be freed, like in free (ptr), how much memory has to be freed?
11. Which is faster? while(1) {} or while(2) {} Both condition check for equality to 0, 1 == 0 and 2 == 0, both evaluate to false. Both statements are equivalent. Hence both take same processing time.
12. Implement memcpy.
13. What is difference between a structure and a union? When to use a structure and when to use a union? http://proanswers.org/9/what-is-difference-between-structure-and-union-in-c
14. Given: unsigned char c = 1100 0010; You need to reverse this and return the result. Answer: 0100 0011 (No arrays have to be used) http://www.geeksforgeeks.org/write-an-efficient-c-program-to-reverse-bits-of-a-number/
15. What is the output of following program? main() { unsigned int a = 10; int b = -19; puts ((a+b)>;0?Positive:Negative); } Sol: Positive
Operating System: 1. A mad user tries to allocate 1 GB memory using calloc. But the program fails after allocating about 800MB(approx). Suggest what could have gone wrong? Calloc puts zeros when allocating memory. The program crashes because it tries to put in 0s to all the page table entries. So the page table is 4096 bytes and when all the pages are filled, thats when the program crashes. It does not crash after allocating all the 1GB.
3. I have two threads, both contain data from a database table. One thread performs some operation and update the data in the database table whereas second thread has not yet done any operation. Second thread does operation after some time and wants to update the operation. Since the first thread has already updated the data in the database table, second thread has stale data. How can we manage so that table should have the actual data not the stale data. http://www.careercup.com/question?id=15029824
4. How to identify deadlocks? http://www2.latech.edu/~box/os/ch07.pdf
5. When should we use multi threading? http://www.justobjects.org/cowcatcher/browse/all/slides/java-essential/core/thread/slide.0.4.html
6. What is virtualization? http://searchservervirtualization.techtarget.com/definition/virtualization
7. What is the difference between logical and physical addresses? Physical address is the actual memory address which denotes a memory area in your storage device. The operating system or some other programs use base addresses as a measure to find addresses. Here base address means starting address of a memory block. According to the program written, the CPU generates an address. This address is added with the base address so that it forms the physical address. The address which is generated by the CPU which is added with base address to form the physical address is called as logical address.
8. When does a process create a child process? The purpose behind forking a child process (to the best of my knowledge) is that it allows some operation to be performed simultaneously with the calling program without blocking it. This is useful for instance with a client/server model, where you want the server to be constantly monitoring connections but still be free to do things with the connections it currently has. Unless concurrency is important, forking can add extra resource overhead to a program that would be better used elsewhere.
9. What happens in the background when fork () system call is used? Entire memory is duplicated. It uses copy on write system. Separate copy is made only on first write to child process. Usually code segment of process isnt modified, hence it is shared.
10. What are the different IPC mechanisms? Refer Galvin.
11. When a CPU is powered, how does bootstrap work? http://physinfo.ulb.ac.be/cit_courseware/opsys/os04.htm
12. Differentiate between processes and threads. Process Threads Heavyweight tasks Lightweight processes May consist of multiple threads Within a process Each process has its own address space Many threads may have same address space IPC via message passing IPC via shared memory Process is forked(More time consuming as its a function call) Threads are spawned Context switch takes more time Context switch takes less time
13. Explain concurrency and methods to attain it. What is semaphore? Refer Galvin.
14. What is starvation? Starvation occurs when a scheduler process (i.e. the operating system) refuses to give a particular thread any quantity of a particular resource (generally CPU). If there are too many high-priority threads, a lower priority thread may be starved.
Aptitude: 1. X has 5 chips with 1 defective chip, Y has 4 chips with 2 defective chips. What is the probability of selecting 1 defective chip out of 9 chips that is from Y? Applying bayes theorem: P(Defective chip|Chip from Y) = (P(Chip from Y|Defective chip) * P(Defective chip)) / P(Chip from Y) = 1 / 5
2. p->q V p->r How many set of values for this logic gives true value? Sol: 7 set of values for p, q, r
3. Two sets {1, 2, 3, 4} and {4, 5}. What is the total number of elements in cartesian product of these two sets. Sol: 8
4. There are 2 white balls and 3 red balls in box A, 3 red and 4 white in box B. Find the probability of selecting white ball from box B. Sol: 4 / 7
5. abc+abc+abc+abc Minimize this expression. Sol: ab + bc
6. You are standing in the left bottom corner. You need to reach the destination in the top right corner. You can move either in upward or east direction. In how many possible combinations can you reach there? Your answer should be generic to any value of n.
Some EC questions: 1. Which terminal of FET is forward biased and which is reversed? 2. What is a Reverse Recovery Effect in a diode? Explain how a diode may be used for Power conversion. 3. What are rectifiers? What are the advantages and disadvantages of a Cockcroft Walton Voltage Multiplier?
Puzzle: 1. People (costs: 10,5,3,2,1) trying to get across a bridge within 21 mins. It's dark and only one person carries a flashlight at any point in time. Two people must cross the bridge, since one has the flashlight. How can they all cross the bridge before it breaks? Send 1, 2 (+2) Bring back 1 (+1) Send 10, 5 (+10) Bring back 2 (+2) Send 1, 3 (+3) Bring back 1 (+1) Send 1, 2 (+2) Total time = 21
2. You have 25 horses and at a time you can do a race of max 5 horses. What are the minimum number of races required to find the top 5 horses? http://www.allinterview.com/showanswers/105254.html