search
Log In

Most viewed questions in Programming and DS

108 votes
14 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 17.6k views
112 votes
9 answers
2
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 17.2k views
70 votes
5 answers
4
You are given the postorder traversal, $P$, of a binary search tree on the $n$ elements $1, 2, \dots, n$. You have to determine the unique binary search tree that has $P$ as its postorder traversal. What is the time complexity of the most efficient algorithm for doing this? $\Theta(\log n)$ $\Theta(n)$ $\Theta(n\log n)$ None of the above, as the tree cannot be uniquely determined
asked Sep 12, 2014 in DS Kathleen 15.6k views
56 votes
6 answers
5
$N$ items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the record to be deleted. For a decrease-key operation, a pointer is provided to the record on which the operation is to be performed. An algorithm performs the following operations on the list in this ... operations put together? $O(\log^{2} N)$ $O(N)$ $O(N^{2})$ $\Theta\left(N^{2}\log N\right)$
asked Feb 12, 2016 in DS Akash Kanase 14.6k views
75 votes
6 answers
6
Suppose we have a balanced binary search tree $T$ holding $n$ numbers. We are given two numbers $L$ and $H$ and wish to sum up all the numbers in $T$ that lie between $L$ and $H$. Suppose there are $m$ such numbers in $T$. If the tightest upper bound on the time to compute the sum is $O(n^a\log^bn+m^c\log^dn)$, the value of $a+10b+100c+1000d$ is ______.
asked Sep 28, 2014 in DS jothee 13.7k views
43 votes
6 answers
7
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)$
asked Sep 19, 2014 in DS Disha 12.5k views
85 votes
9 answers
8
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 12.4k views
25 votes
4 answers
9
What is the maximum height of any AVL-tree with $7$ nodes? Assume that the height of a tree with a single node is $0$. $2$ $3$ $4$ $5$
asked Sep 22, 2014 in DS Kathleen 12.3k views
61 votes
7 answers
10
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)$
asked Sep 19, 2014 in DS Kathleen 11.7k views
54 votes
6 answers
11
Consider the following operation along with Enqueue and Dequeue operations on queues, where $k$ is a global parameter. MultiDequeue(Q){ m = k while (Q is not empty) and (m > 0) { Dequeue(Q) m = m – 1 } } What is the worst case time complexity of a sequence of $n$ queue operations on an initially empty queue? $Θ(n)$ $Θ(n + k)$ $Θ(nk)$ $Θ(n^2)$
asked Aug 7, 2014 in DS gatecse 11.6k views
44 votes
9 answers
12
Consider the following C program. #include<stdio.h> #include<string.h> int main() { char* c=”GATECSIT2017”; char* p=c; printf(“%d”, (int)strlen(c+2[p]-6[p]-1)); return 0; } The output of the program is _______
asked Feb 14, 2017 in Programming Madhav 11.5k views
58 votes
9 answers
13
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 11.3k views
60 votes
7 answers
14
Consider the C functions foo and bar given below: int foo(int val) { int x=0; while(val > 0) { x = x + foo(val--); } return val; } int bar(int val) { int x = 0; while(val > 0) { x= x + bar(val-1); } ... $6$ and $6$ respectively. Infinite loop and abnormal termination respectively. Abnormal termination and infinite loop respectively. Both terminating abnormally.
asked Feb 14, 2017 in Programming Arjun 10.9k views
16 votes
3 answers
15
A is an array $[2.....6, 2.....8, 2.......10]$ of elements. The starting location is $500$. The location of an element $A(5, 5, 5)$ using column major order is __________.
asked Dec 4, 2015 in DS shikharV 10.8k views
32 votes
8 answers
16
We are given a set of $n$ distinct elements and an unlabeled binary tree with $n$ nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree? $0$ $1$ $n!$ $\frac{1} {n+1} .^{2n}C_n$
asked Sep 29, 2014 in DS jothee 10.8k views
21 votes
9 answers
17
A circular queue has been implemented using a singly linked list where each node consists of a value and a single pointer pointing to the next node. We maintain exactly two external pointers FRONT and REAR pointing to the front node and the rear node of the queue, respectively. Which of the ... rear node points to the front node. (I) only. (II) only. Both (I) and (II). Neither (I) nor (II).
asked Feb 14, 2017 in DS Madhav 10.8k views
67 votes
8 answers
18
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 10.8k views
76 votes
5 answers
19
What is the output of the following C code? Assume that the address of $x$ is $2000$ (in decimal) and an integer requires four bytes of memory. int main () { unsigned int x [4] [3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}; printf ("%u, %u, %u", x + 3, *(x + 3), *(x + 2) + 3); } $2036, 2036, 2036$ $2012, 4, 2204$ $2036, 10, 10$ $2012, 4, 6$
asked Feb 13, 2015 in Programming makhdoom ghaya 10.7k views
26 votes
6 answers
20
A binary search tree contains the value $1, 2, 3, 4, 5, 6, 7, 8$. The tree is traversed in pre-order and the values are printed out. Which of the following sequences is a valid output? $5 \ 3 \ 1 \ 2 \ 4 \ 7 \ 8 \ 6$ $5 \ 3 \ 1 \ 2 \ 6 \ 4 \ 8 \ 7$ $5 \ 3 \ 2 \ 4 \ 1 \ 6 \ 7 \ 8$ $5 \ 3 \ 1 \ 2 \ 4 \ 7 \ 6 \ 8$
asked Sep 29, 2014 in DS Kathleen 10.5k views
...