DSA

Which algorithm is used to detect a negative cycle in a graph?

Which algorithm is used to detect a negative cycle in a graph? a) Bellman-Ford Algorithm b) Dijkstra’s Algorithm c) Floyd-Warshall Algorithm d) Prim’s Algorithm Answer: a) Bellman-Ford Algorithm Explanation: The Bellman-Ford algorithm is used to detect negative weight cycles in a graph. By running the algorithm for one additional iteration beyond the number of vertices,

Which algorithm is used to detect a negative cycle in a graph? Read More »

What is the main advantage of a doubly linked list over a singly linked list?

What is the main advantage of a doubly linked list over a singly linked list? a) Allows for traversal in both directions b) Uses less memory c) Easier to implement d) Supports faster sorting Answer: a) Allows for traversal in both directions Explanation: The main advantage of a doubly linked list over a singly linked

What is the main advantage of a doubly linked list over a singly linked list? Read More »

What is a red-black tree?

What is a red-black tree? a) A self-balancing binary search tree where each node has an extra color attribute b) A binary heap with two colors c) A balanced AVL tree with different color properties d) A linked list where each node has a color Answer: a) A self-balancing binary search tree where each node

What is a red-black tree? Read More »

Which of the following algorithms is used to find the shortest path in a graph with negative weights?

Which of the following algorithms is used to find the shortest path in a graph with negative weights? a) Dijkstra’s Algorithm b) Bellman-Ford Algorithm c) Kruskal’s Algorithm d) Floyd-Warshall Algorithm Answer: b) Bellman-Ford Algorithm Explanation: The Bellman-Ford algorithm is used to find the shortest path in graphs with negative weights. Unlike Dijkstra’s algorithm, Bellman-Ford can

Which of the following algorithms is used to find the shortest path in a graph with negative weights? Read More »

Which of the following algorithms is used to detect a cycle in a graph?

Which of the following algorithms is used to detect a cycle in a graph? a) Depth-First Search (DFS) b) Breadth-First Search (BFS) c) Dijkstra’s Algorithm d) Kruskal’s Algorithm Answer: a) Depth-First Search (DFS) Explanation: Depth-First Search (DFS) is commonly used to detect cycles in a graph. By tracking visited nodes and using a recursive or

Which of the following algorithms is used to detect a cycle in a graph? Read More »

Which data structure is used to find the shortest path in an unweighted graph?

Which data structure is used to find the shortest path in an unweighted graph? a) Stack b) Queue c) Priority Queue d) Array Answer: b) Queue Explanation: Breadth-First Search (BFS), which uses a queue, is used to find the shortest path in an unweighted graph. BFS explores all vertices at the current level before moving

Which data structure is used to find the shortest path in an unweighted graph? Read More »

Scroll to Top