Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Greedy Algorithms: Techniques for Optimization and Activity Scheduling, Huffman Codes, Study notes of Algorithms and Programming

The concept of greedy algorithms, a technique for solving optimization problems, and provides examples of its application in activity selection and huffman codes. Greedy algorithms involve making locally optimal choices to reach a globally optimal solution. The activity selection problem, where the goal is to schedule a set of activities with no conflicts, and the huffman codes problem, where the goal is to create an optimal prefix code for a sequence of characters. The document also includes pseudocode for the greedy activity selector and huffman algorithms.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-mjh
koofers-user-mjh 🇺🇸

10 documents

1 / 4

Toggle sidebar

Related documents


Partial preview of the text

Download Greedy Algorithms: Techniques for Optimization and Activity Scheduling, Huffman Codes and more Study notes Algorithms and Programming in PDF only on Docsity! 1 Greedy Algorithms Greedy algorithms is a technique for solving some optimization problems. A greedy algorithm solution to a problem usu- ally involves: 1. Repeatedly identify a decision to be made. 2. Make a locally optimal choice for each deci- sion. To reach a globally optimal solution, the prob- lem must have an appropriate recursive struc- ture, i.e., an optimal solution equals a locally optimal choice plus an optimal solution for the remainder of the problem. 2 Activity Selection A set of activities are to be scheduled in a room. An activity a has start time start[a] and a finish time finish[a]. Maximize the number of sched- uled activities. Locally optimal choice: Among activities with no conflicts with previously scheduled activities, choose the activity with the earliest finish time. Recursive structure: This choice maximizes the amount of time afterwards, so no other choice can allow more activities to be scheduled. A is an array of activities. S is a schedule. Greedy-Activity-Selector(A) sort A by finish[A] n ← length[A] S ← {A[1]} j ← 1 for i ← 2 to n do if start[A[i]] ≥ finish[A[j]] then S ← S ∪ {A[i]} j ← i return S
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved