# Recent questions and answers in Programming and DS 1
In a min-heap with $n$ elements with the smallest element at the root, the $7^{th}$ smallest element can be found in time $\Theta (n \log n)$ $\Theta (n)$ $\Theta(\log n)$ $\Theta(1)$
1 vote
2
3
Main(){ Int a={(1,2,3,4),(5,6,7,8),(9,10,11,12)} Print("\n%u%u%u",a+1,*(a+1),*(*(a+0)+1))); } What will be the output if base address is 10.
1 vote
4
Let $A$ be a square matrix of size $n\times n$. Consider the following program. What is the expected output? C=100 for i=1 to n do for j=1 to n do { Temp=A[i][j]+C A[i][j]=A[j][i] A[j][i]=Temp-C } for i=1 to n do for j=1 to n ... ]); The matrix $A$ itself. Transpose of matrix $A$. Adding $100$ to the upper diagonal elements and subtracting $100$ from diagonal elements of $A$. None of the option.
1 vote
5
1 vote
6
1 vote
7
four vertices {A,B,C,D} is given which has only vertex D as a leaf total number of binary tree are possible when every binary tree has four node!
8
Let us there are n nodes which are labelled. Then the number of trees possible is given by the Catalan Number i.e $\binom{2n}{n} / (n+1)$ Then the binary search trees possible is just 1?
9
What is the output of the following $\text{’C’}$ program? main() { printf(“%x”,-1>>4); } $\text{ffff}$ $\text{0fff}$ $\text{0000}$ $\text{fff0}$
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
Suppose a circular queue of capacity $(n −1)$ elements is implemented with an array of $n$ elements. Assume that the insertion and deletion operations are carried out using REAR and FRONT as array index variables, respectively. Initially, $REAR = FRONT = 0$. The conditions to detect queue full and ... $(REAR+1) \mod n == FRONT$ full: $(FRONT+1) \mod n == REAR$ empty: $REAR == FRONT$
12
If n has 3, then the statement a[++n]=n++; assigns 3 to a assigns 4 to a assigns 4 to a what is assigned is compiler dependent
1 vote
13
The number of possible binary trees with $4$ nodes is $12$ $13$ $14$ $15$
1 vote
14
A full binary tree with $n$ non-leaf nodes contains $\log_ 2 n$ nodes $n+1$ nodes $2n$ nodes $2n+1$ nodes
15
An array $A$ contains $n$ integers in non-decreasing order, $A \leq A \leq \cdots \leq A[n]$. Describe, using Pascal like pseudo code, a linear time algorithm to find $i, j,$ such that $A[i]+A[j]=a$ given integer $M$, if such $i, j$ exist.
1 vote
16
A priority queue is implemented as a Max-Heap. Initially, it has $5$ elements. The level-order traversal of the heap is: $10,8,5,3,2$. Two new elements $1$ and $7$ are inserted into the heap in that order. The level-order traversal of the heap after the insertion of the elements is $10,8,7,3,2,1,5$ $10,8,7,2,3,1,5$ $10,8,7,1,2,3,5$ $10,8,7,5,3,2,1$
17
A program takes as input a balanced binary search tree with $n$ leaf nodes and computes the value of a function $g(x)$ for each node $x$. If the cost of computing $g(x)$ is: $\Large \min \left ( \substack{\text{number of leaf-nodes}\\\text{in left-subtree of$ ... the worst-case time complexity of the program is? $\Theta (n)$ $\Theta (n \log n)$ $\Theta(n^2)$ $\Theta (n^2\log n)$
18
Suppose there is a balanced binary search tree with $n$ nodes, where at each node, in addition to the key, we store the number of elements in the sub tree rooted at that node. Now, given two elements $a$ and $b$, such that $a < b$, we want to find the ... additions. $O(\log n)$ comparisons but a constant number of additions. $O(n)$ comparisons and $O(n)$ additions, using depth-first- search.
19
In the worst case, the number of comparisons needed to search a single linked list of length $n$ for a given element is $\log n$ $\frac{n}{2}$ $\log_2 {n} - 1$ $n$
1 vote
20
can anyone explain by using static and dynamic programing ? what will be output for static and dynamic? #include<stdio.h> int x=10; void part1(int *a) { *a+=x++; printf("%d",*a); } void part2(int *b) { static x=15; *b=*b*x; part1(&x); printf("%d",x); } void main(){ part2(&x); part1(&x); }
21
What is the time complexity to delete an arbitrary node from binary heap? O(n) O(log n) O(1) O(n log n)
22
Output of the following program? #include<stdio.h> struct st { int x; struct st next; }; int main() { struct st temp; temp.x=10; temp.next=temp; printf("%d",temp.next,x); return 0; } Compiler Error $10$ Runtime Error Garbage Value
23
What is the meaning of following declaration? int(*p)(); $p$ is pointer to function $p$ is pointer to such function which return type is array $p$ is array of pointer to function $p$ is pointer to array of function
24
If space occupied by two strings $s_1$ and $s_2$ in 'C' are respectively $m$ and $n$, then space occupied by string obtained by concatenating $s_1$ and $s_2$ is always less than $m+n$ equal to $m+n$ greater than $m+n$ none of these
25
HOW CAN WE GET A CROSS EDGE WHILE PERFORMING A BFS ON UNDIRECTED AND DIRECTED GRAPH CAN ANYONE SHOW WITH AN EXAMPLE?
26
A circularly linked list is used to represent a Queue. A single variable $p$ is used to access the Queue. To which node should $p$ point such that both the operations $\text{enQueue}$ and $\text{deQueue}$ can be performed in constant time? rear node front node not possible with a single pointer node next to front
27
Consider the following $\text{ANSI C}$ program: #include <stdio.h> #include <stdlib.h> struct Node{ int value; struct Node *next;}; int main( ) { struct Node *boxE, *head, *boxN; int index=0; boxE=head= (struct Node *) malloc(sizeof(struct Node)) ... $\textsf{return}$ which will be reported as an error by the compiler It dereferences an uninitialized pointer that may result in a run-time error
28
A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT ($n$ refers to the number of items in the queue) ? Both operations can be performed in $O(1)$ time. At most one ... complexity for both operations will be $\Omega (n)$. Worst case time complexity for both operations will be $\Omega (\log n)$
29
Given the programming constructs assignment for loops where the loop parameter cannot be changed within the loop if-then-else forward go to arbitrary go to non-recursive procedure call recursive procedure/function call repeat loop, which constructs will you not include in a programming language such that it should be ... $\text{(vi), (vii), (viii)}$ $\text{(iii), (vii), (viii)}$
30
The equivalent postfix expression for $d{\large /}(e+f)+b*c$ : $defbc/++*$ $def+/bc+*$ $def+/bc*+$ None of these
31
The value of the following expression $(13 / 4 * 3) % 5 + 1$ is $5.75$ $2.95$ $1.4875$ $5$
32
Suppose $x$ and $y$ are two Integer Variables having values $0\text{x5AB6}$ and $0\text{x61CD}$ respectively. The result (in hex) of applying bitwise operator and to $x$ and $y$ will be : $0\text{x5089}$ $0\text{x4084}$ $0\text{x78A4}$ $0\text{x3AD1}$
1 vote
33
What is the value of the arithmetic expression (Written in C) $2*3/4-3/4*2$ $0$ $1$ $1.5$ None of these
34
Let $a$ be an array containing $n$ integers in increasing order. The following algorithm determines whether there are two distinct numbers in the array whose difference is a specified number $S > 0$. i = 0; j = 1; while (j < n ){ if (E) j++; else if (a[j] - a[i] == S) break; else i++; } if (j < n) printf ... expression for E. $a[j] - a[i] > S$ $a[j] - a[i] < S$ $a[i] - a[j] < S$ $a[i] - a[j] > S$
35
In a binary tree, for every node the difference between the number of nodes in the left and right subtrees is at most $2$. If the height of the tree is $h > 0$, then the minimum number of nodes in the tree is $2^{h-1}$ $2^{h-1} + 1$ $2^h - 1$ $2^h$
1 vote
36
When a user submits a query, a search engine does the following. For every webpage that has been visited by the search engine, it computes a score indicating how relevant that page is to the query. Finally, it reports the pages with the top k scores on the screen, ... by the user. A good data structure for accumulating the scores and ranking them is: a queue a heap a stack a binary search tree
37
In the code fragment given below, $\mathsf{start}$ and $\mathsf{end}$ are integer values and $\mathsf{prime(x)}$ is a function that returns $\mathsf{true}$ if $\mathsf{x}$ is a prime number and $\mathsf{false}$ otherwise. i:=0; j:=0; k:=0; from (m := start; m <= end; m := m+1){ if ( ... } } At the end of the loop: $k == i-j.$ $k == j-i.$ $k == -j-i.$ Depends on $\mathsf{start}$ and $\mathsf{end}$
1 vote
Suppose we constructed the binary search tree shown below by starting with an empty tree and inserting one element at a time from an input sequence, without any rotations or other manipulations. Which of the following assertions about the order of elements in the input sequence $cannot$ be true? $8$ ... $1$ came after $12$ and $29$ came before $42$. $3$ came before $14$ and $16$ came before $28$.
Consider the following functions f() and g(). f(){ g(){ w=5; z=w+1; w=2*z+2; z=3*z-w; } print(z); } We start with $w$ and $z$ set to $0$ and execute $f()$ and $g()$ in parallel—that is, at each step we either execute one statement from $f()$ or one statement from $g()$. Which of the following is not a possible value printed by $g()$ ? $-2$ $-1$ $2$ $4$
What does the following function compute in terms of $n$ and $d$, for integer values of $d$ ? Note that the operation $/$ denotes floating point division, even if the arguments are both integers. function foo(n,d){ if (d == 0){ return 1; }else{ if (d < 0){ return foo(n,d+1)/n; }else{ return ... the values of $d$. $n \times d$ if $d>0$ ,$n\div d$ if $d<0$. $n \times d$ for all the values of $d$.