上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 01 Greedy and Dynamic Programming

上海充通大学 SHANGHAI JLAO TONG UNIVERSITY Computer Algorithm Design and Analysis Lecture 1 Week 13:Greedy and Dynamic Programming Yongxin ZHU,Weiguang SHENG 强 LAMMAMARAU SHANC 1日g
Computer Algorithm Design and Analysis Lecture 1 Week 13: Greedy and Dynamic Programming Yongxin ZHU, Weiguang SHENG

上海充通大学 Greedy Algorithm vs Dynamic SHANGHAI JLAO TONG UNIVERSITY Programming? General idea: Dynamic Programming means Dynamic Planning Greedy algorithm is a special case of dynamic programming Greedy algorithm approaches (approximately sometimes)the global optimum with local optimum Dynamic Programming can handle the optimization issues without local optimum 3/12/2022
3/12/2022 Greedy Algorithm vs Dynamic Programming? General idea: • Dynamic Programming means Dynamic Planning • Greedy algorithm is a special case of dynamic programming • Greedy algorithm approaches (approximately sometimes) the global optimum with local optimum • Dynamic Programming can handle the optimization issues without local optimum

上海充通大学 SHANGHAI JLAO TONG UNIVERSITY Greedy Coin Changing WE NT IE T H C E N T U RY。X SE L E C T I O N S 里迈ESE☒TH Greed is good.Greed is right.Greed works. Greed clarifies,cuts through,and captures the essence of the evolutionary spirit. Gordon Gecko (Michael Douglas) Cashier would say:"Making change with dollars, nickels,and pennies. SH 1日g
Greedy Coin Changing Greed is good. Greed is right. Greed works. Greed clarifies, cuts through, and captures the essence of the evolutionary spirit. - Gordon Gecko (Michael Douglas) Cashier would say: "Making change with dollars, nickels, and pennies

上海充通大学 Coin Changing SHANGHAI JLAO TONG UNIVERSITY Goal.Given currency denominations:1,5,10,25,100,devise a method to pay amount to customer using fewest number of coins. ©EX:34. Cashier's algorithm.At each iteration,add coin of the largest value that does not take us past the amount to be paid. Ex: $2.89
4 Coin Changing Goal. Given currency denominations: 1, 5, 10, 25, 100, devise a method to pay amount to customer using fewest number of coins. Ex: 34¢. Cashier's algorithm. At each iteration, add coin of the largest value that does not take us past the amount to be paid. Ex: $2.89

上海充通大学 SHANGHAI JLAO TONG UNIVERSITY Greedy Algorithm Example1: Minimum Spanning Tree 强 MARARAAA月 奏 SHANG 1日
Greedy Algorithm Example1: Minimum Spanning Tree

上充通大Minimum Spanning Tree(MST) SHANGHAI JLAO TONG UNIVERSITY Spanning tree of a connected graph G:a connected acyclic subgraph of G that includes all of G's vertices Minimum spanning tree of a weighted,connected graph G:a spanning tree of G of the minimum total weight Example: 6 6 C a a a 4 2 2 d 6 d 3 3
Minimum Spanning Tree (MST) Spanning tree of a connected graph G: a connected acyclic subgraph of G that includes all of G’s vertices Minimum spanning tree of a weighted, connected graph G: a spanning tree of G of the minimum total weight Example: c d b a 6 2 4 3 1 c d b a 2 3 1 c d b a 6 4 1

上游充通大粤 Prim's MST algorithm SHANGHAI JLAO TONG UNIVERSITY Start with tree T1 consisting of one (any)vertex and "grow"tree one vertex at a time to produce MST through a series of expanding subtrees T1,T2,...,T On each iteration,construct Ti1 from T;by adding vertex not in T;that is closest to those already in Ti(this is a 'greedy”step!) Stop when all vertices are included
Prim’s MST algorithm Start with tree T1 consisting of one (any) vertex and “grow” tree one vertex at a time to produce MST through a series of expanding subtrees T1 , T2 , …, Tn On each iteration, construct Ti+1 from Ti by adding vertex not in Ti that is closest to those already in Ti (this is a “greedy” step!) Stop when all vertices are included

上游究通大学 Example SHANGHAI JLAO TONG UNIVERSITY 4 4 4 C a 6 6 2 2 2 d d 3 3 b 3 4 4 C a a 1 2 2 3 3
Example c d b a 4 2 6 1 3 c d b a 4 2 6 1 3 c d b a 4 2 6 1 3 c d b a 4 2 6 1 3 c d b a 4 2 6 1 3

上海克通大Notes about Prim's algorithm SHANGHAI JLAO TONG UNIVERSITY Proof by induction that this construction actually yields an MST(CLRS,Ch.23.1).Main property is given in the next page. Needs priority queue for locating closest fringe vertex.The Detailed algorithm can be found in Levitin,P.310. Efficiency O(n2)for weight matrix representation of graph and array implementation of priority queue O(m log n)for adjacency lists representation of graph with n vertices and m edges and min-heap implementation of the priority queue
Notes about Prim’s algorithm Proof by induction that this construction actually yields an MST (CLRS, Ch. 23.1). Main property is given in the next page. Needs priority queue for locating closest fringe vertex. The Detailed algorithm can be found in Levitin, P. 310. Efficiency • O(n 2 ) for weight matrix representation of graph and array implementation of priority queue • O(m log n) for adjacency lists representation of graph with n vertices and m edges and min-heap implementation of the priority queue

The Crucial Property behind Prim's Algorithm SHANGHAI JLAO TONG UNIVERSITY Claim:Let G=(V,E)be a weighted graph and (X,y)be a partition of V (called a cut).Suppose e (x,y)is an edge of E across the cut, where x is in X and y is in Y,and e has the minimum weight among all such crossing edges(called a light edge).Then there is an MST containing e. Y X
The Crucial Property behind Prim’s Algorithm Claim: Let G = (V,E) be a weighted graph and (X,Y) be a partition of V (called a cut). Suppose e = (x,y) is an edge of E across the cut, where x is in X and y is in Y, and e has the minimum weight among all such crossing edges (called a light edge). Then there is an MST containing e. y x X Y
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 01 算法设计与分析基础.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 09 C程序组织.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 08 指针.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 07 函数.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 06 C语言数组.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 05 C语言语句.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 03 C语言数据类型.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 02 C语言简介.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 15 输入输出.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 14 内存检测、剖面分析.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 13 高级指针.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 12 结构、联合与枚举.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 11 字符串.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 10 C程序调试.pdf
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 01 课程简介及编程基础(绳伟光).pdf
- 机械工业出版社:计算机科学丛书《计算机组成与设计:硬件、软件接口》电子教材(中文第4版).pdf
- 《计算机系统结构》课程教学资源(电子书籍)《Computer Systems》A Programmer's Perspective(Randal E. Bryant、David R. O'Hallaron,THIRD EDITION).pdf
- 《计算机系统结构》课程教学资源(电子书籍)《Computer Organization and Design》THE HARDWARE / SOFTWARE INTERFACE(DAVID A. PATTERSON JOHN L. HENNESSY,Fourth Edtion,彩色版).pdf
- 《中文信息学报》:中文组织机构名称与简称的识别.pdf
- 上海交通大学:《C++程序设计与实践》课程教学资源(讲义)方波生成器项目报告书.doc
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 02 Divide and Conquer.pptx
- 上海交通大学:《C程序与算法设计》课程教学资源(课件讲稿)Lecture 04 C语言运算符与表达式.pdf
- 《C程序与算法设计》课程教学资源(学习资料)快乐的Linux命令行.pdf
- 上海交通大学:《ROS机器人操作系统基础与实战》课程教学资源(实验指导书)01 ROS系统安装.doc
- 上海交通大学:《ROS机器人操作系统基础与实战》课程教学资源(实验指导书)02 ROS基本元素实验(一).doc
- 上海交通大学:《ROS机器人操作系统基础与实战》课程教学资源(实验指导书)03 ROS基本元素实验(二).doc
- 上海交通大学:《ROS机器人操作系统基础与实战》课程教学资源(实验指导书)04 调试和可视化.doc
- 上海交通大学:《ROS机器人操作系统基础与实战》课程教学资源(实验指导书)05 外部设备的使用.doc
- 上海交通大学:《ROS机器人操作系统基础与实战》课程教学资源(实验指导书)06 机器视觉.doc
- 上海交通大学:《ROS机器人操作系统基础与实战》课程教学资源(实验指导书)07 机器人建模与仿真.doc
- 上海交通大学:《ROS机器人操作系统基础与实战》课程教学资源(实验指导书)08 机器人导航包.doc
- 上海交通大学:《ROS机器人操作系统基础与实战》课程教学资源(实验指导书)09 机械臂规划Moveit.doc
- 《并行与分布式程序设计》课程教学参考书:CUDA C PROGRAMMING(CUDA编程指南4.0中文版).pdf
- 《并行与分布式程序设计》课程教学参考书:NVIDIA《CUDA C PROGRAMMING GUIDE》(Design Guide,CHANGES FROM VERSION 9.0).pdf
- 《并行与分布式程序设计》课程教学参考书:NVIDIA《CUDA C Programming》(Professional).pdf
- 《并行与分布式程序设计》课程教学参考书:CUDA《Programming Massively Parallel Processors》A Hands-on Approach(美,David B. Kirk and Wen-mei W. Hwu,英文版).pdf
- 《并行与分布式程序设计》课程教学参考书:CUDA《Programming Massively Parellel Processors》大规模并行处理器编程实战(美)David B.Kirk&Wen-mei W.Hwu(中文版).pdf
- 《并行与分布式程序设计》课程教学参考书:分布式与云计算(美)Tom White《Hadoop权威指南》(中文第3版).pdf
- 《并行与分布式程序设计》课程教学参考书:分布式与云计算《Spark大数据处理技术、应用与性能优化》(PDF扫描版).pdf
- 《并行与分布式程序设计》课程教学参考书:并行与并发编程《An Introduction to Parallel Programming》.pdf