TCS
Company
Programming
Database
It is a walk-in-interview setup having an interview room with
one chair and a waiting room with a number of chairs. The interviewer interviews
candidates in the interview room. When the interviewer finishes interviewing a candidate,
he dismisses the candidate and goes to the waiting room to see if there are other
candidates waiting. If there are, he brings one of them to his room and interviews him. If
there are no candidates waiting, he returns to his chair in the interview room and
continues reading his last unfinished magazine. If there are no unfinished magazines, he
starts reading a new magazine. After he finishes reading one full magazine, he goes to
sleep.
Each candidate, when he arrives, looks to see what the interviewer is doing. If the
interviewer is reading a magazine, the candidate waits for the interviewer to finish
reading the current page of the magazine. Then the candidate enters the interview room
and asks the interviewer to interview him. If the interviewer is sleeping, the candidate
wakes him up and then asks the interviewer to interview him. If the interviewer is
interviewing another candidate, the candidate goes to the waiting room. If there is a free
chair in the waiting room, the candidate sits in it and waits his turn. If there is no free
chair, then the candidate leaves.
Based on a naive analysis, the above description should ensure that the walk-ininterview
functions correctly, with the interviewer interviewing any candidate who arrives
until there are no more candidates, and then reading magazines and/or sleeping until the
next candidate arrives. In practice, there are a number of problems that can occur that
are illustrative of general scheduling problems. Please discuss those problems and
provide an algorithm to solve those problems.
Note: There are two doors between the interview room and the waiting room.
Tip: Read literature on the Dining Philosophers problem
Read Solution (Total 1)
-
- do
{
wait(candidates[i])
wait(candidates[(i+1)]%n]
...
...
critical section
....
.....
signal(candidate[i])
signal(candidate[(i+1)]%n)
read magzines
}while(true);
- 10 years agoHelpfull: Yes(20) No(6)
TCS Other Question
Why should i hire u ?
The challenge
You will need to phrase your question in multiple forms. In the first form, you can simply
state your question and solution. You will then need to transform question into a more
abstract form. This form can be thought of as a set of instructions that are required for a
computer to be able to solve a problem. You can also transform your question context in
a way that the solution remains the same. In another form, you can transform the
question formula, by retaining the question context. You can also invert the question so
that the formula is inverted. As you immerse yourself in the challenge, you will notice
that a number of interesting combinations of changes can result in a variety of interesting
questions.
In order to create such questions, you need to ask the following questions
1. How can variables be identified?
2. Are there different types of variables?
3. Are there limits to the values that a variable can take?
4. How are the variables related to each other and to the solution?
5. How can the context of the problem be changed? Can the same solution be
obtained by changing the context of the problem?
6. How can you play with the solution formula?
7. Can the problem be made more interesting and educational by adding relevant
textual content from leading international journals or magazines?
Please read the following steps and the example enclosed by which you will be able to
convert a question into an abstract form
1. A portion of a question is said to be generalized when that portion can be
replaced by a variable which can take a set of well defined values. Identify such
variables in the question statement and replace them with variable names such
as variable1, variable2 etc.
E.g. Consider the question “A train travels at 50 Km/hr. Calculate the time it
takes to travel 500 Km”. The underlined portion can be replaced by
another number(s). Hence that portion of the question is said to be generalized.
Note: In this example, we have chosen only one variable which is the speed of
the train. You may be able to identify many such variables in a question.
2. A variable can be one of the following types: text or a number. If you can think of
other types of variables, do not hesitate to declare and use them.
E.g. The original question is transformed into the second form as “A train travels
at Variable1 Km/hr. Calculate the time it takes to travel 500 Km.” In this example,
Variable1 is a number.
3. Declare the identified variables, its type and the possible values it can take. E.g.
Variable1 is a number and it can take values between 50 and 150.
4. You will then need to represent the solution to the question as a function of the
variables identified.
E.g. Answer: 500/Variable1 hours