Wednesday, 27 November 2013

Question on Summing up a series

Find the sum of the expression


(A) 7
(B) 8
(C) 9
(D) 10

Answer : (B)

Explanation : 

The expression can be written as :





= [sq_root(2) - sq_root(1) ] + [sq_root(3) - sq_root(2) ] + [sq_root(4) - sq_root(3) ] + ... + [sq_root(81) - sq_root(80) ]
= sq_root(81)  - - sq_root(1)
= 9 - 1
= 8

Hence the answer is 8.

Question on Speed & Distance

A tourist covers half of his journey by train at 60 km/h, half of the remainder by bus at 30 km/h and the rest by cycle at 10 km/h. The average of the tourist in km/h during his entire journey is

(A) 36
(B) 30
(C) 24
(D) 18

Answer: (C)

Explanation :

Lets assume the distance = X

Time it took for the tourist to cover first part of the journey = (X/2)/60 = X/120
Time it took for the tourist to cover second part of the journey = (X/4)/30 = X/120
Time it took for the tourist to cover third part of the journey = (X/4)/10 = X/40

Total time it took for the journey = X/120 + X/120 + X/40 = 5X/120

Average speed of the journey = Distance/ Time = X / (5X/120) = 120/5 = 24 Kmph

Question on Probability

Out of all the 2-digit integers between 1 and 100, a 2-digit number has to be selected at random. What is the probability that the selected number is not divisible by 7?

(A) 13/90
(B) 12/90
(C) 78/90
(D) 77/90

Answer : (D)

Explanation:
Number of 2 digit numbers between 1 and 100 = 90

2 digit numbers between (10 and 99) that are divisible by 7 : 7, 14, 21, 28, 35, 42, 49, 56, 73, 70, 77, 84, 91, 98

Number of 2 digit numbers between (10 and 99) that are divisible by 7 = 13.

Number of 2 digit numbers between (10 and 99) that are NOT divisible by 7 = 90 - 13 = 77

So, the probability that a number is NOT divisible by 7 = 77/90

Question on English : 3

Which one of the following options is the closest in meaning to the word given
below?
Nadir
(A) Highest (B) Lowest (C) Medium (D) Integration

Answer: (B)

Explanation : 

Nadir is the lowest point on a curve.

Question on English

Were you a bird, you ___________ in the sky.
(A) would fly (B) shall fly
(C) should fly (D) shall have flown

Answer: (A)

Question on English

Complete the sentence:
Universalism is to particularism as diffuseness is to ________
(A) specificity (B) neutrality (C) generality (D) adaptation

Answer: (A)
The relation is that of antonyms

Question on Series

What will be the maximum sum of 44, 42, 40, ... ?

(A) 502
(B) 504
(C) 506
(D) 500

Answer: C

Explanation :
44 + 42 + 40 + 38 + ..... + 4 + 2 + 0 + (-2) + (-4) + ....

This series is maximum when the series reaches 2.

So, the sum of
= 44 + 42 + 40 + 38 + ..... + 4 + 2
= 2 (22 + 21 + 20 + .... + 1)
= 2 (22 * 23) /2
= 506

Topics to revise :
Arithmetic Expressions

Question on Logical Expressions

What is the logical translation of the following statement?
                              “None of my friends are perfect.”







Answer : D

Explanation :
This question is not properly explained. Looks like F(X) returns TRUE if X is a friend and P(X) returns TRUE is X is prefect.

Analyzing Options Method
Option A :
This options says that, there exist a person X such that he is a friend to me AND he is not perfect. This sentence basically says :"Some of my friends are not perfect". So, obviously it is not saying “None of my friends are perfect.”.

Option B :
This options says, there is a person who is not a friend to me but he is perfect. Means "Some of people who are not friends with me are perfect". Obviously it does not say “None of my friends are perfect.”.

Option C :
This option says, there exist a person X who is not a friend to me and he is not perfect as well. Means "Some of people who are not friends with me are not perfect". Obviously it does not mean “None of my friends are perfect.”.

Option D :
This option basically says, there does not exist a person who is friends with me and perfect as well. That means "None of my friends are actually perfect". There could be persons who are friends with me but they are not perfect OR they are perfect but they are not friends with me. This is exactly we are looking for.

Derivation Approach
 “None of my friends are perfect.”
=> Vx (F(x) --> ~P(x)) [V means For All, ~ is negate operation]
=> Vx(~F(x) v ~P(x))
=> ~Ex(F(x) ^ P(x)) [E means There Exist]

Topics to revise :
Logical Expressions

References :


Question on Programming

Consider the following function


Answer : B

Explanation :

Loop A runs Log N times if you watch closely.
[ J becomes 2, 4, 8, 16, ...., 2^X. It stops when 2^X = N. That is X = Log N.]

Loop B runs for n/2 times. Each time Loop A runs it increments K by n/2.

So, value of K is approx, n/2 times the statement inside A runs.
=> n/2 * Number of times Loop B runs * Number of times Loop A runs
=> n/2 * n/2 * Log N
=> O(n^2 Log N)

Topics to revise :
C language

References :
None as of now

Question on Basic Graph Theorems

Which of the following statements is/are TRUE for undirected graphs?

P  : Number of odd degree vertices is even.
Q : Sum of degrees of all vertices is even.

(A) P only
(B) Q only
(C) Both P and Q
(D) Neither P nor Q

Answer: C

Explanation :

Example Method
Example 1:
P: number of add degree vertices = 2 (Even) => P is valid
Q: Sum of degrees of all vertices = 1+2+2+1 = 6 (Even) =>Q is valid




Example 2:
P: number of add degree vertices = 0 (Even) => P is valid
Q: Sum of degrees of all vertices = 2+2+2 = 6(Even) =>Q is valid





Example 3:
P: number of add degree vertices = 2 (Even) => P is valid
Q: Sum of degrees of all vertices = 2+2+3+3+2 = 12 (Even) =>Q is valid





Direct Proof Method
Prove P : Number of odd degree vertices is even.
Lets assume there are n nodes in undirected graph and n1 nodes are of add degree. This information can be put in an equation format as shown below.


We know that part C of the expression is even number as a undirected edge corresponds to 1 degree to each of the nodes attached.

B part of the expression is also even number because degrees of all vertices of Vn1+1 to Vn are even numbers.

If we observe A part of the expression, deg(Vi) for i=1 to n1 are odd numbers. To make the whole expression (A) even n1 has to be a even number.

Hence, the number of nodes (n1) of off degree are even.

Prove Q : Sum of degrees of all vertices is even. 
This property is obvious from the fact that while counting the degress of vertices, each edhe is counted twice (once at each end).

Topics to revise :
Undirected Graphs and Basic Theorems

References :
Please read Chapter 1: Introduction (Page 8) in Graph Theory by N.Deo

Question on Graphs & Probability

Consider an undirected random graph of eight vertices. The probability that there is an edge between a pair of vertices is ½. What is the expected number of unordered cycles of length three?

(A) 1/8
(B) 1
(C) 7
(D) 8

Answer: C

Explanation :
To make a cycle of 3, we need 3 vertices.

The number of such sets of 3 vertices from set of 8 is = 8C3
[Not 8P3, because the order of nodes is not important]



For such each set of such 3 vertices, a loop/cycle will be made only of 3 edges exist between those nodes. Probability of having a cycle between those 3 nodes is = (1/2)(1/2)(1/2) = 1/8

Expected number of cycles will be = 8C3 * (1/8) = 7



Topics to revise :
Probability
Undirected Graphs and Cycles

References :

Monday, 25 November 2013

Question on Digital Circuits

A RAM chip has a capacity of 1024 words of 8 bits each (1K × 8) . The number of 2 × 4 decoders with enable line needed to construct a 16K × 16 RAM from 1K × 8 RAM is

A. 4
B. 5
C. 6
D. 7

Answer : (B)

Explanation :
Basic RAM chip size = 1K × 8
RAM to construct = 16K × 16

For each word in the new RAM, word size is 16 bits, So you need to put 2 RAMs (1K × 8) to create (1K × 16).We can put such 16 dual RAMs to create 16K × 16.i.e., 16 X (1K × 16).

To address 16K locations in 16K × 16 we need 14 bits. 10 bits will be used to to locate the word in 1K × 16 locations. Rest of the 4 bits will need to be used to identify one of the 16 locations. For this we will need 4×16 DECODER.

But we need to solve this problem with 2×4 decoders. You can arrange (or will need) 5 such 2×4 decoders to use 4×16 decoder.


Hence we need 5 2×4 decoders. Answer: B.

Topics to revisit :
Decoders
Encoders
Multiplexers
DeMultiplexers

References :

Question on sorting

The number of elements that can be sorted in Θ (log n) time using heap sort is

(A) Θ (1)
(B) Θ ( sq_root(log n) )
(C) Θ (log n/(log log n))
(C) Θ (log n)

Answer: C.

Explanation :

Sorting complexity of heap sort is O(n logn).

Lets assume that x number of elements can be sorted in log n time.
i.e., O(x log x) = O(log n)

Substitution method
Option A : x = O(1)

Complexity to sort the array of O(1) elements using heap sort is O(1 log(1)) = O(1). This is not an answer as O(log n) != O(1).

Option B : x = O (sq_root(log n))
Complexity to sort the array of O (sq_root(log n)) elements using heap sort is sq_root(log n)) log (sq_root(log n))) = O( sq_root(log n)) * log (log n) ) != O(log n)

Option C : x = Θ (log n/(log log n))
Complexity to sort the array of Θ (log n/(log log n)) elements using heap sort is
     =  O ( log n/(log log n) log (log n/(log log n)) )
     =  O ( log n/(log log n)  * [ log (log n) -  log (log log n)]
     =  O ( log n - [logn * log (log log n)/log log n)] )
     =   O (log n).

Option D : x = Θ (log n)
Complexity to sort the array of Θ (log n) elements using heap sort is
      = O (log n * log (log n)) != O(log n)
   
It is clear that C is the answer.

Topics to revisit :
Time complexity
Sorting
Heap sort

References :

Question on Semaphores

34. A certain computation generates two arrays a and b such that a[i]= f (i) for 0 ≤  i  < n and b[i] = g( a[i] ) for 0 ≤  i  < n . Suppose this computation is decomposed into two concurrent processes X and Y such that X computes the array a and Y computes the array b. The processes employ two binary semaphores R and S, both initialized to zero. The array a is shared by the two processes. The structures of the processes are shown below.

Process X:
private i;
for  (i  = 0; i < n; i++)  { 
    a[i] = f(i);
    ExitX(R, S);
}

Process Y:
private i;
for  (i  = 0; i < n; i++)  { 
    Entry(R, S);
    b[i] = g(a[i]);
}

Which one of the following represents the CORRECT implementations of ExitX and EntryY ?

(A)
ExitX (R, S) {
    P(R) ;
    V(S) ;
}

EntryY (R, S) {
    P(S) ;
    V(R) ;
}

(B)
ExitX (R, S) {
    V(R) ;
    V(S) ;
}

EntryY (R, S) {
    P(R) ;
    P(S) ;
}

(C)
ExitX (R, S) {
    P(R) ;
    V(R) ;
}

EntryY (R, S) {
    V(S) ;
    P(R) ;
}

(D)
ExitX (R, S) {
    V(R) ;
    P(S) ;
}

EntryY (R, S) {
    V(S) ;
    P(R) ;
}

Answer : (C)

Explanation :

Lets see the difinition of Semaphore Wait (P) and Signal (V)

P(S) {
        While (S <= 0) ; //no op
         S--;
}

V(S) {
        S++;
}

If semaphore initialized to n, usually n processes can enter the critical section guarder by P(S).

Now, Lets examine the options.

Option A :

Process X:
private i;
for  (i  = 0; i < n; i++)  { 
    a[i] = f(i);
    P(R) ;
    V(S) ;
}

Process Y:
private i;
for  (i  = 0; i < n; i++)  { 
    P(S) ;
    V(R) ;
    b[i] = g(a[i]);
}

As you can see both the processes X and Y, wait for P(R) and P(S) respectfully as R and S are intialized to 0. This is like a deadlock situation.

Option B
Process X:
private i;
for  (i  = 0; i < n; i++)  { 
    a[i] = f(i);
    V(R) ;
    V(S) ;
}

Process Y:
private i;
for  (i  = 0; i < n; i++)  { 
    P(R) ;
    P(S) ;
    b[i] = g(a[i]);
}

As you can see, process Y cannot go further as it waits on R (and S). Process X can release those semaphores and process Y can go inside. This works well in normal scenario. But, it could be possible that after first execution of ExitX, process X can continue and try to execute ExitX before Y can execute EntryY. Since this is a binary semaphore (which can possibly have only two values), this is a invalid use-case.

Option D
Process X:
private i;
for  (i  = 0; i < n; i++)  { 
    a[i] = f(i);
    V(R) ;
    P(S) ;
}

Process Y:
private i;
for  (i  = 0; i < n; i++)  { 
    V(S) ;
    P(R) ;
    b[i] = g(a[i]);
}

The same invalid use-case can happen in this scenario as well. Process X runs V(R) and Process Y runs V(S) and then X can execute P(S) can go through the for loop again and try to run V(R). But that would be invalid as R is already 1.

Option C:
Process X:
private i;
for  (i  = 0; i < n; i++)  { 
    a[i] = f(i);
    P(S) ;
    V(R) ;
}

Process Y:
private i;
for  (i  = 0; i < n; i++)  { 
    V(S) ;
    P(R) ;
    b[i] = g(a[i]);
}

Process Y would go first here and execute V(S) and then it waits on P(R). Process X then executes P(S) and executes V(R) and continues. Process Y then can excute P(R) now and initialize b[i]. Now, X would come back at P(S) again and waits and similarly process Y would go through the for loop and executes V(S). This way X and Y execute altenatively one after the other i.e., X initializes a[0] and then Y generates b[0] and X generates a[1] etc.

Topics to Revise :
Semaphore

References :

Question ? on Semaphores

A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads x from memory, increments by one, stores it to memory, and then terminates. Each of the processes Y and Z reads x from memory, decrements by two, stores it to memory, and then terminates. Each process before reading x invokes the P operation (i.e., wait) on a counting semaphore S and invokes the V operation (i.e., signal) on the semaphore S after storing x to memory. Semaphore S is initialized to two. What is the maximum possible value of x after all processes complete execution?
(A) –2
(B) –1
(C) 1
(D) 2

Answer: (D)

Explanation :

S is a counting semaphore initalized to 2 i.e., Two process can go inside a critical section protected by S.

W, X read the variable, increment by 1 and write it back.
Y, Z can read the variable, decrement by 2 and write it back.

Pseudo code W
1.    Wait(S)
2.       Read(x) //into a register
3.        x++
4.      Write(x)
5.    Release(S)

Pseudo code X
1.    Wait(S)
2.       Read(x) //into a register
3.        x++
4.      Write(x)
5.    Release(S)

Pseudo code Y
1.    Wait(S)
2.       Read(x) //into a register
3.         x = x - 2
4.      Write(x)
5.    Release(S)

Pseudo code Z
1.    Wait(S)
2.       Read(x) //into a register
3.        x = x - 2
4.      Write(x)
5.    Release(S)

Whenever Y or Z runs the count gets decreased by 2. So, to have the maximum sum, we should copy the variable into one of the processes which increases the count, and at the same time the decrementing processed should run in parallaly, so that whaterver they write back into memory can be overridden by incrementing process. So, in effect decrement would never happen.

This is how it should be done:
W executes statement 1 : Decreases the semaphone count by 1. S = 1 now.
W executes statement 2 : Reads x from memory and copies into internal register.
Y executes statement 1 :  Decreases the semaphore count by 1. S = 0 now. Now, both W, Y are in critical section and no other process can go inside it.
Y executes statements 2-4 : Reads x (i.e. 0), decrements it by 2 and writes back. Now, x = -2
Y executes statement 5 : Releases semaphore i.e., increments by 1. So, S = 1. Now, some other process can go inside ciritcal section.
Z executes statement 1 :  Decreases the semaphore count by 1. S = 0 now. Now, both W, Z are in critical section and no other process can go inside it.
Z executes statements 2-4 : Reads x (i.e. -2), decrements it by 2 and writes back. Now, x = -4
Z executes statement 5 : Releases semaphore i.e., increments by 1. So, S = 1. Now, some other process can go inside cirtical section.
W executes statement 3-4 : Increments x (i.e., 0, which it read long back) to 1, writes it back to memory. x = 1.
W executes statement 5 : Releases semaphore i.e., increments by 1. So, S = 2. Now, some other processes can go inside cirtical section.
X executes statement 1-5 : X reads the value of x (i.e., 1) and increments it by 1 and writes back to memory. x = 2 now.

this way the value of x gets maximized. Thus the answer is (D)

Topics to Revise :
Semaphores
Critical Section
Concurrent Executions

References :

Question on Logical expressions

Which one of the following expressions does NOT represent exclusive NOR of x
and y?

(A) xy  + x 'y '
(B) x  ⊕ y '
(C) x ' ⊕ y
(D) x ' ⊕ y '

Answer : (D)

Explanation :

Elimination Method

Option A : xy + x'y' => This is nothing but (x NOR y)

Option B : x ⊕ y' = x(y')'+x'(y') = xy+x'y' = X NOR y

Option C: x' ⊕ y = x'(y)'+(x')'y =x'y'+xy= X NOR y

Option D:  x ' ⊕ y ' = x'(y')'+(x')'y'=x'y+xy' = x ⊕ y <> x NOR y

So, answer is D.

Truth Table Method
Lets write truth tables for each of those expressions.

Truth tables for the expressions in question :

As you can see, except expression in (D), all expressions match x NOR y. So, answer is (D)

Topics to revise :
Logical Expressions
Truth Tables

References :

Tuesday, 12 November 2013

Question 16 on Deadlock

Three concurrent processes X, Y, and Z execute three different code segments that access and update certain shared variables. Process X executes the P operation (i.e., wait) on semaphores a, b and c; process Y executes the P operation on semaphores b, c and d; process Z executes the P operation on semaphores c, d, and a before entering the respective code segments. After completing the execution of its code segment, each process invokes the V operation (i.e., signal) on its three semaphores. All semaphores are binary semaphores initialized to one. Which one of the following represents a deadlock-free order of invoking the P operations by the processes?

(A) X : P(a) P(b) P(c)    Y : P(b) P(c) P(d)   Z : P(c) P(d) P(a)
(B) X : P(b) P(a) P(c)    Y : P(b) P(c) P(d)   Z : P(a) P(c) P(d)
(C) X : P(b) P(a) P(c)    Y : P(c) P(b) P(d)   Z : P(a) P(c) P(d)
(D) X : P(a) P(b) P(c)    Y : P(c) P(b) P(d)   Z : P(c) P(d) P(a)

Answer: (B)

Explanation :
To solve this problem, we need to go through each of the options and check if they can create a deadlock at any point of their executions.

(A) X : P(a) P(b) P(c)    Y : P(b) P(c) P(d)   Z : P(c) P(d) P(a)
Lets assume X starts the process and executes P(a) and then Y executes P(b) and Z executes P(c). Now, X can not go forward because Y has a lock on b, and Y cannot go forward and execute P(c) because Z holds a lock on c. Now, the only process that can go forward is Z, so it executes P(d). But it cannot go further and execute P(a) because X holds the lock a. Now all the three processes cannot go ahead as they dependency on each other. Thus this method of access creates deadlocks.

(C) X : P(b) P(a) P(c)    Y : P(c) P(b) P(d)   Z : P(a) P(c) P(d)
Lets assume X starts processing with P(b) and then executes P(a). And then Y picks up P(c) and then waits on b to execute P(b) because b is locked by X -- where as X cannot go forward because it needs to execute P(c) but it was locked by Y. So, there is cleat cycle of dependencies between X and Y causing a deadlock situation.

We can also find a deadlock situation involving all of three processes as well. X executes P(b), Y executes P(c) and Z executes P(a). X cannot go forward now because Z holds the lock on a. Z cannot go forward and execute P(c) because Y holds lock on c. Similarly, Y cannot go ahead and execute P(b) because X holds lock c. As you can see, this is a deadlock situation. Also, clearly it also has circular cycle of dependencies.

(D) X : P(a) P(b) P(c)    Y : P(c) P(b) P(d)   Z : P(c) P(d) P(a)
Similar to option C, this also has a deadlock problem. X executes P(a) and P(b) and Y executes P(c). X cannot go forward now because c is locked by Y and Y cannot go forward because b is already locked by X, thus causing a deadlock situation between X & Y.

Apart from this other deadlock situations can also be found (e.g., X & Z in the circular loop waiting for lock on c and a respectively).

(B) X : P(b) P(a) P(c)    Y : P(b) P(c) P(d)   Z : P(a) P(c) P(d)
In this situation, we cannot find any deadlock. So, this is our answer.

Topics to revise
Semaphores
Deadlocks

References

Question 15: Clustered Indexes

An index is clustered, if

(A) it is on a set of fields that form a candidate key.
(B) it is on a set of fields that include the primary key.
(C) the data records of the file are organized in the same order as the data
(D) the data records of the file are organized not in the same order as the data

Answer: (C)

Explanation:
Clustered index is index whose search key specifies the sequential order of the file. Clustered index key is usually but not necessarily the primary key (link). Hence the right answer is C.

Lets evaluate the options one by one.
(A) it is on a set of fields that form a candidate key : ?
(B) it is on a set of fields that include the primary key.: If the index is on primary key (or on the fields including the primary key), it is definitely a clustered index. But if it a clustered index, it is not necessary that it would include the primary key.
(C) the data records of the file are organized in the same order as the data : This is correct
(D) the data records of the file are organized not in the same order as the data: This is not true according to the definition of clustered index.

Concepts to revise
Indexing & Hashing

References

Question 14: Transport & Datalink layer

Assume that source S and destination D are connected through two intermediate routers labeled R. Determine how many times each packet has to visit the network layer and the data link layer during a transmission from S to D.

(A) Network layer – 4 times and Data link layer-4 times
(B) Network layer – 4 times and Data link layer-3 times
(C) Network layer – 4 times and Data link layer-6 times
(D) Network layer – 2 times and Data link layer-6 times

Answer : (C)

Explanation :

As you can see in the above diagram, The packet goes to Network Layer 4 times and Data Link layer 6 times.

Why network layer is considered as only once and data link layer is considered twice ?
Once the message comes to Network layer, it tries to connect to R's network level. Network level sends message via Data link layer.

Pseudo Code for network layer at the Source (S)
Find R
Send Message to R
                 Send Message via Datalink layer.

Pseudo Code for network layer at the Receiver (R)
Ready to receive messages.
Receive Message from Source
               Message is received via Datalink layer.
Find  next R
Send Message to next R
              Send Message via Datalink layer.

As you can see datalink layer gets called twice for the message transfer (or pass through), but message gets processed only once at the network layer.

Concepts to Cover :
TCP/IP Stack
Datalink layer
Transport layer
Physical layer

References :

Question 13: Public Key Encryption

Using public key cryptography, X adds a digital signature σ to message M, encrypts <M, σ>, and sends it to Y, where it is decrypted. Which one of the following sequences of keys is used for the operations?

(A) Encryption: X’s private key followed by Y’s private key; Decryption: X’s public key  followed   by  Y’s  public key
(B) Encryption: X’s private key followed by Y’s public key; Decryption: X’s public key followed by Y’s private key
(C) Encryption: X’s public key followed by Y’s private key; Decryption: Y’s public key followed by X’s private key
(D) Encryption: X’s private key followed by Y’s public key; Decryption: Y’s private key followed by X’spublic key

Answer : (D)

Explanation :
The encryption & decryption logic in the options are related to Public Key encryption. Public keys are universally available but private keys are kept with the key owners.

When X needs to send message to Y, X first needs to encrypt it with their own private key and Y's public key and Y needs to apply decrypt the message using the keys in reverse order i.e., first with its own private key and then X's public key.

Important point to note here is that decryption needs to be done in the reverse order.

Clearly D is the answer.

Elimination approach
(A) Encryption: X’s private key followed by Y’s private key; Decryption: X’s public key  followed   by  Y’s  public key : This is clearly wrong because X does not access to Y's private key.

(B) Encryption: X’s private key followed by Y’s public key; Decryption: X’s public key followed by Y’s private key : This is clearly wrong answer as well, because Y is not decrypting in the reverse order. Y is decrypting the message with X's private key which is encrypted with Y's public key.

(C) Encryption: X’s public key followed by Y’s private key; Decryption: Y’s public key followed by X’s private key : This is wrong answer as well as X does not access to Y's private key.

(D) Encryption: X’s private key followed by Y’s public key; Decryption: Y’s private key followed by X’spublic key : This is the correct answer as the encryption and decryption are done with correct keys and decryption was also done in reverse order.

References :