search
Log In

Most answered questions in Programming and DS

118 votes
15 answers
1
The number of ways in which the numbers $1, 2, 3, 4, 5, 6, 7$ can be inserted in an empty binary search tree, such that the resulting tree has height $6$, is _________. Note: The height of a tree with a single node is $0$.
asked Feb 12, 2016 in DS Akash Kanase 22.3k views
24 votes
13 answers
2
Consider the following function implemented in C: void printxy(int x, int y) { int *ptr; x=0; ptr=&x; y=*ptr; *ptr=1; printf(“%d, %d”, x, y); } The output of invoking $printxy(1,1)$ is: $0, 0$ $0, 1$ $1, 0$ $1, 1$
asked Feb 14, 2017 in Programming Madhav 4.2k views
34 votes
12 answers
3
Consider the following two functions. void fun1(int n) { if(n == 0) return; printf("%d", n); fun2(n - 2); printf("%d", n); } void fun2(int n) { if(n == 0) return; printf("%d", n); fun1(++n); printf("%d", n); } The output printed when $\text{fun1}(5)$ is called is $53423122233445$ $53423120112233$ $53423122132435$ $53423120213243$
asked Feb 14, 2017 in Programming Arjun 9.2k views
21 votes
12 answers
4
A binary tree T has $20$ leaves. The number of nodes in T having two children is ______.
asked Feb 12, 2015 in DS jothee 11.7k views
35 votes
11 answers
5
What will be the output of the following $C$ program? void count (int n) { static int d=1; printf ("%d",n); printf ("%d",d); d++; if (n>1) count (n-1); printf ("%d",d); } void main(){ count (3); } $3 \ 1 \ 2 \ 2 \ 1 \ 3 \ 4 \ 4 \ 4$ $3 \ 1 \ 2 \ 1 \ 1 \ 1 \ 2 \ 2 \ 2$ $3 \ 1 \ 2 \ 2 \ 1 \ 3 \ 4$ $3 \ 1 \ 2 \ 1 \ 1 \ 1 \ 2$
asked Feb 12, 2016 in Programming Sandeep Singh 7.4k views
94 votes
11 answers
6
Let $Q$ denote a queue containing sixteen numbers and $S$ be an empty stack. $Head(Q)$ returns the element at the head of the queue $Q$ without removing it from $Q$. Similarly $Top(S)$ returns the element at the top of $S$ without removing it from $S$. Consider ... ); else x:= Pop(S); Enqueue (Q, x); end end The maximum possible number of iterations of the while loop in the algorithm is _______.
asked Feb 12, 2016 in DS Sandeep Singh 14.7k views
120 votes
11 answers
7
When searching for the key value $60$ in a binary search tree, nodes containing the key values $10, 20, 40, 50, 70, 80, 90$ are traversed, not necessarily in the order given. How many different orders are possible in which these key values can occur on the search path from the root to the node containing the value $60$? $35$ $64$ $128$ $5040$
asked Oct 30, 2014 in DS Ishrat Jahan 21.3k views
40 votes
11 answers
8
Consider a hash function that distributes keys uniformly. The hash table size is $20$. After hashing of how many keys will the probability that any new key hashed collides with an existing one exceed $0.5$. $5$ $6$ $7$ $10$
asked Oct 30, 2014 in DS Ishrat Jahan 11.2k views
57 votes
11 answers
9
In a compact single dimensional array representation for lower triangular matrices (i.e all the elements above the diagonal are zero) of size $n \times n$ ... this new representation is: $i+j$ $i+j-1$ $(j-1)+\frac{i(i-1)}{2}$ $i+\frac{j(j-1)}{2}$
asked Oct 4, 2014 in DS Kathleen 13.4k views
40 votes
11 answers
10
In a binary tree with $n$ nodes, every node has an odd number of descendants. Every node is considered to be its own descendant. What is the number of nodes in the tree that have exactly one child? $0$ $1$ $\frac{(n-1)}{2}$ $n-1$
asked Sep 29, 2014 in DS jothee 6.9k views
60 votes
11 answers
11
Consider a rooted n node binary tree represented using pointers. The best upper bound on the time required to determine the number of subtrees having exactly $4$ nodes is $O(n^a\log^bn)$. Then the value of $a+10b$ is __________.
asked Sep 26, 2014 in DS jothee 11.2k views
13 votes
10 answers
12
What is the worst case time complexity of inserting $n$ elements into an empty linked list, if the linked list needs to be maintained in sorted order? $\Theta(n)$ $\Theta(n \log n)$ $\Theta ( n)^{2}$ $\Theta(1)$
asked Feb 12, 2020 in DS Arjun 8.9k views
31 votes
10 answers
13
Consider the following C program: #include <stdio.h> int r() { static int num=7; return num--; } int main() { for (r();r();r()) printf(“%d”,r()); return 0; } Which one of the following values will be displayed on execution of the programs? $41$ $52$ $63$ $630$
asked Feb 7, 2019 in Programming Arjun 9.9k views
30 votes
10 answers
14
Let $T$ be a full binary tree with $8$ leaves. (A full binary tree has every level full.) Suppose two leaves $a$ and $b$ of $T$ are chosen uniformly and independently at random. The expected value of the distance between $a$ and $b$ in $T$ (ie., the number of edges in the unique path between $a$ and $b$) is (rounded off to $2$ decimal places) _________.
asked Feb 7, 2019 in DS Arjun 12.9k views
54 votes
10 answers
15
A hash table of length $10$ uses open addressing with hash function $h(k) = k \: mod \: 10$, and linear probing. After inserting $6$ ... insertion sequences of the key values using the same hash function and linear probing will result in the hash table shown above? $10$ $20$ $30$ $40$
asked Apr 21, 2016 in DS jothee 12.3k views
29 votes
10 answers
16
Consider a binary tree T that has $200$ leaf nodes. Then the number of nodes in T that have exactly two children are ______.
asked Feb 14, 2015 in DS jothee 8.8k views
17 votes
9 answers
17
Consider the following $\text{C}$ program: #include<stdio.h> int counter=0; int calc (int a, int b) { int c; counter++; if(b==3) return (a*a*a); else { c = calc(a, b/3); return (c*c*c); } } int main() { calc(4, 81); printf("%d", counter); } The output of this program is ______.
asked Feb 14, 2018 in Programming gatecse 5k views
28 votes
9 answers
18
Consider the following C program: #include<stdio.h> struct Ournode{ char x, y, z; }; int main() { struct Ournode p={'1', '0', 'a'+2}; struct Ournode *q=&p; printf("%c, %c", *((char*)q+1), *((char*)q+2)); return 0; } The output of this program is: 0, c 0, a+2 '0', 'a+2' '0', 'c'
asked Feb 14, 2018 in Programming gatecse 9.4k views
62 votes
9 answers
19
Consider the C code fragment given below. typedef struct node { int data; node* next; } node; void join(node* m, node* n) { node* p = n; while(p->next != NULL) { p = p->next; } p->next = m; } Assuming that m and n point to valid NULL-terminated linked ... or append list m to the end of list n. cause a null pointer dereference for all inputs. append list n to the end of list m for all inputs.
asked Feb 14, 2017 in DS khushtak 13.6k views
75 votes
9 answers
20
Consider the following C program. #include<stdio.h> #include<string.h> void printlength(char *s, char *t) { unsigned int c=0; int len = ((strlen(s) - strlen(t)) > c) ? strlen(s) : strlen(t); printf("%d\n", len); } void main() { char *x = "abc"; ... that $strlen$ is defined in $string.h$ as returning a value of type $size\_t$, which is an unsigned int. The output of the program is __________ .
asked Feb 14, 2017 in Programming srestha 12.5k views
...