Tuesday , 21 October 2014
Home » Tag Archives: Interview Question

Tag Archives: Interview Question

what happens, after you type a URL into a browser : Interview Question

Q.) Explain what happens, step by step, after you type a URL into a browser  Use as much detail as possible 

Ans

There’s no right, or even complete, answer for this question   This question allows you to go into arbitrary amounts of detail depending on what you’re comfortable with   Here’s a start though:

  1. Browser contacts the DNS server to find the IP address of URL
  2. DNS returns back the IP address of the site
  3. Browser opens TCP connection to the web server at port 80
  4. Browser fetches the html code of the page requested
  5. Browser renders the HTML in the display window
  6. Browser terminates the connection when window is closed

One of the most interesting steps is Step 1 and 2 – “Domain Name Resolution ”  The web ad-dresses we type are nothing but an alias to an IP address in human readable form   Mapping of  domain  names  and  their  associated  Internet  Protocol  (IP)  addresses  is  managed  by  the Domain Name System (DNS), which is a distributed but hierarchical entity .

Each domain name server is divided into zones   A single server may only be responsible for  knowing the host names and IP addresses for a small subset of a zone, but DNS servers can work  together  to  map  all  domain  names  to  their  IP  addresses    That  means  if  one  domain name  server  is  unable  to  find  the  IP  addresses  of  a  requested  domain  then  it  requests  the information from other domain name servers.

Delete a node in the middle of a single linked list : Interview Question

Q.) Implement an algorithm to delete a node in the middle of a single linked list, given  only access to that node

ans.)

The solution to this is to simply copy the data from the next node into this node and then
delete the next node

NOTE: This  problem  can  not  be  solved  if  the  node  to  be  deleted  is  the  last  node
in the linked list  That’s ok—your interviewer wants to see you point that out  You
could consider marking it as dummy in that case   This is an issue you should dis-
cuss with your interviewer

public static boolean deleteNode(LinkedListNode n) {
  if (n == null || n.next == null) {
    return false; // Failure
  } 
  LinkedListNode next = n.next; 
  n.data = next.data; 
  n.next = next.next; 
  return true;
}