You can prepare effectively for Software Development DSA in C++ with this dedicated MCQ Practice Test (available with solutions) on the important topic of "Test: Dynamic Programming - 2". These 15 questions have been designed by the experts with the latest curriculum of Software Development 2026, to help you master the concept.
Test Highlights:
Sign up on EduRev for free to attempt this test and track your preparation progress.
Which algorithm is used to find the shortest path in a graph with negative edge weights?
Detailed Solution: Question 1
Which algorithm is used to find the shortest path between all pairs of vertices in a graph?
Detailed Solution: Question 2
Which data structure is typically used to implement the Bellman–Ford algorithm efficiently?
Detailed Solution: Question 3
Which data structure is typically used to implement the Bellman–Ford algorithm efficiently?
Detailed Solution: Question 4
Detailed Solution: Question 5
What will be the output of the following code?
#include <iostream>
using namespace std;
#define INF 99999
int main() {
int graph[4][4] = { {0, 3, INF, 5},
{2, 0, INF, 4},
{INF, 1, 0, INF},
{INF, INF, 2, 0} };
for (int k = 0; k < 4; k++) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (graph[i][j] > graph[i][k] + graph[k][j]) {
graph[i][j] = graph[i][k] + graph[k][j];
}
}
}
}
cout << graph[1][3];
return 0;
}
Detailed Solution: Question 6
What will be the output of the following code?
#include <iostream>
using namespace std;
#define INF 99999
int main() {
int graph[4][4] = { {0, INF, -2, INF},
{4, 0, 3, INF},
{INF, INF, 0, 2},
{INF, -1, INF, 0} };
for (int k = 0; k < 4; k++) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (graph[i][j] > graph[i][k] + graph[k][j]) {
graph[i][j] = graph[i][k] + graph[k][j];
}
}
}
}
cout << graph[3][2];
return 0;
}
Detailed Solution: Question 7
What will be the output of the following code?
#include <iostream>
using namespace std;
#define INF 99999
int main() {
int graph[4][4] = { {0, 3, 6, 15},
{INF, 0, -2, INF},
{INF, INF, 0, 2},
{1, INF, INF, 0} };
for (int k = 0; k < 4; k++) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (graph[i][j] > graph[i][k] + graph[k][j]) {
graph[i][j] = graph[i][k] + graph[k][j];
}
}
}
}
cout << graph[0][3];
return 0;
}
Detailed Solution: Question 8
What will be the output of the following code?
#include <iostream>
using namespace std;
#define INF 99999
int main() {
int graph[4][4] = { {0, 3, INF, 10},
{INF, 0, INF, 4},
{1, INF, 0, INF},
{INF, INF, 2, 0} };
for (int k = 0; k < 4; k++) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (graph[i][j] > graph[i][k] + graph[k][j]) {
graph[i][j] = graph[i][k] + graph[k][j];
}
}
}
}
cout << graph[2][3];
return 0;
}
Detailed Solution: Question 9
What will be the output of the following code?
#include <iostream>
using namespace std;
#define INF 99999
int main() {
int graph[4][4] = { {0, INF, INF, 10},
{4, 0, INF, INF},
{1, INF, 0, INF},
{INF, 5, 2, 0} };
for (int k = 0; k < 4; k++) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (graph[i][j] > graph[i][k] + graph[k][j]) {
graph[i][j] = graph[i][k] + graph[k][j];
}
}
}
}
cout << graph[3][1];
return 0;
}
Detailed Solution: Question 10
Which algorithm can be used to find the shortest path in a directed acyclic graph (DAG)?
Detailed Solution: Question 11
Which of the following statements is true regarding the Bellman–Ford algorithm?
Detailed Solution: Question 12
Which algorithm can be used to find the shortest path between all pairs of vertices in a directed graph?
Detailed Solution: Question 13
The Floyd Warshall algorithm has a time complexity of:
Detailed Solution: Question 14
Which technique is used to solve problems in a multi-stage graph using dynamic programming?
Detailed Solution: Question 15
152 videos|118 docs|24 tests |