当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

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

资源类别:文库,文档格式:PPT,文档页数:32,文件大小:417KB,团购合买
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
点击下载完整版文档(PPT)

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

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共32页,可试读12页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有