美文网首页
算法练习(51): 栈的可生成性问题中禁止出现的排列(1.3.4

算法练习(51): 栈的可生成性问题中禁止出现的排列(1.3.4

作者: kyson老师 | 来源:发表于2017-11-18 00:21 被阅读126次

本系列博客习题来自《算法(第四版)》,算是本人的读书笔记,如果有人在读这本书的,欢迎大家多多交流。为了方便讨论,本人新建了一个微信群(算法交流),想要加入的,请添加我的微信号:zhujinhui207407 谢谢。另外,本人的个人博客 http://www.kyson.cn 也在不停的更新中,欢迎一起讨论

算法(第4版)

知识点

  • 栈的可生成性问题中禁止出现的排列

题目

1.3.46 栈的可生成性问题中禁止出现的排列。若三元组 (a, b, c) 中 a<b<c 且 c 最先被弹出,a 第二,b 第三(c 和 a 以及 a 和 b 之间可以间隔其他整数),那么当且仅当排列中不含这样的三元组时(如上题所述的)栈才可能生成它。


1.3.46 Forbidden triple for stack generability. Prove that a permutation can be gener- ated by a stack (as in the previous question) if and only if it has no forbidden triple (a, b, c) such that a < b < c with c first, a second, and b third (possibly with other intervening integers between c and a and between a and b).
Partial solution: Suppose that there is a forbidden triple (a, b, c). Item c is popped before a and b, but a and b are pushed before c. Thus, when c is pushed, both a and b are on the stack. Therefore, a cannot be popped before b.

广告

我的首款个人开发的APP壁纸宝贝上线了,欢迎大家下载。

相关文章

网友评论

      本文标题:算法练习(51): 栈的可生成性问题中禁止出现的排列(1.3.4

      本文链接:https://www.haomeiwen.com/subject/xjwsvxtx.html