Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary - ADVANCE DATA STRUCTURE

Rating
-
Sold
-
Pages
9
Uploaded on
16-12-2024
Written in
2024/2025

It provides you with key concepts of Advance Data Structure like: 1.Job Sequencing with Deadline ack 3.Minimum cost spanning tree 4.Single Source Shortest Path

Institution
Course

Content preview

Greedy Method: General Explanation and Example
1. Introduction to the Greedy Method
The Greedy Method is an algorithmic paradigm used to solve optimization problems. It builds up a
solution piece by piece, always choosing the next piece that offers the most immediate benefit. This
approach does not always yield the optimal solution for all problems, but it works well for many, especially
those that have the "greedy-choice property" and "optimal substructure."

Greedy-Choice Property: A global optimal solution can be arrived at by selecting a local optimal choice.
Optimal Substructure: An optimal solution to the problem contains optimal solutions to its subproblems.
2. General Steps of the Greedy Method
Define the Problem: Clearly understand the problem and what needs to be optimized.
Choose the Greedy Strategy: Determine the criteria for making the greedy choice (e.g., selecting the
largest, smallest, earliest, etc.).
Prove the Greedy Choice is Safe: Show that making a local optimal choice does not preclude the
possibility of finding the global optimum.
Construct a Solution: Build the solution iteratively by making a series of greedy choices.
Analyze: Evaluate the efficiency of the algorithm, usually in terms of time and space complexity.

3. Example: Coin Change Problem
Problem Statement: Given a set of coin denominations and an amount of money, determine the minimum
number of coins required to make up that amount.

Denominations Available: 1, 5, 10, 25 (U.S. coin denominations)

Amount to Change: 63 cents

Step-by-Step Solution:

Greedy Strategy: Always pick the largest denomination that does not exceed the remaining amount.
Procedure:
Start with 63 cents.
Choose the largest coin ≤ 63, which is 25. Subtract 25 from 63, leaving 38.
Choose the largest coin ≤ 38, which is 25. Subtract 25 from 38, leaving 13.
Choose the largest coin ≤ 13, which is 10. Subtract 10 from 13, leaving 3.
Choose the largest coin ≤ 3, which is 1. Subtract 1 from 3, leaving 2.
Repeat until the remaining amount is 0.
Solution:

Number of coins used: 3 (25 + 25 + 10 + 1 + 1 + 1)
Output: Minimum number of coins required is 6.
Algorithm:

function minCoins(coins, n, amount):
sort(coins in descending order)
count = 0
for i = 0 to n-1:
while amount >= coins[i]:
amount = amount - coins[i]
count = count + 1
return count
Explanation:

Step 1: Sort the coins in descending order.
Step 2: Start from the largest coin and keep subtracting it from the amount until the amount becomes
smaller than the coin value.

, Step 3: Move to the next largest coin and repeat until the amount is zero.
4. Limitations
The Greedy Method may not always give the optimal solution for every problem. For instance, if the coin
denominations were 1, 3, and 4, and the amount was 6, a greedy approach would pick coins (4, 1, 1),
which totals 3 coins. However, the optimal solution is (3, 3), which totals 2 coins.

5. Applications of the Greedy Method
Activity Selection Problem: Selecting the maximum number of activities that don't overlap.
Huffman Coding: Creating an optimal prefix code.
Kruskal’s and Prim’s Algorithms: Finding a minimum spanning tree in a graph.
Dijkstra’s Algorithm: Finding the shortest path in a graph.

--------------------------------------------------------------------------------------------------------------------------------------------
----------

Job Sequencing with Deadlines Using the Greedy Method

1. Introduction to Job Sequencing with Deadlines
Job sequencing with deadlines is a classic optimization problem where the objective is to maximize the
total profit earned by performing a set of jobs, each with a specific deadline and profit. The jobs need to
be completed within their deadlines, and each job takes exactly one unit of time. The goal is to find the
optimal sequence of jobs that maximizes the total profit.
2. Problem Statement
Input: A set of jobs, each with a deadline and a profit.
Output: A sequence of jobs that maximizes the total profit while ensuring that each job is completed within
its deadline.
3. Assumptions
Each job takes exactly one unit of time.
A job can only be completed if it is started before its deadline.
Only one job can be processed at a time.
4. Greedy Approach
The greedy strategy to solve the job sequencing problem involves the following steps:

Sort the Jobs: Arrange the jobs in decreasing order of profit.
Select Jobs: Iterate over the sorted jobs and schedule each job at the latest available slot before its
deadline. If no such slot is available, skip the job.
5. Example
Consider the following set of jobs:

Job Deadline Profit
J1 4 100
J2 1 19
J3 2 27
J4 1 25
J5 3 15

Step-by-Step Solution:

Sort Jobs by Profit:

Sorted Jobs: J1, J3, J4, J5, J2
Schedule Jobs:

Schedule J1 at slot 4 (its deadline).
Schedule J3 at slot 2 (its deadline).

Written for

Institution
Course

Document information

Uploaded on
December 16, 2024
Number of pages
9
Written in
2024/2025
Type
SUMMARY

Subjects

$6.19
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
priyankamuthabathula18

Also available in package deal

Get to know the seller

Seller avatar
priyankamuthabathula18 Srinivasa Institute of Engineering and Technology
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
6
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions