0% found this document useful (0 votes)
37 views2 pages

CGPT 2

The document describes several greedy algorithms and dynamic programming problems. It explains the scenarios for the knapsack problem, job sequencing with deadlines, optimal merge patterns, and Huffman coding, and how each uses a greedy approach. It also outlines scenarios involving multistage graphs, all pairs shortest paths, 0-1 knapsack problem, chained matrix multiplication, longest common subsequence, and the travelling salesperson problem, and how dynamic programming can be applied to find optimal solutions for each.

Uploaded by

Gourav Dubey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

CGPT 2

The document describes several greedy algorithms and dynamic programming problems. It explains the scenarios for the knapsack problem, job sequencing with deadlines, optimal merge patterns, and Huffman coding, and how each uses a greedy approach. It also outlines scenarios involving multistage graphs, all pairs shortest paths, 0-1 knapsack problem, chained matrix multiplication, longest common subsequence, and the travelling salesperson problem, and how dynamic programming can be applied to find optimal solutions for each.

Uploaded by

Gourav Dubey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Greedy Algorithms:

1. Knapsack Problem:
 Scenario: Imagine you have a knapsack with a limited weight capacity,
and you want to maximize the total value of items you can carry.
 Approach: Greedily select items based on their value-to-weight ratio
until the knapsack is full.
2. Job Sequencing with Deadlines:
 Scenario: You have multiple jobs with associated deadlines and profits.
You need to schedule these jobs to maximize the total profit.
 Approach: Sort jobs by their profits and schedule them in a way that
doesn't miss any deadlines.
3. Optimal Merge Patterns:
 Scenario: Given a set of files with different sizes, you want to merge
them efficiently.
 Approach: Greedily merge the smallest available files at each step to
minimize the overall merging cost.
4. Huffman Coding:
 Scenario: You want to encode a set of characters efficiently to
minimize the total encoded length.
 Approach: Build a Huffman Tree by repeatedly combining the two
least frequent characters until a single tree is formed.

Dynamic Programming:

1. Multistage Graph:
 Scenario: Represent a process with multiple stages, each with different
costs. Find the optimal path through these stages.
 Approach: Use dynamic programming to find the minimum cost path
through the stages.
2. All Pairs Shortest Paths:
 Scenario: Find the shortest paths between all pairs of vertices in a
graph.
 Approach: Utilize dynamic programming to compute the shortest
paths step by step.
3. 0-1 Knapsack:
 Scenario: Similar to the Knapsack Problem, but now you can't take
fractions of items.
 Approach: Use dynamic programming to fill a table with the maximum
value achievable at each subcapacity.
4. Chained Matrix Multiplication:
 Scenario: Given a sequence of matrices, find the most efficient way to
multiply them.
 Approach: Dynamic programming is used to minimize the total
number of scalar multiplications.
5. Longest Common Subsequence:
 Scenario: Find the longest subsequence present in two given
sequences.
 Approach: Dynamic programming is employed to build a table of
lengths of common subsequences.
6. Travelling Salesperson Problem:
 Scenario: A salesperson wants to visit each city exactly once and return
to the starting city with the minimum possible total distance traveled.
 Approach: Dynamic programming techniques can be applied to find
the optimal tour.

You might also like