西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第二部分 栈、队列、递归方法_递归 Chapter 5 RECURSION(英文)

Chapter 5 RECURSION I1. Introduction to Recursion 2. Principles of Recursion L3 Backtracking: Postponing the Work 4. Tree-Structured Programs Look-Ahead in games I5. Pointers and Pitfalls
Chapter 5 RECURSION 1. Introduction to Recursion 2. Principles of Recursion 3. Backtracking: Postponing the Work 4. Tree-Structured Programs: Look-Ahead in Games 5. Pointers and Pitfalls

5.1 Stacks and Trees Stack DIDID space AAALALAALA DIDIDIDID 团团的门 data Time 数据结构是递归的 Start +- Finish
5.1 Stacks and Trees 数据结构是递归的

THEOREM 5.1 During the traversal of any tree, vertices are added to or deleted from the path back to the root in the fashion of a stack. Given any stack, conversely, a tree can be drawn to portray the life history of the stack, as items are pushed onto or popped from it
THEOREM 5.1 During the traversal of any tree, vertices are added to or deleted from the path back to the root in the fashion of a stack. Given any stack, conversely, a tree can be drawn to portray the life history of the stack, as items are pushed onto or popped from it

Tree-Diagram Definitions o The circles in a tree diagram are called vertices or nodes o The top of the tree is called its root o the vertices immediately below a given vertex are callled the children of that vertex The(unique vertex immediately above a given vertex is called its parent. The root is the only vertex in the tree that has no parent 分支 ◆Th兄第 ting a vertex with one immed ately above or below is called a branch. 9 Siblings are vertices with the same parent
Tree-Diagram Definitions The circles in a tree diagram are called vertices or nodes. The top of the tree is called its root. The vertices immediately below a given vertex are called the children of that vertex. The (unique) vertex immediately above a given vertex is called its parent. (The root is the only vertex in the tree that has no parent.) The line connecting a vertex with one immediately above or below is called a branch. Siblings are vertices with the same parent. 分支 兄弟

9 A vertex with no children is called a leaf or an externa/ vertex Two branches of a tree are adjacent if the lower vertex of the first branch is the upper vertex of the second. a sequence of branches in which each is adjacent to its successor is called a path. o The height of a tree is the number of vertices on a longest possible path from the root to a leaf. (Hence a tree containing only one vertex has height 1.) The depth or level of a vertex is the number of branches on a path from the root to the vertex
A vertex with no children is called a leaf or an external vertex. Two branches of a tree are adjacent if the lower vertex of the first branch is the upper vertex of the second. A sequence of branches in which each is adjacent to its successor is called a path. The height of a tree is the number of vertices on a longest possible path from the root to a leaf. (Hence a tree containing only one vertex has height 1.) The depth or level of a vertex is the number of branches on a path from the root to the vertex

Factorials: A Recursive Definition Informal definition: The factorial function of a positive integer IS n!=nx(n-1)x.XI 定义是递归的 Formal definition 雪n=0时 n*(n-1)!,当n≥1时
Factorials: A Recursive Definition Informal definition: The factorial function of a positive integer is n! = n(n-1)…1 Formal definition: − = = 当 时 当 时 n (n 1)!, n 1 1, n 0 n! 定义是递归的

boundary Every recursive processconsists of two parts: A smallest, base case that is processed without recursion and recursion a general method that reduces a particular case to one or more ot the smaller cases thereby making progress toward eventually reducing the problem all the way to the base case
Every recursive process consists of two parts: A smallest, base case that is processed without recursion; and A general method that reduces a particular case to one or more of the smaller cases, thereby making progress toward eventually reducing the problem all the way to the base case. boundary recursion

Towers of hanoi 问题的解法是递归的 Rules: Move only one disk at a time. No larger disk can be on top of a smaller disk
Towers of Hanoi Rules: Move only one disk at a time. No larger disk can be on top of a smaller disk. 问题的解法是递归的

void move int count, int start, int finish, int temp); / Pre: There are at least count disks on the tower start.The top disk(if any) on each of towers temp and finish is larger than any of the top count disks on tower start. Post: The top count disks on start have been moved to finish tempused for temporary storage has been returned to its starting position. / const int disks 64. // Make this constant much smaller to run program. void move(int count, int start, int finish, int temp); Pre: None. Post: The simulation of the Towers of Hanoi has terminated. /
void move(int count, int start, int finish, int temp); /* Pre: There are at least count disks on the tower start. The top disk (if any) on each of towers temp and finish is larger than any of the top count disks on tower start. Post: The top count disks on start have been moved to finish; temp (used for temporary storage) has been returned to its starting position.*/ const int disks = 64; // Make this constant much smaller to run program. void move(int count, int start, int finish, int temp); /* Pre: None. Post: The simulation of the Towers of Hanoi has terminated. */

main( i move(disks, 1, 3, 2);3 void move(int count, int start int nish, int temp) i if (count>O i move count-1, start, temp, nish); cout < Move disk < count < from < start < to<< finish <<< endl move count-1, temp, nish, start; Please see pg. 166-167 figure 5. 4-5.5
main( ) { move(disks, 1, 3, 2); } void move(int count, int start, int nish, int temp) { if (count > 0) { move(count - 1, start, temp, nish); cout << "Move disk " << count << " from " << start << " to " << finish << "." << endl; move(count - 1, temp, nish, start); } } Please see pg. 166-167 figure 5.4 - 5.5
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第二部分 栈、队列、递归方法_链式栈与队列 Chapter 4 Linked Stacks and Queues(英文).ppt
- 西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第二部分 栈、队列、递归方法_队列 Chapter 3 QUEUES(英文).ppt
- 西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第二部分 栈、队列、递归方法_栈 Chapter 2 INTRODUCTION TO STACKS(英文).ppt
- 西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第一部分 绪论_大规模程序开发 Chapter 1 PROGRAMMING PRINCIPLES(英文).ppt
- 西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第一部分 绪论_数据结构导言(中文).ppt
- 西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第一部分 绪论_C++回顾(C++编程简介,中文).ppt
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)用Dijkstra方法求最短路径.doc
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)中缀表达式转后缀表达式.doc
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)查找最短路径.doc
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)四则运算计算器.doc
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)图书馆系统.doc
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)十进制数转化为其他进制的数.doc
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)查找性能比较.doc
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)列车车票查询.doc
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)平衡二叉树.doc
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)录像带商店.doc
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)前缀算术表达式转换成中缀算术表达式.doc
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)文本行编辑系统.doc
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)农夫过河问题.doc
- 西安建筑科技大学:《数据结构与算法》教学资源(课程设计题目任务书)哈夫曼编码.doc
- 西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第三部分 线性表_线性表 Chapter 6 LISTS AND STRINGS(英文).ppt
- 西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第四部分 查找、排列_查找 Chapter 7 SEARCHING(英文).ppt
- 西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第四部分 查找、排列_排列 Chapter 8 SORTING(英文).ppt
- 西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第四部分 查找、排列_检索 Chapter 9 Tables And Information Retrieval(英文).ppt
- 西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第五部分 树结构_二叉树 Chapter 10 BINARY TREES(英文).ppt
- 西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第五部分 树结构_多叉树 Chapter 11 MULTIWAY TREES(英文).ppt
- 西安建筑科技大学:《数据结构基础(选修)》课程PPT电子教案_第一部分 绪论(中文).ppt
- 西安建筑科技大学:《数据结构基础(选修)》课程PPT电子教案_第二部分 线性表(中文).ppt
- 西安建筑科技大学:《数据结构基础(选修)》课程PPT电子教案_第三部分 栈、队列、递归方法(中文).ppt
- 西安建筑科技大学:《数据结构基础(选修)》课程PPT电子教案_第四部分 树与二叉树(中文).ppt
- 西安建筑科技大学:《数据结构基础(选修)》课程PPT电子教案_第五部分 图(中文).ppt
- 西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第六部分 图结构_图 Chapter 12 GRAPHS(英文).ppt
- 西安建筑科技大学:《数据结构基础(选修)》课程PPT电子教案_第六部分 排序(中文).ppt
- 西安建筑科技大学:《数据结构基础(选修)》课程PPT电子教案_第七部分 查找(中文).ppt
- 西安建筑科技大学:《数据结构基础》课程课堂笔记_第一部分 绪论_大规模程序开发 PROGRAMMING PRINCIPLES(英文).doc
- 西安建筑科技大学:《数据结构基础》课程课堂笔记_第二部分 栈、队列、递归方法_栈 INTRODUCTION TO STACKS(英文).doc
- 西安建筑科技大学:《数据结构基础》课程课堂笔记_第二部分 栈、队列、递归方法_队列 Queues(英文).doc
- 西安建筑科技大学:《数据结构基础》课程课堂笔记_第二部分 栈、队列、递归方法_递归 RECURSION(英文).doc
- 西安建筑科技大学:《数据结构基础》课程课堂笔记_第二部分 栈、队列、递归方法_链式栈与队列 LINKED STACKS AND QUEUES(英文).doc
- 西安建筑科技大学:《数据结构基础》课程课堂笔记_第三部分 线性表_线性表 LISTS(英文).doc