0% found this document useful (0 votes)
2 views

Lab assignment-2

The lab assignment requires the implementation of various algorithms using the Greedy approach, including activity selection, train platform scheduling, job scheduling for maximum profit, fractional knapsack problem, and Huffman coding for data compression. Specific input data and expected outputs are provided for each problem. Additionally, there are links to external questions for further practice.

Uploaded by

ygoyal2be23
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)
2 views

Lab assignment-2

The lab assignment requires the implementation of various algorithms using the Greedy approach, including activity selection, train platform scheduling, job scheduling for maximum profit, fractional knapsack problem, and Huffman coding for data compression. Specific input data and expected outputs are provided for each problem. Additionally, there are links to external questions for further practice.

Uploaded by

ygoyal2be23
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/ 1

UCS415 Design and Analysis of Algorithms

Lab Assignment 2

Write a program to solve the following problems using Greedy approach:


 Given the Input: start[] = {1, 3, 0, 5, 8, 5}, finish[] = {2, 4, 6, 7, 9, 9}; using Activity
selection. Select the maximum number of activities that can be performed by a single
person, assuming that a person can only work on a single activity at a time.
 We are given two arrays that represent the arrival and departure times of trains, the
task is to find the minimum number of platforms required so that no train waits.
Input: arr[] = {9:00, 9:40, 9:50, 11:00, 15:00, 18:00}, dep[] = {9:10, 12:00, 11:20,
11:30, 19:00, 20:00}
Output: 3
 Given an array of jobs where every job has a deadline and associated profit if the job
is finished before the deadline.
JobID Deadline Profit
a 4 20
b 1 10
c 1 40
d 1 30
Maximize the total profit if only one job can be scheduled at a time.

 Given the weights and profits of N items, in the form of {profit, weight},
Input: arr[] = {{60, 10}, {100, 20}, {120, 30}}, put these items in a knapsack of
capacity W= 50 to get the maximum total profit in the knapsack. Use Fractional
Knapsack, and break items for maximizing the total value of the knapsack.
 Huffman Coding is a lossless data compression algorithm. The algorithm assigns
variable-length codes to input characters, with shorter codes assigned to more frequent
characters. Write a program to implement Huffman Coding. Given a string as input,
your task is to:

1. Build a Huffman Tree for the characters in the string.


2. Generate the corresponding Huffman Codes for each character.
3. Encode the string using the generated Huffman Codes.
4. Decode the encoded string back to its original form.

Additional Questions:
 https://www.interviewbit.com/problems/majority-element/
 https://www.interviewbit.com/problems/distribute-candy/
 https://www.hackerearth.com/practice/algorithms/greedy/basics-of-
greedy- algorithms/tutorial/ [Solve the problem available at the end]
 https://www.codechef.com/problems/SUBSEG2
 https://www.codechef.com/problems/FGFS/
 https://www.hackerrank.com/challenges/board-cutting/problem

You might also like