Q: If you are using a Depth-first search (DFS) for traversing an unweighted graph, then which of the following will happen? 1. It produces the minimum spanning tree 2. It produces all pair shortest path tree Choose the correct answer from the options given below.
Solution: Depth-first search (DFS) for traversing an unweighted graph, will produce the minimum spanning tree. Only Depth-first search (DFS) for traversing a weighted graph, will produce all pair shortest-path tree.
Q: With the given information provided find out the address of Arr[17] in a 1-D array Arr[30]. - lower bound = 1 - starting base address = 1100 - size of each element is 2.
Solution: We need to find the address of Arr[17]. Starting base address is 1100. Arr[1] – 1100 (2bytes) Arr[2] – 1102 (2bytes) Arr[3] – 1104 (2bytes) Arr[4] – 1106 (2bytes) Arr[5] – 1108 (2bytes) Arr[6] – 1110 (2bytes) Arr[7] – 1112 (2bytes) Arr[8] – 1114 (2bytes) Arr[9] – 1116 (2bytes) Arr[10] – 1118 (2bytes) Arr[11] – 1120 (2bytes) Arr[12] – 1122 (2bytes) Arr[13] – 1124 (2bytes) Arr[14] – 1126 (2bytes) Arr[15] – 1128 (2bytes) Arr[16] – 1130 (2bytes) Arr[17] – 1132 (2bytes) Thus, the Answer for arr[17] is 1132
Q: What will be the output of the following pseudocode?
Integer arr[]={10, 20, 30, 40, 5}
Integer a, s
Set s = 0
Set a = arr[1] + arr[2]
Print aSolution: There is an array of integer arr[]={10,20,30,40,50}. There are two variables a and b declared. . The value initialized for s is 0. On the next line adding the 1st index value 20 and 2nd index value 30 arr[1] + arr[2]( 20+30), the answer is 50 will be stored in a. Finally printing the updated values of a is 50.Q: What will be the output of the following pseudocode? Integer a, b, c Set b = 2, a = 2 c = a ^ b Print c [Note- ^ is the bitwise exclusive OR operator that compares each bit of its first operand to the corresponding bit of its-- other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0]
Solution: There are three variables a, b and c declared. Value initialized for a is 2 and b is 2. When we do a bitwise exclusive OR of c i.e (2^2), the answer is 0. Finally, print the value of c.
Q: Which of the following series will be printed by the given pseudocode? Integer i, j, k, n Set j=1, k=1 for(each i from 1 to 5) print k j=j+1 k=k+j end for
Solution: There are four variables i, j,k, and n declared. Value initialized for j is 1 and k is 1. For loop, i value starts from 1 loop will run till the i<5, In the first iteration i value, is 1, printing k value is 1. Next line j value will be incremented by 1 (1+1) =>2. On the next line adding k and j (1+2), then the answer is 3. 2nd iteration i value will be incremented by 1, i=2. Print k, the updated k value is 3. on the next line j value will be incremented by 1 (2+1) =>3. On the next line adding k and j (3+3) , then the answer is 6. 3rd iteration i value will be incremented by 1, i=3. Print k, the updated k value is 6. on the next line j value will be incremented by 1 (3+1) =>4. On the next line adding k and j (6+4) , then the answer is 10. 4th iteration i value will be incremented by 1, i=4. Print k, the updated k value is 10. on the next line j value will be incremented by 1 (4+1) =>5. On the next line adding k and j (10+5) , then the answer is 15. 5th iteration i value will be in
Q: Find the output of the following pseudo-code: Integer x,y,z; x=0 y=1 x = y = z = 8 Print x
Solution: In this question, the value of x is initialized as 0 and y as 1 in the beginning. Later the value 8 is assigned to the variable z and the value of z is assigned to the variable y and the value of y is assigned to the variable x. Finally, the value of x is updated as 8.
Q: Find the output of the following pseudo-code: Integer value, n Set value = 1, n = 45 while(value less than equal to n) value = value << 1 end loop Print value
Solution: Here, the left shift operation pushes the values towards the left once; when 1 is left-shifted the value that we will be obtaining will always be 2 to the power something. When one is converted in the beginning and not shifted the value will be 2^0 which is 1. The next iteration will be pushed one place towards the left, therefore the value now will be 2^1 which is 2; this will go on happening until the value stored is greater than 45. The value which is greater than 45 in 2 powers is 64. Now the loop terminates and the last value stored in the variable is 64 and the same will be printed.
Q: Find the output of the following pseudo-code: Integer c, d Set c = 15, d = 12 d = c – 1 Print c //line c = d + (c – 2) if(c < 40) Goto line end if
Solution: c and a is initialized, and d as well; line 5 we are re-initializing c in every iteration of goto; the goto loop terminates only when the value of c is greater than 40 the last value stored in c which breaks the if the condition is 51 and all the numbers 15 27 and 39 will be printed according to the algebraic expression in line number 5.
Q: Find the output of the following pseudo-code if x= 4 and y=5:
Integer fun(int x, int y)
if(x > 1)
fun(x – 2, y + 2)
end if
print y
End function fun()Solution: the first reverse recursion would print 9 and returns to a previous function call, next it prints 7 and returns to the very first function call finally it prints a 5 and completes the execution.
Q: How many times will the print statement be executed: Integer a, b, c Set a = 8, b = 10, c = 6 If(a > c AND (b + c) > a) Print a end if if(c > b OR (a + c) > b) Print b end if if((b+c) MOD a EQUALS 0) Print c end if
Solution: All the conditions are true when checked with the condition so the print statement will be executed 3 times.
| You Have Score    | /10 |