版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、CHAPTER 10 ALGORITHM DESIGN TECHNIQUES,1 Greedy Algorithms, Optimization Problems: Given a set of constrains and an optimization function. Solutions that satisfy the constrains are called feasible solutions. A feasible solution for which the optimization function has the best possible value is calle
2、d an optimal solution., The Greedy Method: Make the best decision at each stage, under some greedy criterion. A decision made in one stage is not changed in a later stage, so each decision should assure feasibility.,1/12,1 Greedy Algorithms,2/12,Note: Greedy algorithm works only if the local optimum
3、 is equal to the global optimum. Greedy algorithm does not guarantee optimal solutions. However, it generally produces solutions that are very close in value (heuristics) to the optimal, and hence is intuitively appealing when finding the optimal solution takes too much time.,1 Greedy Algorithms,1.
4、Huffman Codes for file compression,Example Suppose our text is a string of length 1000 that comprises the characters a, u, x, and z. Then it will take ? bits to store the string as 1000 one-byte characters.,8000,Notice that we have only 4 distinct characters in that string. Hence we need only 2 bits
5、 to identify them.,We may encode the symbols as a = 00, u = 01, x = 10, z = 11. For example, aaaxuaxz is encoded as 0000001001001011. Then the space taken by the string with length 1000 will be 2000 bits + space for code table. /* log C bits are needed in a standard encoding where C is the size of t
6、he character set */, frequency := number of occurrences of a symbol.,In string aaaxuaxz , f(a) = 4, f(u) = 1, f(x) = 2, f(z) = 1.,The size of the coded string can be reduced using variable-length codes, for example, a = 0, u = 110, x = 10, z = 111.,3/12,Discussion 9: In what case that there are not
7、likely to be any savings even using Huffman codes?,1 Greedy Algorithms,Representation of the original code in a binary tree /* trie */, If character Ci is at depth di and occurs fi times, then the cost of the code = di fi .,Cost ( aaaxuaxz 0000001001001011 ) = 24 + 21 + 22 + 21 = 16,Representation o
8、f the optimal code in a binary tree,Cost ( aaaxuaxz 00010110010111 ) = 14 + 31 + 22 + 31 = 14,The answer is aaaxuaxz (with a = 0, u = 110, x = 10, z = 111). What makes this decoding method work?,The trick is: No code is a prefix of another.,Now, with a = 0, u = 110, x = 10, z = 111 and the string 00
9、010110010111, can you decode it?,4/12,Discussion 10: What must the tree look like if we are to decode unambiguously?,1 Greedy Algorithms, Huffmans Algorithm (1952),void Huffman ( PriorityQueue heap , int C ) consider the C characters as C single node binary trees, and initialize them into a min heap
10、; for ( i = 1; i C; i+ ) create a new node; /* be greedy here */ delete root from min heap and attach it to left_child of node; delete root from min heap and attach it to right_child of node; weight of node = sum of weights of its children; /* weight of a tree = sum of the frequencies of its leaves
11、*/ insert node into min heap; ,T = O( ? ),C log C,5/12,1 Greedy Algorithms,Cost = 310 + 215 + 212 + 53 + 44 + 213 + 51 = 146,6/12,Research Project 4 Huffman Codes (30),As a professor who gives the final exam problem on Huffman codes, I am encountering a big problem: the Huffman codes are NOT unique.
12、 The students are submitting all kinds of codes, and I need a computer program to help me determine which ones are correct and which ones are not. Detailed requirements can be downloaded from ,7/12,2. A Simple Scheduling Problem,Given N jobs j1 , j2 , , jN , their running times t1 , t2 , , tN , and
13、one processor.,Schedule jobs to minimize the average completion time. /* assume nonpreemptive scheduling */, The Single Processor Case,1 Greedy Algorithms,8/12,1 Greedy Algorithms,Example,Schedule 1,Tavg = ( 15 + 23 + 26 + 36 ) / 4 = 25,Schedule 2,Tavg = ( 3 + 11 + 21 + 36 ) / 4 = 17.75,In general:,
14、9/12,Best scheduling is to make tik nondecreasing.,1 Greedy Algorithms, The Multiprocessor Case N jobs on P processors,An Optimal Solution, Minimizing the Final Completion Time,NP Hard,10/12,1 Greedy Algorithms, Flow Shop Scheduling a simple case with 2 processors,Consider a machine shop that has 2
15、identical processors P1 and P2 . We have N jobs J1, . , JN that need to be processed. Each job Ji can be broken into 2 tasks ji1 and ji2 .,A schedule is an assignment of jobs to time intervals on machines such that, jij must be processed by Pj and the processing time is tij ., No machine processes m
16、ore than one job at any time., ji2 may not be started before ji1 is finished.,Construct a minimum-completion-time 2 machine schedule for a given set of N jobs.,Let ai = ti1 0, and bi = ti2 .,Example Given N = 4,T1234 = ?,40,11/12,Discussion 11: What if ai = 0?,1 Greedy Algorithms,【Proposition】 An optimal schedule exists if min bi , aj min bj , ai for any pair of adjacent jobs Ji and Jj . All the schedules with th
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- (2026年)公务员考试公共基础知识考前预测试卷
- 金融产品营销指标评估表
- 文化创意公司设计总监绩效考评表
- 风电场运维人员叶片检查标准流程
- 家电零售门店店长与导购员团队组长绩效指标表
- 关于年终奖金分配的讨论函5篇
- 2026年合肥丰乐种业股份有限公司人员招聘考试备考试题及答案
- 2026重庆祥龙天然气有限公司招聘6人笔试模拟试题及答案解析
- 2026清远市清城区横荷街道办事处公开招聘村(居)委会工作人员3人考试备考题库及答案解析
- IT技术支持与服务平台工程师绩效考评表
- 2026年广西北部湾国际港务集团有限公司人员招聘考试题库及详细答案解析
- 2026年济南市烟草专卖局人员招聘考试备考题库及答案详解
- 中国心肺复苏指南(2026年更新版)
- 屋面防水翻新工程质量评估报告
- 2026秋新人美版四年级美术上册教学课件:第二单元第1课 重重叠叠的枝叶 有多个微课视频
- 2026年河南豫地科技集团招聘试题及答案
- 2026年武汉大学辅导员招聘笔试试题(附答案)
- 2026-2027学年人教版九年级上学期数学第一次月考模拟考试培优卷(含答案)
- T-SDPEA 0046-2025 燃煤发电机组延寿改造项目可行性研究报告编制导则
- 成人鼻肠管留置与维护技术规范(2025版)(置管流程+并发症处理)
- 区域性职工代表大会资料1(常用版)
评论
0/150
提交评论