A candidate is solving a problem on dynamic programming for the Infosys coding round. The problem involves overlapping subproblems and optimal substructure. What is the minimum number of steps to solve such problems?
A1 step - direct solution
B2 steps - define subproblems and find recurrence
C3 steps - define subproblems, find recurrence, implement with memoization/tabulation
D4 steps - analyze, define, find recurrence, and optimize further
Correct Answer:
C. 3 steps - define subproblems, find recurrence, implement with memoization/tabulation
Explanation:
Dynamic programming requires defining subproblems, establishing recurrence relations, and implementing solutions using memoization or tabulation for optimization.
A complex algorithmic problem in Infosys placement requires analyzing a graph with weighted edges. What would be the optimal approach for finding the shortest path?
ADepth-first search (DFS)
BBreadth-first search (BFS)
CDijkstra's algorithm for weighted graphs
DLinear search
Correct Answer:
C. Dijkstra's algorithm for weighted graphs
Explanation:
Dijkstra's algorithm is the optimal choice for finding shortest paths in weighted graphs with non-negative weights, with O(E log V) complexity.