Greedy Algorithm is an approach that makes the best choice at each step to find an optimal solution. Practice these multiple-choice questions to understand greedy strategies and problem-solving techniques with answers.
1. Question: Greedy Algorithms are:
Answer: b. Greedy Algorithms assume locally correct decisions to lead towards a global optimum solution.
Explanation: Greedy Algorithms choose what seems the best right now in the hopes that their choices will result in a global solution. But they do not provide the best answer in every given situation.
2. Question: What Greedy Algorithm can be widely used to solve the above-mentioned problems?
Answer: d. All of the above
Explanation: TSP, MST and the Shortest Path among other problems are solvable using Greedy Algorithms.
3. Question: The main design principle employed by the Greedy Algorithm in the Huffman coding is:
Answer: b. The use of codewords with variable lengths by the frequencies
Explanation: Under Huffman coding, a Greedy Algorithm is used to allocate shorter codewords for the more frequent symbols and longer ones for less frequent so that the encoding is optimized.
4. Question: What is the main benefit of Greedy Algorithms?
Answer: b. Simplicity and the implementation
Explanation: Greedy Algorithms are characterized by their simplicity and ease of implementation, which makes them very applicable to a variety of different problems.
5. Question: What is the main weakness of the Greedy Algorithms?
Answer: a. Inability to handle large datasets
Explanation: If the size of datasets is very large, Greedy Algorithms may not be very effective for some specific problems because they are based on locally optimal decisions but without implementing global considerations.
6. Question: Which of the following problems does not use any optimization?
Answer: d. Linear Search
Explanation: Linear Search is an algorithm for searching, not a problem of optimization where the search must find the optimal solution.
7. Question: In Dijkstra's algorithm for finding the Shortest Path, what is the Greedy Choice at each step?
Answer: a. Choosing the shortest edge
Explanation: Dijkstra's algorithm adopts a greedy strategy by choosing the shortest distance edge at every step.
8. Question: What is the Greedy Algorithm used for finding the Minimum Spanning Tree?
Answer: d. Prim's Algorithm
Explanation: Prim's Algorithm is a very greedy approach to finding the MST of any given graph.
9. Question: What is the main goal of the Greedy Choice in the Fractional Knapsack Problem?
Answer: c. Maximizing total value
Explanation: However, the greedy choice in the Fractional Knapsack Problem is the selection of items with maximum value.
10. Question: Which of the following describes what a Greedy Algorithm is?
Answer: b. Global optimization at each step is important.
Explanation: Greedy Algorithms perform global optimization at every step, in the hope of reaching a globally optimal plan.
11. Question: What is the order of complexity for Huffman Coding using a Greedy Algorithm?
Answer: a. O(n log n)
Explanation: The time complexity of Huffman Coding is O(n log n) based on the use of a Greedy Algorithm.
12. Question: What is the problem that is not usually solved through a Greedy Algorithm?
Answer: c. Longest Common Subsequence
Explanation: Longest Common Subsequence is a dynamic programming algorithm and not a Greedy Approach.
13. Question: What is the Greedy Choice at each step in the Activity Selection Problem?
Answer: b. Selecting the activity with the last end time
Explanation: In the Activity Selection Problem, The Greedy Choice is choosing the activity that has the earliest start time at each step.
14. Question: What defines the Greedy Algorithms?
Answer: a. They choose locally and optimally at every stage.
Explanation: Greedy Algorithms choose the best locally available options at each stage, in the hope of getting a global minimum.
15. Question: How many of the given problems are solved using the Greedy Algorithms?
Answer: a. Sorting
Explanation: Minimum Spanning Tree (Kruskal's and Prim's algorithms) are solved using the Greedy Algorithms.
16. Question: How is Huffman Coding applied?
Answer: c.Data compression
Explanation: Huffman coding is a type of Greedy Algorithm recommended for data compression.
17. Question: What type of data structure is typically used in Dijkstra's algorithm to determine the shortest possible path?
Answer: c. Priority Queue
Explanation: Utilizing a Priority Queue (a heap structure), Dijkstra's algorithm records and sorts the vertices according to their tentative distances.
18. Question: What does the Fractional Knapsack problem cover?
Answer:c. Maximization of the total value within a weight constraint
Explanation: In the Fractional Knapsack problem, items are selected according to their value-to-weight ratio and maximize the total value within a weight restriction.
19. Question: What is the unique characteristic of Greedy Algorithms that solve the Activity Selection Problem?
Answer: a. To increase the number of activities, there are many options available to consider.
Explanation: The activity selection problem is based on selecting the most activities without having conflicting time intervals.
20. Question: For the Job Sequencing Problem's Greedy Algorithm, what is a job-selection criterion if two jobs have equal deadlines?
Answer: b. Choose the job that brings in the most revenue
Explanation: The criterion for evaluating two jobs with the same deadline in the Job Sequencing Problem is to choose a job having the highest profit.
21. Question: What is the major weakness of the Greedy Algorithms?
Answer: b. They may not always lead to the global optimum
Explanation: The main disadvantage of Greedy Algorithms is that they do not necessarily ensure the globally optimal solution.
22. Question: What Greedy Algorithm is designed for finding the shortest path in the weighted graphs with nonnegative edge weights?
Answer: b. Dijkstra's Algorithm
Explanation: Dijkstra's Algorithm is applied to find the shortest path in a weighted graph, where the edge weights are non-negative.
23. Question: What is the basic concept behind assigning the shorter codes to symbols in the Greedy Algorithm of the Huffman Coding problem?
Answer:b. To decrease the length of the encoded data
Explanation: In Huffman Coding, shorter codes are given to the symbols to reduce the length of encoded data.
24. Question: Which of the following problems is an uncommon application of the Greedy Algorithms?
Answer: d. Matrix Multiplication
Explanation: A Greedy Algorithm rarely solves the matrix multiplication. It is commonly dealt with using dynamic programming techniques.
25. Question: What is the core idea of the Greedy Algorithms?
Answer:b. Local optimization
Explanation: Greedy Algorithms make the locally optimal decisions at each stage hoping to end up with a global optimum.
26. Question: What problems can be solved using the Greedy Algorithms?
Answer:d. All of the above
Explanation: Optimization problems such as the Knapsack Problem and Shortest path problem often use Greedy Algorithms.
27. Question: How does the Kruskal's algorithm work?
Answer: b. Minimum Spanning Tree
Explanation: The application of Kruskal's algorithm determines the Minimum Spanning Tree for a given graph.
28. Question: What kinds of characters do the shorter codes receive in Huffman Coding?
Answer: a. Frequent characters
Explanation: Huffman Coding uses shorter code lengths for the characters that are occurring more often, reducing the overall lengths of their codes.
29. Question: What is a greedy approach to the Job Scheduling problem?
Answer: d. Minimum Completion Time First
Explanation: Job Scheduling Greedy applies the principle of minimal completion times for scheduling jobs.
30. Question: What does Dijkstra's algorithm seek to achieve?
Answer: b. The shortest Path in a weighted graph.
Explanation: In a weighted graph, the algorithm used to locate the shortest path method is known as Dijkstra's.
31. Question: What is the Greedy algorithm for the Fractional Knapsack Problem?
Answer: d. Greedy Choice Property
Explanation: The Fractional Knapsack Problem Greedy algorithm uses the greediness selection property.
32. Question: What is the greedy decision made at each iteration in the Activity Selection Problem?
Answer: c. Select the activity that finishes the earliest.
Explanation: The greedy solution to the activity selection problem is selecting an active with the earliest finisher time.
33. Question: What is the Greedy Choice Property?
Answer: a. Making the locally optimal choice in each stage leads to a globally optimum solution.
Explanation: The Greedy Choice Property is based on the idea that choosing locally optimal options at each stage yields a globally ideal solution.
34. Question: Which algorithm employs a priority queue for its implementation?
Answer: d. Both A and B
Explanation: Dijkstra's Algorithm and Prim's Algorithm commonly employ the priority queue for a very efficient implementation.
35. Question: How is The Time Complexity of the Huffman Coding?
Answer: O(n log n)
Explanation: The time complexity of the Huffman Coding is O(n log n), where for each character there is n.
36. Question: In the Knapsack Problem, if a part of an item can be put in the knapsack, it is called:
Answer: a. Fractional Knapsack Problem
Explanation: When a component of an item can be easily removed, it is called the Fractional Knapsack Problem.
37. Question: What Greedy Algorithm is commonly used to optimize the files' merge pattern?
Answer: d. Optimal Merge Pattern
Explanation: The Optimal Merge Pattern is a Greedy Algorithm to find the best way of merging several sorted sequences.
38. Question: How can we determine the Greedy choice in the Huffman Coding algorithm?
Answer: b. Select the most frequent character in the given sentence
Explanation: In Huffman Coding, the selection of a greedy choice is to initially choose the character with the most frequency.
39. Question: What is NOT the feature of Greedy Algorithms?
Answer: d. Backtracking
Explanation: Greedy Algorithms do not have backtracking as a characteristic. Greedy Algorithms aim at the local optimality at all times.
40. Question: What is the runtime performance of searching an element in a balanced BST?
Answer: a. O(log n)
Explanation: Finding an element in a balanced BST has the time complexity O(log n).
41. Question: What data structure has the Last In, First Out (LIFO) ordering?
Answer: b. Stack
Explanation: A stack obeys the principle of Last In, First Out (LIFO) in it.
42. Question: Why do we have the breadth-first search (BFS) algorithm?
Answer: c. Go through a tree or graph vertically
Explanation: Traversing a tree or graph with BFS means going from one level to the next.
43. Question: What sorting algorithm has the best average-case time complexity?
Answer: b. Merge Sort
Explanation: The average-case time complexity of Merge Sort is O(n log n).
44. Question: Which of the following is a dynamic programming algorithm?
Answer: c. Bellman-Ford
Explanation:A dynamic programming algorithm called the Bellman-Ford is used to find the shortest paths in a weighted graph.
We request you to subscribe our newsletter for upcoming updates.