# Recent questions and answers in Programming 1
Aliasing in the context of programming languages refers to multiple variables having the same memory location multiple variables having the same value multiple variables having the same identifier multiple uses of the same variable
2
Consider the following program fragment: int d = 0; int i,j,k; for(i=1; i<31; ++i) for(j=1; j<31; ++j) for(k=1; k<31; ++k) if(((i+j+k)%3) == 0) d=d+1; printf("%d",d); The number of additions performed by the above program fragment is? a. 27,000 b. 27,000 x 3 c. 27,000 x 3 + 9,000 d. 9,930 + 2,700 x 3
1 vote
3
For n=2 the P is coming as 3,but none of the option is satisfying?
1 vote
4
Consider the following program segment int main ( ) { char ∗ str = “GATECS”; printf (“%d”, madeeasy (str)); return 0; } int madeeasy (int ∗ p1) { int ∗ p2 = p1; while (∗++p1); return (p1 – p2); } The output of the above program will be ______. Assume that the object of data type int occupies 2 bytes
5
Consider the following pseudo code, where $x$ and $y$ are positive integers. begin q := 0 r := x while r ≥ y do begin r := r - y q := q + 1 end end The post condition that needs to be satisfied after the program terminates is $\{ r = qx + y \wedge r < y\}$ $\{ x = qy + r \wedge r < y\}$ $\{ y = qx + r \wedge 0 < r < y\}$ $\{ q + 1 < r - y \wedge y > 0\}$
6
1)The number of min heap trees are possible with 15 elements such that every leaf node must be greater than all non-leaf nodes of the tree are ________. -------------------------------------------------------------------------------------------------------------------------- 2)The number of min heap trees are possible with 15 elements_________________
7
In the following procedure Integer procedure P(X,Y); Integer X,Y; value x; begin K=5; L=8; P=x+y; end $X$ is called by value and $Y$ is called by name. If the procedure were invoked by the following program fragment K=0; L=0; Z=P(K,L); then the value of $Z$ will be set equal to $5$ $8$ $13$ $0$
8
What is difference between $pop\left ( \right )$,$empty Stack\left ( \right )$,$delete Stack\left ( \right )$? Can all be performed in $O\left ( 1 \right )$ time?
9
Runtime stack doesnot contain (A) Local variables (B) Static Variables (C) Parameter Passed (D) Return Address
1 vote
10
What will be output if you will compile and execute the following C code? void main() { printf("%d",sizeof(5.2)); } $4$ $8$ $2$ $16$
11
double foo(int n) { int i; double sum; if(n == 0) { return 1.0; } else { sum = 0.0; for(i = 0; i < n; i++) { sum += foo(i); } return sum; } } The space complexity of the above code is? $O(1)$ $O(n)$ $O(n!)$ $n^n$
1 vote
12
Narendra is traveling from point A to point B and there are n toll posts along the way. Before starting the journey, Narendra is given, for each post 1 ≤ i < j ≤ n, the feeto travel from post i to post j. The goal is to minimize the travel cost. The most ... . The answer is given to be (C). Is it like this has been solved using Dijkstra using fibonacci heaps? Am I thinking in correct direction?
13
The function f is defined as follows: int f (int n) { if (n <= 1) return 1; else if (n % 2 == 0) return f(n/2); else return f(3n - 1); } Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements. The ... different values of $n \geq 1$. Which one of the following options is true of the above? i and iii i and iv ii and iii ii and iv
14
Following declaration of an array of struct, assumes size of byte, short, int and long are $1,2,3$ and $4$ respectively. Alignment rule stipulates that $n$ - byte field must be located at an address divisible by $n$, the fields in the struct are not rearranged, padding is used to ensure ... $8$, what is the total size of $C$, in bytes? $150$ $160$ $200$ $240$
15
Output of following program? #include<stdio.h> int main() { int *ptr; int x; ptr=&x; *ptr=0; printf("x=%d\n",x); printf("*ptr=%d\n",*ptr); *ptr+=5; printf("x=%d\n",x); printf("*ptr=%d\n",*ptr); (*ptr)++; printf( x=%d\n",x); printf("*ptr=%d\n",*ptr); return 0; } $x=0$ $^*ptr=0$ ... $^*ptr=0$ $x=5$ $^*ptr=5$ $x=$garbage value $^*ptr=$garbage value $x=0$ $^*ptr=0$ $x=0$ $^*ptr=0$ $x=0$ $^*ptr=0$
16
What is the time complexity for insertion in binary tree in worst case? O(1) O(log n) O(n) O(n log n)
1 vote
17
What is the time complexity to delete an arbitrary node from binary heap? O(n) O(log n) O(1) O(n log n)
1 vote
18
Following is C like Pseudo code of a function that takes a number as an argument, and uses a stack S to do processing. void fun(int n) { Stack S;//Say it creates an empty stack S while(n>0) { // This line pushes the value of n%2 to stack S; Push(&S,n%2); n=n ... $n$ in reverse order. Prints binary representation of $n$. Prints the value of $\log n$. Prints the value of $\log n$ in reverse order.
19
Consider the following C program. #include <stdio.h> main() { int arr[] = {1, 1, 2, 4, 8, 16, 32, 64}; int i, j, val, t = 16; unsigned char c; for (i = 0; i < 256; i++) { c = i; val = 0; for (j = 0; j < 8; j++) val = val + ((c >> j) & 0x1)*arr[j]; if (val == t) printf("%d\n", i); } } Trace the execution of the code inside the for loop indexed by i when i = 35.
20
What will be the output of the following C program? If you think it will give a runtime error, you need to mention it. In either case, your answer must include proper justifications without which no credit will be given. #include<stdio.h> main() { unsigned char i, j, a[]={1, 2, 3, 4, 5}; int n; i=j=n=5; while ... =%d, n=%d\n", i, j, n); while(j-- !=0) a+=n; printf("j=%d, a=%d\n", j, a); }
21
explain little bit more in easy way
22
Consider 3 dimensional Array A   stored in linear array in column major order. If the base address starts at 10, The location of A    is ________. (Assume the first element is stored at A and each element take 1 memory location)
1 vote
23
Consider the tree T in which left subtree contains half of the maximum number of nodes possible in the avl tree of height 6 and right subtree contains one 3rd of the minimum number of nodes possible in Avl tree of height 6.What will be total number of nodes in T? Edit:- I am getting 75.5 as answer.Now i am not sure whether to pick 75 ot 76
24
25
Can binary serach tree have duplicate elements in the tree?
26
true/false ? ) if stack is implemented as a array,all operation push ,pop ,is emptystack(),delete stack() can be performed in constant time. )if stack is implemented as a linked list ,all operation ,is emptystack(),delete stack() can be performed in constant time.
27
Consider an array $A\left[20, 10\right]$, assume $4$ words per memory cell and the base address of array $A$ is $100$. What is the address of $A\left[11, 5\right]$ ? Assume row major storage. $560$ $565$ $570$ $575$
1 vote
28
A three dimensional array in 'C' is declared as int A[x][y][z]. Here, the address of an item at the location A[p][q][r] can be computed as follows: (where w is the word length of an integer) &A+w(y*z*q+z*p+r) &A+w(y*z*p+z*q+r) &A+w(x*y*p+z*q+r) &A+w(x*y*q+z*p+r)
29
Consider an initially empty hash table of length 10. Following set of keys are inserted using open addressing with hash function h(k) = k mod 10 and linear probing. The number of different insertion sequence of the key values using the given hash function and linear probing will result in the hash table shown in above? (given ans is 128 but i am getting 288)
1 vote
30
What is the correct way to round off $x$, $a$ $\text{float}$ to an $\text{int}$ value? $y=(\text{int})(x+0.5)$ $y=\text{int} (x+0.5)$ $y=(\text{int}) x+0.5$ $y=(\text{int})(\text{int})x+0.5)$
1 vote
31
Find the output of the following $“C”$ code : Main() { int x=20, y=35; x=y++ + x++; y=++y + ++x; printf (“%d, %d\n”, x, y); } $55, 93$ $53, 97$ $56, 95$ $57, 94$
1 vote
32
After $3$ calls of the $c$ function bug ( ) below, the values of $i$ and $j$ will be : int j = 1; bug () { static int i = 0; int j = 0; i++; j++; return (i); } $i = 0, j = 0$ $i = 3, j = 3$ $i = 3, j = 0$ $i = 3, j = 1$
33
What error would the following function give on compilation? f(int a, int b) { int a; a=20; return a; } Missing parenthesis is $\textit{return}$ statement. Function should be defined as $\text{int f(int a, int b)}$ Redeclaration of $a$. None of these.
34
What will be returned by the following function foo when called as foo(10)? int foo(int n) { return n & n | 1; }
35
What is the output of the code given below? # include<stdio.h> int main() { char name[]="satellites"; int len; int size; len= strlen(name); size = sizeof(name); printf("%d",len*size); return 0; } $100$ $110$ $40$ $44$
36
A binary search tree in which every non leaf node has non empty left and right subtrees is called a strictly binary tree . Such a tree with 19 leaves cannot have more than 37 nodes has exactly 37 nodes has exactly 35 nodes cannot have more than 35 nodes
37
Consider the following recursive C function that takes two arguments unsigned int rer(unsigned int n, unsigned int r){ if(n>0)return(n%r + rer(n/r,r)); else retturn 0; } What is the return value of the function $rer$ when it is called as $rer(513,2)$? $9$ $8$ $5$ $2$
Suppose we are implementing quadratic probing with a Hash function, $Hash(y) = X$ $mode$ $100$. If an element with key $4594$ is inserted and the first three locations attempted are already occupied, then the next cell that will be tried is : $2$ $3$ $9$ $97$