Print Page | Close Window

Data Structure and Algorithms

Printed From: One Stop GATE
Category: GATE AT A GLANCE
Forum Name: Basic GATE Info
Forum Discription: All the basic information about GATE for the starters.
URL: http://forum.onestopgate.com/forum_posts.asp?TID=1815
Printed Date: 07Feb2025 at 10:25am


Topic: Data Structure and Algorithms
Posted By: aparna
Subject: Data Structure and Algorithms
Date Posted: 26Nov2007 at 2:31am
Q.1. Data Structure and Algorithms
In a box there are random number of white and black marbles. At a time two marbles are taken out at random and if

A) Both Black: Discard both and insert a white
B) Both White: Discard one and retain one
C) One Black and One White: Discard White and retain Black.

If initially there are nb black and nw white marbles then determine the color of the only marble remaining at the end.

Options
1. white if nb is even
2. white if nw is odd
3. black if nb is even
4. black if nw is odd

Ans: 1

Explanation:
Here parity of black is preserved and the parity of white is neglected.

Lets consider each case
A) Both Black: Discard both and insert a white Parity of back is preserved by discarding both, i.e if there are nb marbles then nb-2 remain. Thus if nb is even, nb-2 is also even. For nw, it becomes nw+1 and hence parity is changed(or is not conserved).

B) Both White: Discard one and retain one Again no change to nb and nw parity is neglected.
C) One Black and One White: Discard White and retain Black. Same applies here also.

Thus, the color of last marble depends on nb and not on nw.

Hence, we get the following table:

nb nw remaining
even even white
even odd white
odd even black
odd odd black

which can be further reduce to :

nb nw remaining
even X white
odd X black



Print Page | Close Window