Welcome Message

Hi, welcome to my website. This is a place where you can get all the questions, puzzles, algorithms asked in interviews and their solutions. Feel free to contact me if you have any queries / suggestions and please leave your valuable comments.. Thanks for visiting -Pragya.

March 17, 2009

The best presentation of Happy Life

1. Take 10-30 min walk everyday, and while you walk ...Smile.
2. Sit in silence for at least 10 minutes each day.
3. Spend more time with people over age of 70 and under the age of six.
4. Try to make at least three people smile each day.
5. Realize that life is a school and you are here to learn,pass all your tests. Problems are simply part of curriculum that appear and fade away like algebra class, but the lessons you learn will last a life time.
6. Smile and laugh more. It will keep the energy vampires away.
7. Life isn't fair.. but it's still good.
8. Life is too short to waste time hating someone.
9. You don't have to win every argument. Agree to disagreements.
10. Make peace with your past, so it wont mess up the present.
11. Don't compare your life to others. You have no idea what their journey is all about.
12. No one is incharge of your happiness except you
13. Forgive everyone for everything.
14. What other people think of you is none of your business.
15. Time heals almost everything. Give time, time.
16. However good or bad a situation is, it will change.
17. Your job won't take care of you when you are sick. Your friends will. Stay in touch.
18. The best is yet to come .... BELIEVE.
19. No matter how you feel, get up , dress up and show up.
20. Do the right thing.
21. Call your family often.
22. Remember that you are too blessed to be stressed.
23. Enjoy the ride. Remember that life is not Disney world and you certainly don't want a fast pass. Make the most of it. Enjoy the ride.

March 5, 2009

OOPs Questions

1)Explain about Object oriented programming?
Ans : Object oriented programming is one of the most popular methodologies in software development. It offers a powerful model for creating computer programs. It speeds the program development process, improves maintenance and enhances reusability of programs.

2)Explain what is an object?
Ans : An object is a combination of messages and data. Objects can receive and send messages and use messages to interact with each other. The messages contain information that is to be passed to the recipient object.

4) Explain the implementation phase with respect to OOP?
The design phase is followed by OOP, which is the implementation phase. OOP provides specifications for writing programs in a programming language. During the implementation phase, programming is done as per the requirements gathered during the analysis and design phases.

5) Explain about the Design Phase?
In the design phase, the developers of the system document their understanding of the system. Design generates the blue print of the system that is to be implemented. The first step in creating an object oriented design is the identification of classes and their relationships.

6) Explain about a class?
Class describes the nature of a particular thing. Structure and modularity is provided by a Class in object oriented programming environment. Characteristics of the class should be understandable by an ordinary non programmer and it should also convey the meaning of the problem statement to him. Class acts like a blue print.

7) Explain about instance in object oriented programming?
Every class and an object have an instance. Instance of a particular object is created at runtime. Values defined for a particular object define its State. Instance of an object explains the relation ship between different elements.

March 4, 2009

DS interview ques

1) Define data structure in terms of relation?
A : The possible ways in which the data items or atoms are logically related define different data structures.

2) How do you define a vector for a data structure?
The simplest data structure that makes use of computed address to locate its elements in the one – dimensional array and is called as a vector.

3) Define stack
An important sub class of lists permits the insertion or deletion of an element to occur only at one end. A linear list belonging to this sub class is called a stack.

4)State the theorem which is used to determine whether a given expression is valid or not.
A polish suffix formula is well formed if and only if the rank of the formula is “one” and the rank of any proper head of a polish formula is greater than or equal to “one”.

What is a priority queue?
Waiting queue may not operate on a strictly first in first out basis, but on some complex priority scheme based on such factors as what compiler is being used, the execution time required, number of print lines, etc. The resulting queue is called a priority queue.

11) What is linear hashing?
In linear hashing, the table is gradually expanded by splitting the buckets in order until the table has doubled its size.

12) What is splitting?
Splitting refers to the rehashing of a bucket b and its overflow in order to distribute the keys in them among b and one other primary location.

13) What is a one way chain or singly linked linear list?
A list has been defined to consist of an ordered set of elements which may vary in number. A simple way to represent a linear list is to expand each node to contain a link or pointer to the next time.

14) Name two desirable properties of hashing functions.
Some of the desirable properties of a hashing function are speed and the generation of addresses uniformly.

15) What is the distant relationship between a list structure and a digraph?
In particular, a list is a directed graph with one source node corresponding to the entire list and with every node immediately connected to the source code.

16) Define Simulation?
Simulation is the process of forming an abstract model from a real situation in order to understand the impact of modifications and the effect of introducing various strategies on the situation.

17) Define Index area and its subdivisions?
Index area is created automatically by the data-management routines in the operating systems. A number of index levels may be involved in an indexed sequential file. The lowest of index is the track index, which is always written on the first track of the cylinders for the indexed sequential file. The track index contains two entries for each prime track of the cylinder a normal entry and an overflow entry.

18) Given N discs of decreasing size stacked on one needle and two empty needles, it is required to stack all the discs onto a second needle in decreasing order of size. The third needle may be used as temporary storage.
The movement of the discs is restricted by the following rules
(1) A disc may be moved from any needle to any other
(2) Only one disc may be moved at a time
(3) At no time may a larger disc rest upon smaller disc explain the solution?
Ans) The solution to this problem is most clearly seen with the aid of induction, to move one disc, merely move it from needle A to needle C. To move two discs, move the first disc to needle B, move the second from needle A to needle C, then move the disc from needle B to needle C.

19) Define addressing and linear addressing functions?
There are many data structures which can be represented so as to permit the referencing of any element by knowing its position in the structure. The selection operation associated with such a structure is said to possess an addressing function. An addressing function for a data structure consisting of n elements is a function which maps the ith element of the data structure onto an integer between one and n. In the case of a vector, the addressing function f maps the ith element onto the integer I, which is a linear addressing function.

20) What exactly does this procedure BUBBLE_SORT (K, N) does?
Given a vector K of N elements, this procedure sorts the elements into ascending order using the method just described. The variables PASS and LAST denote the pass counter and position of the last unsorted elements respectively. The variable I is used to index the vector elements. The variable EXCHS is used to count the number of exchanges made on any pass. All variables are integer.

http://www.coders2020.com/interview/data_structures_interview_questions

Algo related questions

1)Define and state the importance of sub algorithm in computation and its relation ship with main algorithm?
Ans : A sub algorithm is an independent component of an algorithm and for this reason is defined separately from the main algorithm. The purpose of a sub algorithm is to perform some computation when required, under control of the main algorithm. This computation may be performed on zero or more parameters passed by the calling routine.

2)Define and describe an iterative process with general steps of flow chart?
Ans : There are four parts in the iterative process they are
Initialization: -The decision parameter is used to determine when to exit from the loop.
Decision: -The decision parameter is used to determine whether to remain in the loop or not.
Computation: - The required computation is performed in this part.
Update: - The decision parameter is updated and a transfer to the next iteration results.

3)State recursion and its different types?
Ans : Recursion is the name given to the technique of defining a set or a process in terms of itself. There are essentially two types of recursion. The first type concerns recursively defined function and the second type of recursion is the recursive use of a procedure.

4)Explain the depth of recursion?
Ans : This is another recursion procedure which is the number of times the procedure is called recursively in the process of enlarging a given argument or arguments. Usually this quantity is not obvious except in the case of extremely simple recursive functions, such as FACTORIAL (N), for which the depth is N.

5) State the problems which differentiate between recursive procedure and non-recursive procedure?
Ans : A recursive procedure can be called from within or outside itself, and to ensure its proper functioning, it has to save in same order the return address so that it return to the proper location will result when the return to a calling statement is made. The procedure must also save the formal parameters, local variables etc.

6) What is the difference between Storage structure and file structure?
The representation of a particular data structure in the memory of a computer is called a storage structure whereas a storage structure representation in auxiliary memory is often called a file structure.

http://www.coders2020.com/interview/algorithms_interview_questions

Interview Questions

Q: How many cars are there in the USA?

Sol1: Total number of cars in the USA = (Total number of cars manufactured in the USA + Total number of cars imported in the USA - Total number of cars exported from the USA)

Sol2:
Let
Population = 250 million
People per household = 3
Cars/household = 1
Avg life of car = 10 years

Total cars = ((25 X 10^6) / 3) / 10 - 1

Sol3:
aprox population of USA is x ... and approx population of people ownig cars be say 20 percent or 30 percent ... (minus children, old people, so on) so there so I would go with .25x as number of people with cars and that should give me an approx number of so many cars ...

March 2, 2009

Icosahedron Coloring Problem

Problem :How many different ways can you color an icosahedron with one of three colors on each face?

Sol :

As with any mathematical problem, we must understand the problem before we can attempt to solve it. First, an icosahedron is a regular solid consisting of 20 faces, each of which is an equilateral triangle. We wish to color each face of the icosahedron with one of three colors. A sample icosahedron colored red, green, and blue is pictured at right. We will permit any face to be colored any of the three colors, regardless of the colors of adjacent faces.

An initial guess for the number of ways to color the icosahedron might go as follows: we can choose any of three colors for the first face, and no matter which color we choose, we can choose any of three colors for the second face, so there are 3 · 3 = 9 ways to color the first 2 faces. Continuing in this fasion, we see there are 33 ways to color the first three faces, and in general, 3n ways to color the first n faces. Therefore, there are 320 = 3,486,784,401 ways to color the 20 faces of the icosahedron with three colors.

The problem with the above reasoning is that we have overcounted. If we were coloring an oriented icosahedron (one that is fixed in space), then 320 would be the correct answer. However, the question is much more interesting if we allow our icosahedron to be unoriented, that is, the icosahedron may be rotated in space. Each colored icosahedron can be positioned many different ways, so two colored icosahedrons that at first glance appear different may be the same if one can be rotated so that its coloring matches that of the other. The major task in counting the number of colorings, then, is to determine when two colorings are the same. Therefore, we will study some simpler problems to gain intuition before we answer the question, "How many ways can you color an unoriented icosahedron with three colors?"

Basic Combinatorics

First we will count the ways we can arrange n objects in a line. Clearly we can choose any of n distinct objects to go in the first position, and regardless of our choice, we can choose any of n – 1 for the second position. We can choose any of n – 2 for the third position, and so on, until we obtain the formula n(n – 1)(n – 2) ··· (2)(1) = n! ways to arrange n elements in a line.

Now suppose we wanted to arrange n distinct objects in an unoriented circle (that is, a circle that we can rotate). An equivalent question is, "How many different necklaces can we make with n beads of different colors?" Since we can rotate the necklace, we can choose one specific bead and fix it at the top. We can then choose any of n – 1 beads to be positioned to the right of the first bead, and n – 2 beads for the next position, and so on. The number of unique necklaces then becomes 1·(n – 1)(n – 2) ··· (2)(1) = (n – 1)!

The problem becomes more difficult when we have nonunique items to arrange in a circle. Consider the following two orderings of orange and blue dots arranged in a circle. They are different when fixed in space, but as necklaces made from orange and blue beads, they are the same, since we can rotate one to align it with the other. This example forces us to consider the symmetries of elements arranged in a circle.

Answer: 58,130,055



http://www.mrwright.org

Aptitude Question

Q: )
1
1 1
2 1
1 2 1 1
1 1 1 2 2 1
What's the next line?
Ans : 312211.
This is the "look and say" sequence in which each term after the first describes the previous term: one 1 (11); two 1s (21); one 2 and one 1 (1211); one 1, one 2, and two 1's (111221); and so on.

Q : Which of the following expresses Google's over-arching philosophy?

a) I'm feeling lucky

b) Don't be evil

c) Oh, I already fixed that

d) You should never be more than 50 feet from food

e) All of the above

Answer: b

GLAT : Google Labs Aptitude Test

Linked List questions(Good one)

Q2 : You are give a node in a linked list and you need to delete it from the list..

Sol: the problem is that we have to delete the node.. but dont know the node before that ... so what we can do is copy the content of the node next to it in the current node .. and simply delete the next node...instead of transfering all teh content iteratively till the end.

Reference :http://www.tekpool.com/node/107

Q3: How to find common node in intersecting linked lists
Sol : There is no need to reverse the link lists. All we need to do is to first calculate len=len1-len2 (len1>len2, as discussed above). Point p1 and p2 to list1 (the longer one) and list2 respectively. Then step only p1 for "len" no. of nodes. After this we are guaranteed that p1 and p2 are equidistant from the common node. So now start stepping p1 and p2 simultaneously until p1==p2. This will the common node. This is a simple O(n) solution.

Linked List Interview questions

Question : how does one find a loop in a singly linked list in O(n) time using constant memory? you cannot modify the list in any way (and constant memory means the amount of memory required for the solution cannot be a function of n.)

Sol: One way to detect a loop is to iterate over the list with 2 pointers at the same time where one is iterating at double speed. If the 2 pointers are ever equal after they iterate once and before they both reach an end, there's a loop.

However , this may not be the best solution if the loop is very long as we ll have to iterate with in the loop many times. So, a better approach would be to associate a variable with each node and change or set its value once the node is encountered. So If we encounter a node whose variable value has already been set, that means we ve already traversed that node and thus be sure that loop exists.