sample questions

advertisement
Algorithm sample question for segment – 4,5,6,7,8
Segment -4
1.
2.
3.
4.
Define: Greedy Algorithm.
Write down the differences between dynamic programming and greedy algorithm?
Define: An activity-selection problem.
Find all possible optimal set for the following data set using activity selection problem:
i
1
2
3
4
5
6
7
Si
1
3
5
7
6
13
18
fi
4
5
6
11
12
18
22
Answer: a) {1,3,4,6,7} b){1,3,5,6,7} c) {2,3,4,6,7} d) {2,3,5,6,7}
5. What are the applications of activity-selection problem.
6. What are the differences between 0/1 knapsack problem and fractional knapsack
problem? Give example.
7. Why 0/1 knapsack problem can’t return optimal solution in greedy method?
8. Define: variable-length code and fixed-length code with example.
9. Generate a Huffman tree and determine an optimal Huffman code for the following
text:
“to be or not to be it is true”
10. Generate a Huffman tree and determine an optimal Huffman code for the following
set of frequencies:
a:45, b:13, c:12, d:16, e:9,f:5
11. What are the applications of Huffman code.
12. Consider the following graph and apply the traveling salesperson problem to find the
optimal tour:
10
A
15
B
11
13
25
D
14 18
15
13 20
14
C
17
Answer: 1,2,4,3,1
Segment -5
1. What are the two ways to represent a graph in the computer memory? Explain with
example.
2. Discuss the two techniques of graph traversal.
3. Give example of: complete graph, null graph, adjacent matrix, adjacent list, degree,
sub-graph, loop, cycle, directed graph, undirected graph.
4. What are the differences between graph and tree?
5. Show how Breadth First Search works on the following graph and consider E as the
source:
B
A
E
F
G
D
C
6. Show how Depth First Search works on the following graph and consider E as the
source:
B
A
E
F
D
G
C
7. Consider the following graph and find all possible spanning tree:
A
B
D
C
F
8. Construct minimum spanning tree from the following graph using Prim’s algorithm
and consider E as the source:
A
50
90
85
F
75
E
G
45
5
25
D
35
3
70
3
B
10
C
9. Construct minimum spanning tree from the following graph using Kruskal algorithm.
A
50
90
85
F
D
35
3
75
E
70
3
B
10
45
5
25
G
C
10. Define: Spanning tree and minimum spanning tree.
11. Write down the differences between BFS and DFS.
12. Briefly discuss the time complexity and space complexity of BFS and DFS.
Segment -6
1. Define: Single source shortest path and all pair shortest path.
2. Write down the differences between Dijkstra’s Algorithm and Bellman-Ford
algorithm?
3. Consider the following weighted, directed graph. Run the Dijkstra’s algorithm to find
single source shortest path on the graph using A as source.
B
5
A
9
1
E
7
3
6
C
4
D
4. Consider the following weighted, directed graph. Run the Bellman-Ford algorithm to
find single source shortest path on the graph using A as source.
B
5
A
9
1
E
7
3
6
C
D
4
5. Find the Floyd-Warshall algorithm on the following weighted directed graph. Also
show the matrix D(K) and ∏(K) that results for each iteration.
1
3
5
4
2
8
2
-4
1
-5
7
4
6
3
Segment -7
1.
2.
3.
4.
5.
Define: Recurrence and Recurrence tree. Give example.
Why we need Recurrence?
Why we should solve Recurrences?
Briefly describe NP-complete and NP-Hard problem?
Briefly describe all NP-complete problems are NP-hard, but all NP-hard problems are
not NP-complete.
6. Define: SATISFIABILITY and Reducibility.
7. Define: Backtracking.
8. Write an algorithm to solve n-queen problem.
9. Discuss n-queen problem with backtracking.
10. Briefly discuss n-queen problem complexity.
11. Briefly discuss Branch and Bound.
12. Why Bounding functions is used?
13. When node elimination is done in Branch and Bound problem?
14. What are the applications of Branch and Bound?
Segment -8
1. What is Computational Geometry? What are the application areas of computational
geometry?
2. How we can determine if two lines are collinear?
3. How we can determine if two line segments intersect?
4. Define: convex hull?
5. Write down Graham’s scan algorithm of convex hull construction?
6. Consider the following points and find convex hull using Graham’s scan algorithm:
P1(0.7, 2.7), P2(1.8,3.2),P3(2.6,0.8),P4(0.9,2.5),P5(0.6,0.7),P6(1.5,0.6),
P7(1.5,2.5),P8(2,1.5), P9(1.0,2.0),P10(0.8,1.5). Answer: P1,P2,P3,P5,P6
7. Write down Euclid’s algorithm of Greatest Common Divisor (GCD).
8. Find gcd(30,21) using Euclid’s algorithm.
9. What is the running time of Euclid’s algorithm to calculate GCD.
10. Write down the algorithm to calculate
xn mod m.
11. Write an efficient algorithm of prime number testing.
12. To test whether a number is prime or not why do we have to test whether it is
divisible only upto the square root of that number ?
Y-Values
3.5
3
2.5
2
Y-Values
1.5
1
0.5
0
0.5
1
2
4
Download