0% found this document useful (0 votes)
8 views4 pages

Seminar

The document discusses two optimization problems: the Activity Selection Problem and Huffman Coding. The Activity Selection Problem aims to select the maximum number of non-overlapping activities based on their start and finish times using a greedy algorithm. Huffman Coding is a method for efficient data encoding that constructs a binary tree based on character frequencies to minimize data size for compression.

Uploaded by

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

Seminar

The document discusses two optimization problems: the Activity Selection Problem and Huffman Coding. The Activity Selection Problem aims to select the maximum number of non-overlapping activities based on their start and finish times using a greedy algorithm. Huffman Coding is a method for efficient data encoding that constructs a binary tree based on character frequencies to minimize data size for compression.

Uploaded by

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

Activity Selection Problem

 Mathematical Optimization Problem


 Select the maximum number of activities without overlapping from the given set of activities
 Each activity has a start time and a finish time
 The goal is to schedule as many activities as possible without overlapping

Note :

Si  Start Time

Fi  Finishing Time

Activity  (Si, Fi)

Greedy Algorithm for Activity Selection Problem

 Activities are sorted according to their finishing time


 The activities are greedily selected by going down the list and picking whatever activity is
compactable with the current selection

Steps

 Sort the activity by arranging the finishing time (Fi) in ascending order
 Arrange the sorted list in a way that it does not overlap with the previous activity

Algorithm

1. n  length [s] //Determine the number of activities.


2. A  {1} //Initialize the selection set A with the first activity
3. i1 //Set i to track the last added activity.
4. for j  2 to n //Loop through all activities starting from the second one.
5. do if Sj >= Fi //check if the start time of activity j is greater than or equal to the
Finishing Time of i.
6. then A  a U {j} //Add activity j to set A
7. i  j //Update j to this newly added activity
8. return A //After checking all activities,
return the set A containing the selected activities.

Example

Consider the following set of activities with their start and finish times:

 Activity 1: (1, 4)

 Activity 2: (3, 5)

 Activity 3: (0, 6)

 Activity 4: (5, 7)

 Activity 5: (8, 9)

 Activity 6: (5, 9)
Step 1: Sort Activities by Finish Time

 Sorted Activities: (1, 4), (3, 5), (0, 6), (5, 7), (8, 9), (5, 9)

Step 2: Select the First Activity

 Selected Activity: (1, 4)

Step 3: Iterate and Select Non-overlapping Activities

 Next Activity: (3, 5) (overlaps with (1, 4), so skip)

 Next Activity: (0, 6) (overlaps with (1, 4), so skip)

 Next Activity: (5, 7) (does not overlap, select it)

 Next Activity: (8, 9) (does not overlap, select it)

 Next Activity: (5, 9) (overlaps with (5, 7), so skip)

Final Selected Activities: (1, 4), (5, 7), (8, 9)

HUFFMAN CODE

 Used for efficient encoding of data


 Widely used and beneficial technique for compressing data

Steps to construct Huffman Code

1. Frequency Table
2. Priority Queue
3. Tree Construction
4. Code Assignment

Example

Suppose we have the following characters and their frequencies:

Character Frequency

A 5

B 9

C 12

D 13

E 16

F 45
Character Frequency

Step-by-Step Construction:

1. Initial Priority Queue:

o (A, 5), (B, 9), (C, 12), (D, 13), (E, 16), (F, 45)

2. First Iteration:

o Remove (A, 5) and (B, 9)

o Create new node (AB, 14)

o Queue: (C, 12), (D, 13), (E, 16), (F, 45), (AB, 14)

3. Second Iteration:

o Remove (C, 12) and (D, 13)

o Create new node (CD, 25)

o Queue: (E, 16), (F, 45), (AB, 14), (CD, 25)

4. Third Iteration:

o Remove (E, 16) and (AB, 14)

o Create new node (EAB, 30)

o Queue: (F, 45), (CD, 25), (EAB, 30)

5. Fourth Iteration:

o Remove (CD, 25) and (EAB, 30)

o Create new node (CDEAB, 55)

o Queue: (F, 45), (CDEAB, 55)

6. Final Iteration:

o Remove (F, 45) and (CDEAB, 55)

o Create new node (FCDEAB, 100)

o Queue: (FCDEAB, 100)

Huffman Tree:

Code Assignment:

 A: 1100

 B: 1101

 C: 100

 D: 101
 E: 111

 F: 0

Advantages of Huffman Coding

 Optimality: Produces the most efficient prefix code for a given set of character frequencies.

 Compression: Significantly reduces the amount of data needed to represent the original
information.

Applications

 File Compression: Used in formats like ZIP and GZIP.

 Multimedia Compression: Applied in JPEG and MP3 formats.

 Data Transmission: Efficiently encodes data for transmission over networks.

Huffman coding is a fundamental algorithm in data compression, providing a simple yet powerful
method to reduce the size of data without losing information.

You might also like