THE GATEBOOK Q&A - Recent questions and answers
http://thegatebook.in/qa/qa
Powered by Question2AnswerAnswered: why *(x+i) is same as &x[i] ??
http://thegatebook.in/qa/2528/why-x-i-is-same-as-%26x-i?show=2549#a2549
it's a typo. correct option is same as<br />
<br />
*(x+i) is same as x[i].Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2528/why-x-i-is-same-as-%26x-i?show=2549#a2549Wed, 20 Sep 2017 11:39:05 +0000Number of Equivalence Relation,Relation Test
http://thegatebook.in/qa/2486/number-of-equivalence-relation-relation-test
Number of Equivalence Relation with 3 elements <br />
<br />
no of ways to partition a set <br />
<br />
{1} {1} {1} -> 1 way<br />
<br />
{3} ->1 way<br />
<br />
{2} {1} ->3 total(1+1+3)<br />
<br />
i am unable to get the logic behind this,plese guideDiscrete Mathshttp://thegatebook.in/qa/2486/number-of-equivalence-relation-relation-testTue, 22 Aug 2017 10:37:58 +0000difficult to write down recursive definition for give problem
http://thegatebook.in/qa/2485/difficult-write-down-recursive-definition-for-give-problem
Suppose an array A={a1,a2,&hellip;&hellip;&hellip;&hellip;an} contains a set of n distinct coins types where each ai &euro; N for 1<=n. Suppose also that a1<a2<a3&hellip;&hellip;&hellip;&hellip;&hellip;<an the coin hanging problem is defined as follows:<br />
<br />
Given W &euro; N , find the smallest numbers of coins from A that adds upto W, given an unlimited number of coins of each type are available. We wish to find minimum number of coins needed from A to get W as c(n,W). Let c(i,j) be the minimum number of coins needed from any subset of first &ldquo;i&rdquo; coin that sum to exactly &ldquo;j&rdquo;.<br />
<br />
An incomplete recursive definition for the function c(i,j) is given below<br />
<br />
C(i,j)=0 if j=0<br />
<br />
=&infin; if i=0 and j&ne;0<br />
<br />
=expr1 if i,j>0 and j<a[i]<br />
<br />
=expr2 if i,j>0 and a[i]<=jData Structures Algorithms and C Programminghttp://thegatebook.in/qa/2485/difficult-write-down-recursive-definition-for-give-problemFri, 18 Aug 2017 07:01:57 +0000Doubt in time complexity
http://thegatebook.in/qa/2484/doubt-in-time-complexity
Given a 2-D array A with n rows and k columns initialized to -1 . what is the Time complexity of f(A,m,m)?<br />
<br />
int f(int **a, int n, int k)<br />
<br />
{<br />
<br />
if((n<=k)|| (k<=1)) return 1;<br />
<br />
if(a[n][k]==-1)<br />
<br />
a[n][k]=f(a,n-1,k)+f(a,n-1,k-1);<br />
<br />
return a[n][k];<br />
<br />
how to write recurrence relation for thisData Structures Algorithms and C Programminghttp://thegatebook.in/qa/2484/doubt-in-time-complexityFri, 18 Aug 2017 04:42:53 +0000computer networks
http://thegatebook.in/qa/2483/computer-networks
<p><strong> A TCP machine is sending windows of 65,535 bytes over a 1-Gbps channel that has a 10-msec one-way delay. What is the maximum throughput achievable? What is the line efficiency?</strong></p>Computer Networkshttp://thegatebook.in/qa/2483/computer-networksThu, 17 Aug 2017 20:30:17 +0000Latency of retrieve cache block
http://thegatebook.in/qa/2482/latency-of-retrieve-cache-block
A cpu has cache with block size 64B . the main memory has k- banks , each bank being C-byte wide. Consecutive C-byte chunks are mapped on consecutive banks with wraparound. All the K &ndash;banks can be accessed in parallel, but to accesses the same bank must be serialized. A cache block access may involve multiple iterations of parallel bank accesses depending on the amount of data obtained by accessing all the k-banks in parallel .Each iteration requires decoding the bank numbers to be accessed in parallel and this takes k/2 ns . the latency of one bank access is 80ns . if c=2 and k=24, then latency of retrieving a cache block starting at address zero from main memory is ?Computer Organizationhttp://thegatebook.in/qa/2482/latency-of-retrieve-cache-blockTue, 15 Aug 2017 15:06:31 +0000Memory with array
http://thegatebook.in/qa/2481/memory-with-array
Consider a machine with a byte addressable main memory of 216 bytes. Assume that a direct mapped data cache consisting of 32 lines of 64 byte each is used in the system. A 50* 50 2-d array of bytes is stored in the mm starting from memory location 1100H. Assume that the data cache is initially empty. The complete array is accessed twice. Assume that the contents of the data cache do not change in between the two accesses. How many data cache misses will occur in total?Computer Organizationhttp://thegatebook.in/qa/2481/memory-with-arrayTue, 15 Aug 2017 14:57:01 +0000Doubt in Function
http://thegatebook.in/qa/2480/doubt-in-function
Let k be an integer at least 4 and let . [k] = {1, 2, . . . , k} Let f : [k]4 &rarr;{0, 1} be defined as follows: f(y1, y2, y3, y4) = 1 if an only if the yi's are all distinct. For each choice , z = (z1, z2, z3) &isin; [k]^3 let gz : [k]&rarr;{0, 1}be defined by<br />
gz (Y) = f(Y, z1, z2, z3). Let N be the number of distinct functions gz that are obtained as z varies in {1, 2, . . . , k}^3, that is N =∣ {gz : z &isin; {1, 2, . . . , k}3}∣, . What is N?Discrete Mathshttp://thegatebook.in/qa/2480/doubt-in-functionMon, 14 Aug 2017 17:36:46 +0000Doubts in Function
http://thegatebook.in/qa/2479/doubts-in-function
A function f : N+ &rarr;N+ , defined on the set of positive integers N+,satisfies the following properties:<br />
f(n) = f(n/2) if is even<br />
f(n) = f(n + 5) if is odd<br />
Let R = {i ∣ &exist;j : f(j) = i} be the set of distinct values that f takes. The maximum possible size of is ----------Discrete Mathshttp://thegatebook.in/qa/2479/doubts-in-functionMon, 14 Aug 2017 17:24:10 +0000Propositional logic
http://thegatebook.in/qa/2478/propositional-logic
<p><img alt="" src="http://thegatebook.in/qa/?qa=blob&qa_blobid=16772046866399045784" style="height:239px; width:600px"></p>Discrete Mathshttp://thegatebook.in/qa/2478/propositional-logicMon, 14 Aug 2017 04:51:06 +0000Answered: algorithms time-complexity GATE2014-1-42
http://thegatebook.in/qa/2474/algorithms-time-complexity-gate2014-1-42?show=2477#a2477
<p>Option C is correct answer.. Please see the solution. pages are in the continuation.</p>
<p><img alt="" src="http://thegatebook.in/qa/?qa=blob&qa_blobid=7584932905690700211" style="height:800px; width:600px"></p>
<p><img alt="" src="http://thegatebook.in/qa/?qa=blob&qa_blobid=2126148900164337758" style="height:800px; width:600px"></p>
<p> </p>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2474/algorithms-time-complexity-gate2014-1-42?show=2477#a2477Sun, 13 Aug 2017 07:33:59 +0000Answered: finite automata
http://thegatebook.in/qa/2433/finite-automata?show=2473#a2473
A) is right answerTOChttp://thegatebook.in/qa/2433/finite-automata?show=2473#a2473Sat, 12 Aug 2017 15:50:40 +0000Answered: finite automata
http://thegatebook.in/qa/2435/finite-automata?show=2472#a2472
figure 1 is the right choice<br />
<br />
<br />
<br />
you can solve it by taking string and eliminating option<br />
<br />
option D) can not be answer as it is not accepting ""aa""<br />
<br />
option c) can not be answer as it is not accepting ""abba"<br />
<br />
option b) is not answer because it is accepting string ""ab"" which is not in language given<br />
<br />
hence option A) is right choice and we can further proof that it is accepting all strings generated by language.TOChttp://thegatebook.in/qa/2435/finite-automata?show=2472#a2472Sat, 12 Aug 2017 15:49:15 +0000Answered: recurrence relation
http://thegatebook.in/qa/2464/recurrence-relation?show=2471#a2471
D) is right choice, use master theorem <br />
<br />
as n^2 is fixed it will retain to n^2 only. Buut we can increase the value of 'm' and answer will depend on what value we are chossing for 'm' therefore D) should be choice.Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2464/recurrence-relation?show=2471#a2471Sat, 12 Aug 2017 15:39:16 +0000Answered: reccurence relation
http://thegatebook.in/qa/2465/reccurence-relation?show=2470#a2470
O(n)<br />
<br />
use method by substitution to solve<br />
<br />
you will left with <br />
<br />
T(n-1)+c in end <br />
<br />
which is equal to O(n)Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2465/reccurence-relation?show=2470#a2470Sat, 12 Aug 2017 15:36:11 +0000Answered: kruskal algorithm
http://thegatebook.in/qa/2466/kruskal-algorithm?show=2469#a2469
As the edge weight are sorted, we have to take one edge and add no heap creation required here<br />
<br />
<br />
<br />
Therefore O(m+n)Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2466/kruskal-algorithm?show=2469#a2469Sat, 12 Aug 2017 15:29:13 +0000Answered: spanning tree
http://thegatebook.in/qa/2463/spanning-tree?show=2468#a2468
No mandatory condition is there. What if all edges in graph have same weight ie E max?. Answer is they may contain or may not contain Emax.Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2463/spanning-tree?show=2468#a2468Sat, 12 Aug 2017 15:24:02 +0000Answered: spanning tree
http://thegatebook.in/qa/2461/spanning-tree?show=2467#a2467
What is cayley formula and where it is used?Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2461/spanning-tree?show=2467#a2467Sat, 12 Aug 2017 15:21:41 +0000c programming
http://thegatebook.in/qa/2462/c-programming
<p>Sir according to me there is a compilation error, but while running the program i got the output as :</p>
<p>PFA screenshot.. Please help in this .<img alt="" src="http://thegatebook.in/qa/?qa=blob&qa_blobid=2648880763177223985" style="height:362px; width:600px"></p>
<p><img alt="" src="http://thegatebook.in/qa/?qa=blob&qa_blobid=3180666613869576602" style="height:66px; width:600px"></p>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2462/c-programmingSat, 12 Aug 2017 09:38:17 +0000error while saving
http://thegatebook.in/qa/2460/error-while-saving
<p>PFA image. this code is running perfectly fine when saved as (.c++), but when i am saving it as (.C) it generates compilation error. why so sir?<img alt="" src="http://thegatebook.in/qa/?qa=blob&qa_blobid=17224824513562042903" style="height:435px; width:448px"></p>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2460/error-while-savingSat, 12 Aug 2017 09:33:44 +0000C programming
http://thegatebook.in/qa/2459/c-programming
<p>PFA Screenshot. In the program I am getting compilation error but in the key answer is 7. please help me how to evaluate the increment decrement operator in this question.</p>
<p><img alt="" src="http://thegatebook.in/qa/?qa=blob&qa_blobid=1833265933397681420" style="height:162px; width:472px"></p>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2459/c-programmingSat, 12 Aug 2017 09:31:00 +0000Answered: Binary Search tree
http://thegatebook.in/qa/2456/binary-search-tree?show=2458#a2458
<p>In BST search if we go from say 10 to 40 while searching for 60, So, 10, 20, 40 and 50 visited, means they are visited in order. Similarly, 90, 80 and 70 are visited in order. Becasue it is BST and inorder gives sorted order therefore they will be visited in order.</p>
<p>that is to search 60 we will visit (10,20,40,50) we can arrange them in 4! and then 60 </p>
<p>now after 60 we can permutate (70,80,90) we can arange them in 3! in any order</p>
<h2>(Number of permutation of 7 number)<span class="marker"> </span><strong><span class="marker">/</span> </strong>(Number of permutation of 4 number * number of permutation of 3 number)</h2>
<p> </p>
<p>7! / (4!*3!)</p>
<p>35.</p>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2456/binary-search-tree?show=2458#a2458Sat, 12 Aug 2017 04:51:29 +0000Answered: Balance binary tree
http://thegatebook.in/qa/2454/balance-binary-tree?show=2457#a2457
All of the above are self adjusting balanced binary search tree.Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2454/balance-binary-tree?show=2457#a2457Sat, 12 Aug 2017 04:39:10 +0000Weight - balanced tree
http://thegatebook.in/qa/2455/weight-balanced-tree
<p> </p>
<p>A weight-balanced tree is a binary tree in which for each node. The number of nodes in the left sub tree is at least half and at most twice the number of nodes in the right sub tree. The maximum possible height (number of nodes on the path from the root to the farthest leaf) of such a tree on n nodes is best described by which of the following?</p>
<p>a) <img alt="\log_2 n" src="http://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-dc0a40509632ba551e83df82bf26351d_l3.svg" style="height:17px; width:45px"> b) <img alt="\log_{4/3} n" src="http://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-84ada8f2d642e733860b10a32633de40_l3.svg" style="height:20px; width:58px"> c) <img alt="\log_3 n" src="http://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-9fc76f96788e400230a948d4fe559895_l3.svg" style="height:17px; width:45px"> d) <img alt="\log_{3/2} n" src="http://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-05757c1c7502b91f4bd9399ed305dc52_l3.svg" style="height:20px; width:58px"></p>
<p> </p>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2455/weight-balanced-treeFri, 11 Aug 2017 20:38:52 +0000C programming Output
http://thegatebook.in/qa/2453/c-programming-output
<p>Predict the output of following program?</p>
<table border="0" cellpadding="0" cellspacing="0" style="height:604px; width:604px">
<tbody>
<tr>
<td style="height:604px; width:604px">
<p><code>#include "stdio.h"</code></p>
<p><code>int</code> <code>main()</code></p>
<p><code>{</code></p>
<p> <code>char</code> <code>arr[100];</code></p>
<p> <code>printf</code><code>(</code><code>"%d"</code><code>, </code><code>scanf</code><code>(</code><code>"%s"</code><code>, arr));</code></p>
<p> <code>/* Suppose that input value given</code></p>
<p> <code>for above scanf is "GeeksQuiz" */</code></p>
<p> <code>return</code> <code>1;</code></p>
<p><code>}</code></p>
</td>
</tr>
</tbody>
</table>
<p> </p>
<table style="width:553px">
<tbody>
<tr>
<td style="width:30px">
<p>A</p>
</td>
<td>
<p>9</p>
</td>
</tr>
<tr>
<td style="width:30px">B</td>
<td>
<p>1</p>
</td>
</tr>
<tr>
<td style="width:30px">
<p>C</p>
</td>
<td>
<p>10</p>
</td>
</tr>
<tr>
<td style="width:30px">D</td>
<td>
<p>100</p>
</td>
</tr>
</tbody>
</table>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2453/c-programming-outputFri, 11 Aug 2017 20:18:56 +0000Seven different objects must be divided among three people.
http://thegatebook.in/qa/2452/seven-different-objects-must-be-divided-among-three-people
Seven different objects must be divided among three people. In how many ways can this be done if at least one of them gets exactly 1 object?Discrete Mathshttp://thegatebook.in/qa/2452/seven-different-objects-must-be-divided-among-three-peopleFri, 11 Aug 2017 05:20:46 +0000Answered: The amount of ROM needed to implement a 4 bit multiplier is
http://thegatebook.in/qa/2444/the-amount-of-rom-needed-to-implement-a-4-bit-multiplier-is?show=2451#a2451
This will be covered in Digital ElectronicsComputer Organizationhttp://thegatebook.in/qa/2444/the-amount-of-rom-needed-to-implement-a-4-bit-multiplier-is?show=2451#a2451Fri, 11 Aug 2017 05:16:04 +0000Answered: Full binary tree
http://thegatebook.in/qa/2447/full-binary-tree?show=2450#a2450
The question should be "which of the following combination can not guaruntee the construction of the binary tree uniquely.<br />
<br />
We know that preorder and post order can not guaruntee that.Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2447/full-binary-tree?show=2450#a2450Fri, 11 Aug 2017 05:15:12 +0000Answered: But we can include one cycle for top of stack pointer decrement
http://thegatebook.in/qa/2448/but-we-can-include-one-cycle-for-top-stack-pointer-decrement?show=2449#a2449
That is where ambiguity resides. Question is too unclear to decide whether answer is 2 or 3.Computer Organizationhttp://thegatebook.in/qa/2448/but-we-can-include-one-cycle-for-top-stack-pointer-decrement?show=2449#a2449Fri, 11 Aug 2017 05:11:25 +0000Answered: how to find clock cycles
http://thegatebook.in/qa/2445/how-to-find-clock-cycles?show=2446#a2446
<p>This question is too unclear to answer unambiguously.<br>
<br>
M [SP] <img alt="\leftarrow" src="http://latex.codecogs.com/gif.latex?%5Cleftarrow"> r // 2 cycles<br>
<br>
It is given that each memory operation takes 2 CPU clock cycles<br>
<br>
SP <img alt="\leftarrow" src="http://latex.codecogs.com/gif.latex?%5Cleftarrow">SP - 1// 0 cycles<br>
<br>
As it is given that it is locally decremented.</p>
<p>Total cycles are 2</p>Computer Organizationhttp://thegatebook.in/qa/2445/how-to-find-clock-cycles?show=2446#a2446Thu, 10 Aug 2017 15:09:01 +0000Answered: finite automata
http://thegatebook.in/qa/2436/finite-automata?show=2442#a2442
The answer is 3.<br />
The given regular expression is the string consisting either aa as substring or bb as the substring or both.<br />
<br />
The first option generating the string ab and ba, Which can't be generated by given Regular expression.<br />
Similar to second option.<br />
For 4th option, it is not generating the string aa or bb.TOChttp://thegatebook.in/qa/2436/finite-automata?show=2442#a2442Wed, 09 Aug 2017 09:49:44 +0000Answered: question on subnet
http://thegatebook.in/qa/2438/question-on-subnet?show=2441#a2441
<p>Broadcast address is 204.99.88.31</p>
<p>if we write in binary it would be <img alt="11001100.01100011.01011000.00001111" src="http://latex.codecogs.com/gif.latex?11001100.01100011.01011000.00001111"></p>
<p>The only hint we have about broadcast address is it has all ones in the host part. </p>
<p>Now host part can be last bit or last 2 bits or last 3 bits or last 4 bits</p>
<p>Case1: Assume that last 4 bits as host part</p>
<p>Now make network part as all ones and host part as zeroes to get subnet mask </p>
<p> <img alt="11111111.11111111.11111111.11110000" src="http://latex.codecogs.com/gif.latex?11111111.11111111.11111111.11110000"></p>
<p>255.255.255.240</p>
<p>Case 2: Assume that last 3 bits as host part </p>
<p>Now make network part as all ones and host part as zeroes to get subnet mask </p>
<p><img alt="11111111.11111111.11111111.11111000" src="http://latex.codecogs.com/gif.latex?11111111.11111111.11111111.11111000"></p>
<p>255.255.255.248</p>
<p>Case 3: If you do like above then subnet mask will be</p>
<p>255.255.255. 252</p>
<p>Case 4: if you do like above then subnet mask is</p>
<p>255.255.255.254</p>
<p>Option D is the answer</p>Computer Networkshttp://thegatebook.in/qa/2438/question-on-subnet?show=2441#a2441Wed, 09 Aug 2017 04:30:51 +0000Answered: Webinar for GATE
http://thegatebook.in/qa/2432/webinar-for-gate?show=2440#a2440
The next webinar will be on August 10, 2017. You get mail regarding this.Discrete Mathshttp://thegatebook.in/qa/2432/webinar-for-gate?show=2440#a2440Wed, 09 Aug 2017 03:54:52 +0000Progate Test Series
http://thegatebook.in/qa/2434/progate-test-series
When will Progate Test series start?Aptitudehttp://thegatebook.in/qa/2434/progate-test-seriesMon, 07 Aug 2017 14:52:17 +0000Print output
http://thegatebook.in/qa/2431/print-output
<p><img src="https://gs-post-images.grdp.co/2017/8/image_12135228-img1501829078168-89-rs-high-webp.jpeg" alt="image"></p>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2431/print-outputFri, 04 Aug 2017 14:12:21 +0000operating system foro
http://thegatebook.in/qa/2430/operating-system-foro
Fork system call under os Is in syllabus?Operating Systemshttp://thegatebook.in/qa/2430/operating-system-foroFri, 04 Aug 2017 01:52:32 +0000Answered: integer variable and character pointer
http://thegatebook.in/qa/2413/integer-variable-and-character-pointer?show=2428#a2428
It will give compilation error as ptr (pointer) is character type and it can't store the address of integer type variable will lead to type casting error at compile time.<br />
<br />
If you change pointer to integer type i.e (int * pointer) then the answer will be -:<br />
<br />
1st printf will print (511,511,511)<br />
<br />
2nd printf will print(10,511,10)<br />
<br />
)Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2413/integer-variable-and-character-pointer?show=2428#a2428Thu, 03 Aug 2017 13:16:41 +0000Answered: Q35 trees algo
http://thegatebook.in/qa/2368/q35-trees-algo?show=2427#a2427
I have covered this in videos section under BST<br />
<br />
Recurrence relation for no of BST is<br />
<br />
T(n) = T(0)T(n-1) + T(1).T(n-2).....+T(n-1).T(0)Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2368/q35-trees-algo?show=2427#a2427Thu, 03 Aug 2017 11:25:40 +0000Answered: character array and character pointer
http://thegatebook.in/qa/2414/character-array-and-character-pointer?show=2426#a2426
GATE is array name to char array. It will act as char pointer so intially it points to 'G'. So GATE+4 is (if array start with address 100) 103 that points to '1'.<br />
<br />
"Points to" means it has address of postion of char.<br />
<br />
So now GRADE is also pointing to '1' so *GRADE will dereference and change '1' to '0'. (We can change this as it not a string constant but and char array)<br />
<br />
So when GATE will be printed it will print GATE08.Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2414/character-array-and-character-pointer?show=2426#a2426Thu, 03 Aug 2017 09:28:00 +0000Answered: C program output
http://thegatebook.in/qa/2374/c-program-output?show=2425#a2425
<p>when we specify function call in printf then return value of that function will be printed.</p>
<p>scanf returns </p>
<p>printf returns <strong> <em>the number of characters printed</em></strong><em>. </em></p>
<p>scanf returns</p>
<p> <strong><em>On success, the function returns the number of items successfully read. This count can match the expected number of readings or fewer, even zero, if a matching failure happens. In the case of an input failure before any data could be successfully read, EOF is returned</em></strong></p>
<p> </p>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2374/c-program-output?show=2425#a2425Thu, 03 Aug 2017 09:14:46 +0000Answered: Post increment operator evaluation
http://thegatebook.in/qa/2415/post-increment-operator-evaluation?show=2424#a2424
#define macro just replace whatever code is defined at the complie time in program.<br />
<br />
So CUBE(a++) will become a++*a++*a++.<br />
<br />
Post increment have higher precedence but it value will change after completion of the the current statement, due to post increment effect, i.e, *z++ will use value of z.<br />
<br />
<br />
<br />
So answer would be 3*3*3= 27<br />
<br />
And three time post increment of 3 gives us 6.<br />
<br />
6,27.<br />
<br />
<br />
<br />
But wait that is wrong answer, while saying post increment has more priority over * (it means for both dereference and multiply operator have lower precedence than post increment).<br />
<br />
<br />
<br />
Ideally it should work like above worked, but it executes in this way, a++*a++*a++ this will be converted into postfix expression which is a++a++*a++*.<br />
<br />
I can't show you here but it evaluate to a=6 and b=60. Which is the correct answer. So answer is none in the options.<br />
<br />
(Try solve this postfix expression yourself, hint mind that post increment occur after a++ are poped out of the stack and next 'a' get the updated value).Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2415/post-increment-operator-evaluation?show=2424#a2424Thu, 03 Aug 2017 09:12:14 +0000Answered: Q19 Dynamic Programming
http://thegatebook.in/qa/2354/q19-dynamic-programming?show=2419#a2419
<p>It seems that we have to write recurrence relation to the problem. </p>
<p>T(k) = smallest number of steps needed to move from k to 100.</p>
<p>From every point there is a short cut. Say it is j for k</p>
<p>So either you can go to k+1 or j from k.</p>
<p><img alt="" src="http://thegatebook.in/qa/?qa=blob&qa_blobid=502416586980826733" style="height:349px; width:600px"></p>
<p>T(9) = 1+ min(T(10) , T(15)) </p>
<p>//short cut from 9 is 9--->15 </p>
<p>Value of the product yz is 10*15 = 150</p>
<p> </p>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2354/q19-dynamic-programming?show=2419#a2419Thu, 03 Aug 2017 03:42:23 +0000Answered: C Programming Assignment operator
http://thegatebook.in/qa/2372/c-programming-assignment-operator?show=2417#a2417
<p><img alt="" src="http://thegatebook.in/qa/?qa=blob&qa_blobid=17456172438042171282" style="height:1066px; width:600px"></p>
<p>Check the output</p>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2372/c-programming-assignment-operator?show=2417#a2417Thu, 03 Aug 2017 03:27:54 +0000Answered: Q29 algo lexographic order
http://thegatebook.in/qa/2363/q29-algo-lexographic-order?show=2412#a2412
<p> The correct answer is <img alt="O(n^{2}log n)" src="http://latex.codecogs.com/gif.latex?O%28n%5E%7B2%7Dlog%20n%29"></p>
<p><strong>Method 1</strong> </p>
<p>assume string lenth k rather than n to differentiate no of objects and string length. (no of objects is going to be changed when the problem is divided into sub problems but each string length is always n)</p>
<p>T(n) = 2T(n/2) +nk </p>
<p>please note that k is not constant (k=n).</p>
<p>it seems it falls under case3, isn't it so? But actually not. case 3 has another check called regularity condition. generally i don't mention as it is always satisfied except in some rare cases.</p>
<p>So case 3 has this regularity condition</p>
<p>af(n/b) < = cf(n) for some c <1</p>
<p>in our problem f(n) = nk, a=2 ,b=2</p>
<p>2* f(n/2) <= c f(n) </p>
<p>2* kn/2 <= c (kn) </p>
<p>kn <= c(kn)</p>
<p> not possible for any k<1.</p>
<p>hence case 3 can not be applied. So we take another approach.</p>
<p><strong>Method 2</strong></p>
<p>Lets write recurrence for no of object comparisons </p>
<p>T(n) = 2T(n/2) + n object comparisons</p>
<p>if you solve it you <img alt="\theta (nlogn )" src="http://latex.codecogs.com/gif.latex?%5Ctheta%20%28nlogn%20%29"> object comparisons.</p>
<p>Since each object is string it takes n units for each such object comparison.</p>
<p>hence nlogn * n = n*n logn comparisons </p>
<p>Please let me know if you have any questions here.</p>
<p> </p>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2363/q29-algo-lexographic-order?show=2412#a2412Wed, 02 Aug 2017 13:08:05 +0000Answered: Stacks PUSH, POP
http://thegatebook.in/qa/2371/stacks-push-pop?show=2411#a2411
<p>In the question they are talking about efficient implementation. That means they are assuming this implementation. </p>
<p><a rel="nofollow" href="http://www.geeksforgeeks.org/design-and-implement-special-stack-data-structure/">http://www.geeksforgeeks.org/design-and-implement-special-stack-data-structure/</a></p>
<p>So each element to be inserted two elements are inserted at the end. </p>
<p>That's why it is 2*3*4 bytes </p>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2371/stacks-push-pop?show=2411#a2411Wed, 02 Aug 2017 12:29:47 +0000Sir, Any general approach for such questions ?
http://thegatebook.in/qa/2407/sir-any-general-approach-for-such-questions
<p>For <img alt="A,B \subseteq \Sigma *" src="http://latex.codecogs.com/gif.latex?A%2CB%20%5Csubseteq%20%5CSigma%20*"></p>
<p>We have defined <img alt="A/B = \left \{ x\subseteq \Sigma * | \exists y \in B \and\ xy\in A \right \}" src="http://latex.codecogs.com/gif.latex?A/B%20%3D%20%5Cleft%20%5C%7B%20x%5Csubseteq%20%5CSigma%20*%20%7C%20%5Cexists%20y%20%5Cin%20B%20%5Cand%5C%20xy%5Cin%20A%20%5Cright%20%5C%7D"></p>
<p>A). If A is a CFL and B is regular then what can be said about A/B ?</p>
<p>B). If A is a CSL and B is regular then what can be said about A/B ?</p>
<hr>
<p>Sir, Is there any general approach for such questions ?</p>TOChttp://thegatebook.in/qa/2407/sir-any-general-approach-for-such-questionsWed, 02 Aug 2017 07:49:06 +0000Answered: Global variable
http://thegatebook.in/qa/2397/global-variable?show=2406#a2406
<p><img alt="" src="http://thegatebook.in/qa/?qa=blob&qa_blobid=1736637993514127625" style="height:666px; width:600px"></p>
<p>Option (d) would be the answer </p>Data Structures Algorithms and C Programminghttp://thegatebook.in/qa/2397/global-variable?show=2406#a2406Wed, 02 Aug 2017 05:47:07 +0000Answered: Relations Test Question
http://thegatebook.in/qa/2398/relations-test-question?show=2405#a2405
B. Intersection of any two transitive relations is transitive.<br />
<br />
To disprove this statement the two relations initially you take should be transitive.Discrete Mathshttp://thegatebook.in/qa/2398/relations-test-question?show=2405#a2405Wed, 02 Aug 2017 05:11:21 +0000Answered: Discrete test 4
http://thegatebook.in/qa/2399/discrete-test-4?show=2404#a2404
<p>Self loops are not allowed. But still there is a 0 length path from vertex x to x.</p>
<p><img alt="" src="http://thegatebook.in/qa/?qa=blob&qa_blobid=7272834462372171701" style="height:714px; width:600px"></p>Discrete Mathshttp://thegatebook.in/qa/2399/discrete-test-4?show=2404#a2404Wed, 02 Aug 2017 05:01:36 +0000Answered: discrete test 4
http://thegatebook.in/qa/2400/discrete-test-4?show=2403#a2403
<p><img alt="" src="http://thegatebook.in/qa/?qa=blob&qa_blobid=6590302537363723023" style="height:211px; width:600px"></p>
<p>Case1: All elements in the form (x,x) [ Group 1 ]</p>
<p>Since we have 7 such elements in <img alt="A\times A" src="http://latex.codecogs.com/gif.latex?A%5Ctimes%20A"> so we can select 4 among them in 7C4 ways.</p>
<p>Case 2: 2 elements of type (x,x) and one pair (a,b) and (b,a) from rest of the (49-7)/2 = 21 pairs</p>
<p>7C2 * 21C1 ways</p>
<p>Case3: 2 pairs from Group 2 [Pairs]</p>
<p>21C2 ways</p>
<p>Total ways = 7C4 ways + 7C2 * 21C1 ways + 21C2 ways</p>Discrete Mathshttp://thegatebook.in/qa/2400/discrete-test-4?show=2403#a2403Wed, 02 Aug 2017 04:59:50 +0000