Article 28 - Programming Interview Questions

This article shares some typical questions that are likely to be asked during a Software Engineering position interview. Prepare for it by understanding each topic.

Compare and Contrast C++ and Java

Although the two programming languages are very similar, there are some subtle differences that you should be aware of. Make sure you are comfortable with each programming language.

In Java, there is a garbage collection thread that periodically collects any unused objects for cleaning. There is no garbage collection in C++; instead, the programmer must explicitly clean up after his or her objects.

C++ allows for multiple inheritance, Java allows for only single inheritance (extending a single class) but can implement multiple interfaces.

Compare and Contrast Thread and Process

A process is a particular instance of a running application/program, it has its only memory space. Likewise, a thread is an instance of a particular program's code, but is not considered an application/program even if the program is singlethreaded.

For this reason, a process may contain one or more threads.

One important difference is that threads (within the same process) is permitted to share data and access one another's stack and memory space. Whereas, a process can only communicate with other processes using inter-process communications such as pipes, files, or sockets.

How to Find nth Last element in a linked list?

A simple approach would be to iterate the list to count how many nodes are in the list and then do a second iteration to stop at the nth last node. This is, unfourtunately, unnecessary.

Definition of a node, to be used in this article.

Instead, we can use a smarter approach. We use two pointers, p1 and p2, where p1 points to the node that is n-1 nodes before p2. Initially, we set p1 and p2 to the head of the list, then iterate p2 n-1 nodes ahead. Then in the second loop, we iterate both p1 and p2. When p2 hits the null node, p1 points to the nth last node, so just return p1 as the answer. If the list does not contain n nodes, then you can return some message during the first loop.

Function that returns the nth last node.

How to determine if a linked list has a circular reference?

We will use two pointers, p1 and p2, where p1 will advance one node and p2 will advance two nodes. The idea is that, if p2 advances twice as fast, it will see p1 eventually (if the list is circular). Make sure to check if p2 points to a null entry in case the list is not circular.

Function that detects circular lists.

After learning each of these topics, you should more confident in answering programming interview questions.

Comments (31)

Posted by anonymous - bookmarks at Friday, March 15, 2013 2:31 AM

scgAnO Very good blog.Thanks Again. Keep writing.

Posted by anonymous - cipro at Friday, March 15, 2013 10:59 AM

Appreciate you sharing, great blog post.Really looking forward to read more.

Posted by anonymous - generic viagra at Friday, March 15, 2013 12:38 PM

Im thankful for the blog post.Really looking forward to read more. Much obliged.

Posted by anonymous - generic cialis no prescription at Friday, March 15, 2013 2:17 PM

Very neat article.Much thanks again. Cool.

Posted by anonymous - 10mg levitra at Friday, March 15, 2013 3:57 PM

Thanks again for the post.Much thanks again. Really Cool.

Post a comment

  • Name:
  • Post:
  • Challenge:

Register or login to post comments easier.


Vantasy World Copyright 2011 - 2017. Vantasy World is a project developed by Vantasy Online. Privacy Policy.