The subset-sum problem is defined as follows. Given a set of n positive integers,S = {a1 , a2 , a3 ,..., an }, and positive integer W, is there a subset of S whose elements sum to W? A dynamic program for solving this
X[i, j] = X[i - 1, j] ∨ X[i, j - ai]
X[i, j] = X[i - 1, j] ∨ X[i - 1, j - ai]
X[i, j] = X[i - 1, j] ∧ X[i, j - ai]
X[i, j] = X[i - 1, j] ∧ X[i -1, j - ai]
Algorithms
Dynamic-Programming
GATE 2008 CS
The subset-sum problem is defined as follows. Given a set of n positive integers, S = {a1 , a2 , a3 ,..., an }, and positive integer W, is there a subset of S whose elements sum to W? A dynamic program for solving this
Which entry of the array X, if TRUE, implies that there is a subset whose elements sum to W?
Algorithms
Dynamic-Programming
GATE 2008 CS
A max-heap is a heap where the value of each parent is greater than or equal to the value of its children. Which of the following is a max-heap?
Data Structures
gate 2011
An algorithm to find the length of the longest monotonically increasing sequence of numbers in an array A[0 :n-1] is given below. Let Li denote the length of the longest monotonically increasing sequence starting at index i in the array
Which of the following statements is TRUE?
The algorithm uses dynamic programming paradigm
The algorithm has a linear complexity and uses branch and bound paradigm
The algorithm has a non-linear polynomial complexity and uses branch and bound paradigm
The algorithm uses divide and conquer paradigm.
Algorithms
Dynamic-Programming
gate 2011
Which of the given options provides the increasing order of asymptotic complexity of functions
Algorithms
gate 2011
Four matrices M1, M2, M3 and M4 of dimensions pxq, qxr, rxs and sxt respectively can be multiplied is several ways with different number of total scalar multiplications. For example, when multiplied as ((M1 X M2) X (M3 X M4)), the total number of multiplications is pqr + rst + prt. When multiplied as (((M1 X M2) X M3) X M4), the total number of scalar multiplications is pqr + prs + pst. If p = 10, q = 100, r = 20, s = 5 and t = 80, then the number of scalar multiplications needed is:
Algorithms
Dynamic-Programming
gate 2011
Database table by name Loan_Records is given below.
Borrower Bank_Manager Loan_Amount
Ramesh Sunderajan 10000.00
Suresh Ramgopal 5000.00
Mahesh Sunderajan 7000.00
What is the output of the following SQL query?
SELECT Count(*)
FROM ( ( SELECT Borrower, Bank_Manager
FROM Loan_Records) AS S
NATURAL JOIN ( SELECT Bank_Manager, Loan_Amount
FROM Loan_Records) AS T );
DBMS
gate 2011
An undirected graph G(V, E) contains n ( n > 2 ) nodes named v1 , v2 ,….vn. Two nodes vi , vj are connected if and only if 0 < |i – j| <= 2. Each edge (vi, vj ) is assigned a weight i + j. A sample graph with n = 4 is shown below.
What will be the cost of the minimum spanning tree (MST) of such a graph with n nodes?
Algorithms
Minimum-Spanning-Tree
gate 2011
An undirected graph G(V, E) contains n ( n > 2 ) nodes named v1 , v2 ,….vn. Two nodes vi , vj are connected if and only if 0 < |i – j| <= 2. Each edge (vi, vj ) is assigned a weight i + j. A sample graph with n = 4 is shown below.
The length of the path from v5 to v6 in the MST of previous question with n =10 is
Algorithms
Minimum-Spanning-Tree
gate 2011
Consider the DAG with Consider V = {1, 2, 3, 4, 5, 6}, shown below. Which of the following is NOT a topological ordering?
Data Structures
Graphs
GATE 2007 CS
The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of nodes in a binary tree of height h is:
Data Structures
Binary-Trees
GATE 2007 CS
The maximum number of binary trees that can be formed with three unlabeled nodes is:
Data Structures
Binary-Trees
GATE 2007 CS
Which of the following sorting algorithms has the lowest worst-case complexity?
Algorithms
Time-Complexity
GATE 2007 CS
Consider the following segment of C-code:
int j, n;
j = 1;
while (j <= n)
j = j*2;
The number of comparisons made in the execution of the loop for any n > 0 is: Base of Log is 2 in all options.
Algorithms
Time-Complexity
GATE 2007 CS
The following postfix expression with single digit operands is evaluated using a stack:
8 2 3 ^ / 2 3 * + 5 1 * -
Note that ^ is the exponentiation operator. The top two elements of the stack after the first * is evaluated are:
Data Structures
GATE 2007 CS
Stacks
The inorder and preorder traversal of a binary tree are d b e a f c g and a b d e c f g, respectively. The postorder traversal of the binary tree is:
Data Structures
Binary-Trees
GATE 2007 CS
Consider a hash table of size seven, with starting index zero, and a hash function (3x + 4) mod 7. Assuming the hash table is initially empty, which of the following is the contents of the table when the sequence 1, 3, 8, 10 is inserted into the table using closed hashing? Note that ‘_’ denotes an empty location in the table.
Data Structures
Hashing
GATE 2007 CS
In an unweighted, undirected connected graph, the shortest path from a node S to every other node is computed most efficiently, in terms of time complexity, by
Dijkstra’s algorithm starting from S
Performing a DFS starting from S.
Performing a BFS starting from S
Algorithms
Time-Complexity
GATE 2007 CS
A complete n-ary tree is a tree in which each node has n children or no children. Let I be the number of internal nodes and L be the number of leaves in a complete n-ary tree. If L = 41, and I = 10, what is the value of n?
Data Structures
GATE 2007 CS
In the following C function, let n >= m.
int
gcd(n,m)
{
if
(n%m ==0)
return
m;
n = n%m;
return
gcd(m,n);
}
How many recursive calls are made by this function?
Algorithms
Time-Complexity
GATE 2007 CS