In what type of graphs does the Floyd-Warshall algorithm excel compared to Dijkstra's and Bellman-Ford algorithms?

  • Dense graphs
  • Graphs with disconnected components
  • Graphs with negative weight edges
  • Sparse graphs
The Floyd-Warshall algorithm excels in handling dense graphs. It has a time complexity of O(V^3) but performs well on graphs where the number of vertices ('V') is not very large, making it suitable for dense graphs compared to Dijkstra's and Bellman-Ford algorithms.

Describe the process of reversing a linked list iteratively and recursively.

  • Iteratively: Reversing the order of nodes using a stack.
  • Iteratively: Swapping pointers to reverse the direction of links.
  • Recursively: Applying recursion with backtracking to reverse the linked list.
  • Recursively: Swapping adjacent elements until the list is reversed.
Iteratively reversing a linked list involves swapping pointers to reverse the direction of links, while the recursive approach involves defining a function that calls itself with a modified context to achieve the reversal.

In binary search, what happens in each step of the algorithm?

  • Adjacent elements are swapped
  • Elements are randomly rearranged
  • The middle element is compared with the target, and the search space is narrowed
  • The smallest element is moved to the end
In each step of the binary search algorithm, the middle element of the current search space is compared with the target value. Depending on the result, the search space is either halved or the target is found.

Dijkstra's algorithm is used to find the _______ path between two nodes in a _______ graph.

  • Fastest, Unweighted
  • Longest, Weighted
  • Optimal, Bipartite
  • Shortest, Directed
Dijkstra's algorithm is used to find the shortest path between two nodes in a weighted graph. The term "shortest" refers to the minimum sum of weights along the path, and "weighted" implies that each edge has an associated numerical value.

How does the load factor affect the performance of a hash table?

  • Higher load factor leads to better performance.
  • It has no impact on performance.
  • Load factor has a linear relationship with performance.
  • Lower load factor leads to better performance.
The load factor is the ratio of the number of elements to the size of the hash table. A lower load factor (more space available) generally leads to better performance, as it reduces the likelihood of collisions and maintains a more efficient search time.

Bellman-Ford algorithm can handle graphs with negative edge weights, but it has a higher _______ complexity compared to Dijkstra's algorithm.

  • Computational
  • Memory
  • Space
  • Time
Bellman-Ford algorithm has a higher time complexity compared to Dijkstra's algorithm. Its time complexity is O(VE), where V is the number of vertices and E is the number of edges. This is due to the algorithm's approach of relaxing edges iteratively for a fixed number of times.

To implement DFS iteratively, a _______ can be used to keep track of nodes to visit next.

  • Linked list
  • Priority queue
  • Queue
  • Stack
To implement DFS iteratively, a stack data structure can be used to keep track of nodes to visit next. This follows the LIFO (Last In, First Out) principle, allowing the algorithm to explore as deeply as possible before backtracking.

Can A* search guarantee finding the optimal solution for all problem instances? Explain why or why not.

  • A* search cannot guarantee optimality in all cases
  • A* search is only applicable to specific problems
  • No, it depends on the specific heuristic used
  • Yes, A* search always finds the optimal solution
A* search does not guarantee finding the optimal solution for all problem instances. While it is complete and optimal in theory, the guarantee depends on the admissibility of the heuristic function. If the heuristic is admissible, A* is guaranteed to find the optimal solution; otherwise, optimality is not assured.

Discuss a real-world application where Breadth-First Search (BFS) is commonly used.

  • Database query optimization
  • Image processing algorithms
  • Natural language processing algorithms
  • Shortest path finding in maps/navigation systems
Breadth-First Search is commonly used in maps/navigation systems to find the shortest path between two locations. BFS ensures that the path found is the shortest because it explores nodes level by level, and the first instance of reaching the destination guarantees the shortest path.

Hash tables commonly use _______ as a method to resolve collisions when two keys hash to the same index.

  • Chaining
  • Hashing
  • Probing
  • Sorting
Hash tables commonly use chaining as a method to resolve collisions. Chaining involves each bucket maintaining a linked list of key-value pairs that hash to the same index. When a collision occurs, the new key-value pair is simply appended to the linked list at that index.