前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Tabulation v.s. Recursion With Memory (Dynamic Programming)

Tabulation v.s. Recursion With Memory (Dynamic Programming)

作者头像
杨丝儿
发布2022-03-01 13:09:41
1790
发布2022-03-01 13:09:41
举报
文章被收录于专栏:杨丝儿的小站杨丝儿的小站

Question

DP vs Recursion with memorization

I am wondering if that for any recursive function that can be translated into dynamic programming, is it always possible to also simply leave the function in its recursive form and apply a memorise wrapper to it as well? While we have clearly been shown there are many benefits to turning something into dynamic programming, I feel like some functions may be a lot easier to understand if they are in a recursive form and using a memorise function should help keep running costs low.

Such as the example in lecture 17 with seam carving, in my mind it would be considerably easier to understand what a function was doing if it worked backwards from the end point and recursively found the best path to that point, all why keeping running costs low due to a memorise wrapper.

My Answer

In my opinion, the bottom-up method and the top-down with memory (or recursive with memory) are quite similar methods (or they wouldn’t be classified as dynamic programming together).

  1. They both keep something in a list (maybe dimension higher than 1)
  2. They both cut off the calculated recursion tree. Make sure recursion runs under polynomial-time.

The difference between them is the way they fulfill the memory space and how they cut the recursion tree.

top-down with memory

bottom-up

generate data in memory in a passive way

generate data in memory in an active way

when recursion algorithms visit a node, we store information

when we visit nodes in whatever order we like and then store information

when visiting a stored node, we call its value from memory

after observing the pattern of whole memory, we go through all nodes without repeatation

we compute while storing information while cutting redundant trees

we fulfill memory, then we find a way to cut redundant trees, and finally, we compute

Hope this comparison table can help you with understanding.

(By the way, I think memory decorator is easier to understand and much more to implement too.)

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-01-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Question
  • My Answer
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档