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 »

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 »

What is the time complexity of inserting an element into a sorted linked list?

What is the time complexity of inserting an element into a sorted linked list? a) O(1) b) O(log n) c) O(n) d) O(n log n) Answer: c) O(n) Explanation: Inserting an element into a sorted linked list has a time complexity of O(n) because it requires traversing the list to find the correct insertion point.

What is the time complexity of inserting an element into a sorted linked list? Read More »

Which sorting algorithm is considered a comparison-based sort?

Which sorting algorithm is considered a comparison-based sort? a) Radix Sort b) Counting Sort c) Quick Sort d) Bucket Sort Answer: c) Quick Sort Explanation: Quick Sort is a comparison-based sorting algorithm, meaning it sorts elements by comparing them to one another. The efficiency of Quick Sort is based on how well the pivot element

Which sorting algorithm is considered a comparison-based sort? 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 »

Which of the following data structures is non-linear?

Which of the following data structures is non-linear? a) Array b) Linked List c) Stack d) Graph Answer: d) Graph Explanation: A graph is a non-linear data structure consisting of nodes (also called vertices) and edges connecting the nodes. It is used to represent networks, such as social networks or communication networks, where relationships between

Which of the following data structures is non-linear? Read More »

Scroll to Top