Compsci Explanations PDF
Compsci Explanations PDF
Availability = MTBF
-------------------
MTBF + MTTR
= 10000
-------------------
10000 + 20
= 99.8 % Available
Overall Answer : D
Solution:
Encapsulation and Inheritance are boon and bane from OO world.
Overall Answer : C
Solution: All sorts except Quick-sort accommodate a series that is already sorted. Try sorting a
series (1,1,1,1,1,1) or series (1,2,3,4,5,6) Quick-sort efficacy reduces to Θ (n2) from Θ (nlogn).
Overall Answer : D
Solution: AST, Attribute Grammar, Semantic Stack and Parse Table all are data-structures that
are used in Parsing stages of a given compiler, they do store some part of information but not
involved in “managing information about variables and their attributes”. Ideally Symbol table
can be seen as a tuple S = (variable, attributes). During all stages information is stored and gets
more refined in Symbol table.
Overall Answer : D
Solution: There is one critical point to note here. What is value of X at the end of current context
of loop ? Consider the following explanation.
It will fail at the Step 5. loop startup condition, so our value of (i) is struck at 5
Overall Answer : B
Solution: This is an interesting problem, only noteworthy point here is a sub-expression.
Overall Answer : C
Solution (8) : if T is BST or Binary Search Tree we have to traverse in In Order way as :
UQXWPVZY (where U is having smallest numerical value and Y having highest). So 4th smallest
is W.
Overall Answer : A
Solution: Any K-ary tree with n-nodes and h-height has Total number of nodes or n given by
h
n= ki expanding this
i=0
So kh denotes how many leaves we will have in k-ary tree and rest all are what we call inner-
nodes or penultimate nodes.
Overall Answer : D
Solution: Virtual Memory was designed for sole purpose of following goals.
1. We have program images greater than available ram. We want a mechanism to start our
program with adjustable image in memory and fetch chunks (what is called pages) on the
fly or by generating trap called faults (now called page-faults). That answers II.
2. MMU or Memory Management Unit will treat program images equally and would divide
into chunks and make it aware to OS. It would not peep into images or chunks. That
answers III.
Overall Answer : A
T(1) = 7
T(n+1) = 3n + T(n)
T(1) = 7
T(2) = 3x1 + T(1) = 3x1 + 7
T(3) = 3x2 + T(2) = 3x2 + 3x1 + 7
...
...
T(n+1) = 3xn + 3x(n-1) .... + 3x1 + 7
so if u see further
= 3x(1+2+3 ... + n) + 7
=f(n2) + C
=Θ (n2)
Overall Answer : C
Solution: In case of Binary logic the total number of bits required to implement 256 different
values are given by log2(256) = 8-bits
log3(256) = 5.0474-bits, but we need to have integral value else we will loose .0474th of a state
so we need to have next higher integer.
Overall Answer : C
1. hash-tables are organized in such a way that when given a key you get a value define by a
mapping function of key and values. This means that key needs to be unique. This
answers A. Efficiency comes from the fact that we are deterministically reducing search
space by providing a unique key ourselves.
2. Certainly insertion, deletion and search is provided as in hash-tables analogous to
dictionary all based upon a certain unique key. That answers B.
3. Consider this Key-range=[1..5] and you are told to fetch all data in this range. The
approach is brute-force exhaustively scanning key 1 to 5 and fetching all data. Is it
efficient ? (think this from the point of view of how hash-table is organized)
4. Symbol tables are nothing but data dictionaries so given a identifier as key, gives its
attributes. That answers D.
5. This is tricky. Think of a two-tier hash table. One that hashes keys of a hash table that has
some values.
Here at top level given a key K1 we will be given a key K2 which will be used to find
actual value. Let the input to Hashtable-1 be two sets of keys (1,2,3,4) and (5,6,7,8)
Our goal is to find a set that says lets say (2,5) has overlapping set of keys. We give our
probable keys that we are looking for to reduce the search space and hence being efficient.
Overall Answer : B
Solution: Address resolution protocol is best understood if we have two subnets and a router in
between them when sub-net 1 sends a packet to router for sub-net 2 following things happen.
There is reverse protocol called BOOTP protocol where we have machine address but we don’t
have IP address. Its used in diskless machines to get OS images from server. All nodes are
initially set to 0.0.0.0 They all have machine address of server but not the IP-address of server,
the router or arbiter for give them IP-address of server for a given hardware address.
Overall Answer : D
Solution: Consider the explanation below. (it’s pretty tricky scheduling of operations)
Let’s view AB + ABC + BC as AB(1+C) + BC. One assumption made here is, (r7, register) has
constant 1 stored prior to this schedule of operation. r0 has A, r1 has B and r3 has C.
Overall Answer : B
Solution: Consider the following explanation.
View efficiency as =
(Time-taken-on-single-processor)/((Time-taken-on-parallel-processor)* (Total-no-of-processors))
Overall Answer : C
A DAG is a graph that has no cycles. Read “Which of the following must be true ?” suggests on
the lines of being necessary condition or “mandatory”. A DAG has a property that at-least one
node has out-degree to be 0 (else it will form a cycle). This means no outgoing edge. This
answers II. Consider following graph.
G=(V,E)
|V|=1
|V|=2
|V|=3
The note-worthy point here is in all graphs, there are some vertices, which are having in-degree to
be 0 that is no in-coming edge. But having an isolated vertex is just matter of choice one makes, it
maybe that the graph has no isolated vertex (see last graph of |V| = 3) or it maybe that it does has
an isolated vertex (see the first graph of |V| = 3). So it’s not mandatory to have it. This answers I
and III.
Overall Answer : D
Write-through policy of caching writes data onto cache and memory both.
Total-no-of-times-the-loop-runs = 256
No-of-bytes-written-per-write = 4 bytes (both cache and main memory)
Total-bytes-written = 256 * 4 = 1024 bytes (both cache and main memory)
Write-back policy of caching writes data onto memory only when cache is flushed. There are two
important points when the cache needs to be flushed.
1. When cache is full (i.e. exceeds cache capacity).
2. When cache entry (cache-line) is invalidated (i.e. when some external source, like other
programs modifies same memory address whose entry is in cache).
In present case cache-line invalidation never happens, as it’s assumed no other source modifies a
given memory address (m), whose entry is already there in cache.
Total-no-of-times-the-loop-runs = 256
No-of-bytes-written-per-write = 4 bytes (only in cache).
Total-bytes-written = 256 * 4 = 1024 bytes (only in cache)
Total-cache-capacity = 2048 bytes
Total-bytes-written < Total-cache-capacity, this suggests that there is no cache-line entry being
invalidated (if there is more than 2048 bytes of data, flush extra bytes to memory)and the cache is
not used fully as there are still 1024 bytes remaining in cache. This results in 0 writes in main
memory.
Decode C1E0 0000 into binary as : 1100 0001 1110 0000 0000 0000 0000 0000
S: 1100 0001 1110 0000 0000 0000 0000 0000; equivalent-in-decimal = 1
E: 1100 0001 1110 0000 0000 0000 0000 0000; equivalent-in-decimal = 131
F: 1100 0001 1110 0000 0000 0000 0000 0000; equivalent-in-decimal = 6291456
Let x S
( is belongs-to relation, where S is set of people such that S = {John, Joan, Jack, James, Jill},
who are either lawyer(s) or liar(s))
∀ (for-all) signifies that any given predicate calculus formula should hold for all members of set
(here set is S), in effect giving it “AND” behavior.
∃ (there-exists) signifies that any given predicate calculus formula should hold for any one of
members or set (here set is S), in effect giving it “OR” behavior.
Conditions
1. P(x) : x is a Liar
2. Q(x) : x is a Lawyer
3. x = John (instance 1)
4. Every member of set has to-be-either of Liar or Lawyer or both.
Consider (∀x P(x) v ∀x Q(x)) this is translated when applying above as below:
1. P(John) v Q(Jack) (since ∀ operator is applied individually and not on whole expression,
so 1 and 2 instances of (x) will have different set-members).
2. Similarly, ∀x (P(x) v Q(x)) is translated to P(John) v Q(John) (here ∀ operator is applied
to whole expression)
3. Any relation of type A → B is equal to A v B ( being NOT operator)
4. Replacing A with point 1 and B with point 2 the outcome is (P(John) v Q(Jack)) v
(P(John) v Q(John))
5. ( (P(John)) ^ (Q(Jack))) v (P(John) v Q(John)) ( ^ being AND operator)
6. ( (P(John)) v (P(John) v Q(John))) ^ ( (Q(Jack)) v (P(John) v Q(John)))
7. (P(John) v Q(John)) ^ ( (Q(Jack)) v (P(John) v Q(John))) is of the form
(A) ^ ( (B) v (A)) which translates to (((A) ^ (B)) v (A)) now A has to be true (cond. 4)
so irrespective of values of B, I (in question) holds true all times.
8. This only proves for 1 instance. Since ∀ operator is equal to “AND” it holds for all set
member values so if result in (7.) is to taken as RJohn, then I (in question) can be treated as
RJohn ^ RJoan … ^ RJill each one of them holding true as explained above.
Similar explanation holds true for III (in question) for ∃ operator. But ∃ defines “OR”
behavior. Also, since only one of the instances (John, Joan, Jack, James, Jill) needs to be true
so III holds true at all times, but each time with different instances. It can be treated as
RJohn v RJoan … v RJill , where any one of them needs to be true. As one of them is proved to
be true already, it’s non-mandatory to have every single single-member to be proved true as ∃
requires any one to be true, thus making it true in all case.
Overall Answer : D
Pass-by-value fetches fresh copies of actual parameters, each time they are used. Does not
modifies actual parameters values (of the calling program) from inside a procedure.
Pass-by-value updates actual parameters, each time they are used. It does modifies actual
parameters values (of the calling program) from inside a procedure.
Choice I is intuitively clear, that if and only A is finite B is finite. (we can’t have a subset
exceeding its parent set)
Choice II requires use of pumping lemma for regular expression, which states as follows
Let z=uvw
Where z = any chosen word from set B lets say aa
Then z <= some N where N is suitably chosen value lets say 3 (length of characters of word aaa
in set A)
And |uv | >= 1 (length of uv to be greater than 1) lets assume u = a and v = a too.
So that gives us
z=uvw = aa ( is null-char)
the lemma says B should also contain strings derived from expansion z = u. vi .w,
let examine this. Putting values of u and v and w as we know from above discussion.
z = a . ai. --> ai+1
for suitable values of (i) we have following pattern
z=a ……………………i=0
z= aa ………………… i=1
z=aaa………………… i=2
z=aaaa………………...i=3
…
please see that for i=1 z belongs to B, can the same be said for i => 2. So it implies that our finite
sets can’t cope up with increasing values of (i) and resulting strings out of it. A finite set can’t
prove beyond a certain point that it would contain strings generated by (z). so it’s not possible to
say A to be finite and would contain all strings generated by (z). Even if we assume A to contain
it (some how). Even then B is just a subset of it, so it possible contains a subset of those words
and hence can’t be regular. So there are two implications.
A cant be deterministically regular when considering finitely. Even if its assumed (for the sake of
proving its B to be regular)
B cant be regular because it contains only subset of A values. One may assume that B to have a
set that contains all value of A, but that’s true only in one case and not all. So its false.
Choice III Similar lemma exists for proving a given language is CFL or not. Certainly its subset
wont be CFL either.
Overall Answer : A
Solution:
1100 1100
(+) 1000 1111
1 0101 1011
Overall Answer : B
Solution:
n
If you see ki forms a G.P or geometric progression, which can be broken down as :
i=1
= k1 + k2 + k3 … + kn
a(rn-1)
---------, where |r| > 1 (which is true in our case, as r = k)
r-1
= C * (kn-1) (C = k/(k-1))
so roughly we have
~ Θ (kn)
Overall Answer : A
Solution :
Overall Answer : E
Overall Answer : D
Solution: Consider the following explanation.
Data-grams does not have lower-bound on size to be equal to MTU. That answers I. II and III are
correct because a data-gram can be of any size and hence can be fragmented and can be reaching
destination out of order (opposite to TCP packets which have sequence numbers) and hence needs
re-assembly there (in effect re-ordering also). TCP packets has a size limitations to be of 64
Kbytes segments.
Overall Answer : E
1. Clique is a complete sub-graph of graph G. To find a largest clique one needs to find set
of vertices that suffice total paths of (n(n-1))/2. This is NP-complete.
2. Finding all spanning tree requires constructing trees T1…TN such that each contains all
the vertex of graph G. There are two algorithms to find a variant of spanning tree called
minimal spanning tree, viz. prim’s algorithm and kruskal’s algorithm only these two have
polynomial time implementation.
3. Graph coloring problem is the problem of finding adjacent nodes and having different
color among them. This is NP class problem.
4. Longest simple cycle in undirected graph G is NP class problem.
5. Short cycle in G correspond to shortest path problem (here this path leads to itself), for
this there are polynomial time algorithms.
Overall Answer : B
Solution: Consider the following explanation.
1. Latency is defined as difference of time between when one submits an instruction and
when one gets the result.
2. Throughput is defined as total number of instructions in given amount of time.
Based upon this, latency of single instruction is more on M-7’s pipeline than on M-5’s pipeline.
This goes onto prove further that programs runs slower on M-7.
Let’s take time T (for measuring throughput, a time-window) = 30 nanosecond, now M-5 has
throughput of 3 instructions in given time of 30 nanosecond (30/10) and M7 has throughput of 4
instructions in given time of 30 nanosecond (30/7.5). Throughput does tell that how many
instructions per second a system executes, but doesn’t tell exact amount of time per instruction
required (time at which one input the instruction and time at which result came out).
A N-stage pipeline
Overall Answer : A
Solution: Consider the following explanation.
1. U will execute as soon as one enters the loop (even if the loop runs once).
2. X has two paths one going out of loop and one returning to U (one of them occurs more
frequently than other and X is sitting at the place where it can either send it back or let it
go out of loop).
With 1 in mind U is bound to run at-least once. With 2 in mind U is expected to run 2 times
(that’s more frequent because X returns to U with greater probability or no. of times).
Expected here tells about most-frequent number of times seeing the graph at first instance.
Overall Answer : D
Solution: Consider the following solution.
(((…(x)…))), where only variable components are number of left and right parenthesis. Top-
down parsing starts with non-terminals and end with final resulting string. It starts to replace left-
hand side non-terminals to suitable right-hand side terminals/non-terminals.
Top-down parsing:
Let the result be ((x)), so in top-down parsing, following steps are applied with respect to
productions. (Start with S).
( )
S
( )
Incase of Bottom-up parsing one starts with result and end with starting symbol. It starts to
replace right-hand side terminal/non-terminal with left-hand side non-terminal.
Bottom-up parsing:
Let the result be ((x)), so in bottom-up parsing, following steps are applied with respect to
productions. (Start with ((x))).
( )
S
( )
The grammar is not ambiguous because the left-most derivation and right-most derivation results
in same parse tree.
Overall Answer : D
x 1x 0
00 01 11 10
x2
1
0
1 1 1 1
There are two literals in this case. (( x1).x0) + (x2.( x0)), where represents logical NOT.
Overall Answer : C
Solution: Consider the following explanation.
Greedy algorithms are algorithms, which make locally optimal choice at each stage with the hope
of finding globally optimal solution. Let’s define locally optimal variables for each of three class
of problems. In general, greedy algorithms have five main-features :
Based upon this spanning-tree, clique and flow problem can be seen as under (in order):
1. Locally optimal variable here is finding a subset of tree that contains all nodes for that
subset and is connected. Intuitively this will have some positive-integer edge weights.
2. Locally optimal variable here is finding a subset of a clique (which is already a sub-graph,
which is complete), which is also complete.
3. Locally optimal variable here is finding a path that for a given stage gives maximum
capacity. Intuitively this will have some positive-integer edge weights.
All the above 5 factors can be applied onto 1 and not onto 2 and 3 for a reason as under:
1. Selection function cannot determine which sub-set to choose by itself in case of clique
finding.
2. Feasibility function also cannot determine validity of a candidate vertex whether it will
form a bigger clique or not.
3. Feasibility function cannot determine whether taking a maximum capacity at a stage will
result in global maximum capacity.
Overall Answer : A
Both 38 and 39 are based upon same question
If an event happens for k-times and probability of each such mutually-exclusive event is (1-p),
then overall probability is = (1-p)K
See “Suppose that in each of the k different executions the output of A is “No”” as the events are
over and one gets a final answer as “No”. It means experiment is over and there is no
“probabilistic” factor remaining. Hence it’s certain that the number is composite. So when an
experiment is bound to occur certainly then probability is 1. “No” is given as output when
number is prime and if one gets “No” in all events of an experiment then, it’s “certain” not
“probable” that the number is not prime.