RGPV B.Tech CSE • ADA Unit 2 Notes

ADA Unit 2 Notes: Greedy Method

Learn Greedy Strategy, Optimal Merge Pattern, Huffman Coding, Minimum Spanning Tree, Prim's Algorithm, Kruskal's Algorithm, Fractional Knapsack, Job Sequencing with Deadlines and Dijkstra's Algorithm with exam-oriented explanations for RGPV students.

ADA Unit 2 Study Materials

Read notes, important questions and PYQ analysis for Greedy Method based exam preparation.

📘 Detailed Notes

Complete ADA Unit 2 notes with simple explanations of greedy approach, MST algorithms, Huffman coding and shortest path techniques.

Read Notes

⭐ Important Questions

High-scoring RGPV questions from Greedy Method, Prim's Algorithm, Kruskal's Algorithm, Huffman Coding and Dijkstra's Algorithm.

View Questions

📄 PYQ Analysis

Topic-wise exam trend analysis for greedy algorithms and optimization problems frequently asked in RGPV exams.

Open Analysis

ADA Unit 2 Topics

ADA Unit 2 Complete Exam-Oriented Explanation

ADA Unit 2 mainly focuses on the Greedy Method. Greedy Method is an important algorithm design technique used for solving optimization problems. In this method, the algorithm makes the best possible choice at each step and tries to reach the best overall solution.

The greedy approach is simple and efficient, but it does not work for every problem. It works correctly only when the problem has greedy choice property and optimal substructure. This unit is very important for RGPV examinations because many numerical and algorithm-based questions are asked from greedy algorithms.

Greedy Strategy

Greedy Strategy is a method in which a problem is solved by selecting the best immediate option at every step. Once a choice is made, it is usually not changed later. The main aim is to find an optimum solution by making locally optimum choices.

For example, in Fractional Knapsack, we select items according to the highest profit-to-weight ratio. In Huffman Coding, we repeatedly combine two symbols having the smallest frequency. These are examples of greedy decisions.

Characteristics of Greedy Method

Optimal Merge Pattern

Optimal Merge Pattern is used to merge multiple sorted files with minimum cost. The greedy idea is to always merge the two smallest files first. This reduces the total number of comparisons and gives minimum merge cost.

This concept is frequently asked in exams with numerical examples. Students should practice solving optimal merge pattern using sorted file sizes and cost calculation after each merge.

Huffman Coding

Huffman Coding is a greedy algorithm used for lossless data compression. It assigns shorter binary codes to characters with higher frequency and longer codes to characters with lower frequency. This reduces the total number of bits required to represent the data.

Huffman Coding uses a binary tree. The two nodes with the lowest frequencies are combined repeatedly until a single tree is formed. The left edge is usually represented by 0 and the right edge by 1.

Minimum Spanning Tree

A Minimum Spanning Tree is a subset of edges of a connected weighted graph that connects all vertices with minimum total edge weight and without forming any cycle. MST is useful in network design, road construction, wiring and communication systems.

Prim's Algorithm

Prim's Algorithm is a greedy algorithm used to find the Minimum Spanning Tree. It starts from any vertex and repeatedly selects the minimum weight edge that connects a visited vertex to an unvisited vertex.

In RGPV exams, students should write the definition, steps, example graph and final MST cost. Prim's Algorithm is especially useful for dense graphs.

Kruskal's Algorithm

Kruskal's Algorithm is another greedy algorithm used to find the Minimum Spanning Tree. It first sorts all edges in increasing order of weight and then selects edges one by one, making sure that no cycle is formed.

Kruskal's Algorithm is suitable for sparse graphs. The cycle detection can be done using disjoint set or union-find data structure.

Knapsack Problem

The Knapsack Problem is an optimization problem where we have a bag with limited capacity and a set of items with weights and profits. The goal is to maximize profit without exceeding the capacity of the knapsack.

In Fractional Knapsack, items can be divided into fractions. It is solved using greedy approach by selecting items according to maximum profit per unit weight.

Job Sequencing with Deadlines

Job Sequencing with Deadlines is used to schedule jobs in such a way that maximum profit is obtained. Each job has a deadline and profit. The greedy strategy is to select jobs in decreasing order of profit and place each job in the latest available slot before its deadline.

Single Source Shortest Path

Single Source Shortest Path means finding the shortest path from one source vertex to all other vertices in a weighted graph. Dijkstra's Algorithm is commonly used for this purpose when all edge weights are non-negative.

Dijkstra's Algorithm

Dijkstra's Algorithm is a greedy algorithm used to find the shortest path from a source vertex to all other vertices in a graph with non-negative weights. At every step, it selects the vertex with the minimum temporary distance and updates the distances of its adjacent vertices.

Exam Preparation Tips

For ADA Unit 2, students should focus on algorithms, examples, diagrams, tables and cost calculations. Important topics include Huffman Coding, Prim's Algorithm, Kruskal's Algorithm, Fractional Knapsack, Job Sequencing and Dijkstra's Algorithm.

In long-answer questions, always write the definition, greedy strategy, algorithm steps, example, time complexity and conclusion. This format helps in scoring better marks in RGPV semester examination.

Important Greedy Algorithms and Time Complexities

Algorithm Purpose Time Complexity
Prim's Algorithm Minimum Spanning Tree O(E log V)
Kruskal's Algorithm Minimum Spanning Tree O(E log E)
Dijkstra's Algorithm Single Source Shortest Path O(E log V)
Huffman Coding Data Compression O(n log n)
Fractional Knapsack Maximum Profit Selection O(n log n)

ADA Unit 2 Important Questions

ADA Unit 2 PYQ Analysis

In RGPV exams, ADA Unit 2 questions are commonly asked from algorithm execution and numerical problem solving. Prim's Algorithm, Kruskal's Algorithm, Huffman Coding and Dijkstra's Algorithm are very important for long-answer questions.

Fractional Knapsack and Job Sequencing with Deadlines are often asked as numerical questions. Students should practice step-by-step tables because marks are usually given for method, intermediate steps and final answer.

Frequently Asked Questions

What is Greedy Method?

Greedy Method is an algorithm design technique that selects the best immediate option at each step to reach an optimum solution.

Which algorithms are based on Greedy Technique?

Prim's Algorithm, Kruskal's Algorithm, Huffman Coding, Dijkstra's Algorithm, Fractional Knapsack and Job Sequencing are based on greedy approach.

Is ADA Unit 2 important for RGPV exams?

Yes, ADA Unit 2 is very important because many numerical and algorithm-based questions are asked from greedy algorithms.

Which topics are most important in ADA Unit 2?

Huffman Coding, Prim's Algorithm, Kruskal's Algorithm, Fractional Knapsack, Job Sequencing and Dijkstra's Algorithm are most important.