数据结构与算法2.pptVIP

  • 0
  • 0
  • 约7.33千字
  • 约 43页
  • 2019-11-14 发布于湖北
  • 举报
数据结构与算法 2004.2-5 Review 数据结构 算法 算法的五个重要特性 有穷性:一个算法必须总是在执行有穷步之后结束,且每一步都可在有穷时间内完成; 确定性:算法中每一条指令必须有确切的含义; 可行性:一个算法是能行的,即算法中描述的操作都可以通过已经实现的基本运算执行有限次来实现; 输入:一个算法有零个或多个输入,这些输入取自某个特定的对象集; 输出:一个算法有一个或多个输出,这些输出是同输入有着某些特定关系的量。 算法设计的要求 正确性(Correctness) 语法正确 对一般数据,执行结果正确 对苛刻数据,执行结果正确 对所有数据,执行结果正确 可读性(Readability) 健壮性(Robustness) 效率与低存储量要求 1.4 算法和算法分析 [Find remainder.] Divide m by n and let r be the remainder. (We will have 0 ? r n.) [Is it zero?] If r = 0, the algorithm terminates; n is the answer. [Interchange.] Set m ? n, n ? r, and go back to step 1. ? 算法效率的度量 空间复杂度 (Space Complexity) T(n)=O(f(n)) Keywords: inline, new, delete, private, protected, public Type expressions basic types -- int, char, float, ... array -- int ar[SIZE] function -- void f(int) pointer -- int* , char*, void (*f)(int) reference -- int, char* class, union, struct -- user-defined operators -- + , - ,.., , = ,.., == , != ,.., , || indexing -- o[ e ] application -- o(...) access -- o.m(...) dereference -- p-m(...) in/decrement -- o++, o-- conditional -- b?e:e2 Control conditional -- if (b) S1; else S2; selection -- switch(n) { case : n1: S1; break; ... default: ... } iteration -- while (b) S looping -- for( int i = 1; i = MAX; i + + ) S jumps -- return, break, continue, goto ADT in C style ADT in C++ Inheritance Techniques templates -- templateclassT class C { ... } overloading -- void read(int); voi read(float) friends -- to bypass protection type conversions -- by class constructors or type operators type coercion -- by explicit casts (is dangerous) smart pointers -- by overloading de-reference 1. 线性表 线性表的类型定义 线性表的顺序表示和实现 线性表的链式表示和实现 一元多项式的表示及相加 什 么 是 线 性 表 1.1 线性表的类型和定义 线性表操作例1: 合并(Union) 线性表操作例2:有序合并(Merge) 1.2 线性表的顺序表示和实现 线性表顺序存储的特点 优点 可随机存取; 表的长度 =最后一个结点的序号。 缺点 插入、删除结点时,平均需移动表内一半元素。若表长为n,则算法 ListInsert_Sq 和 ListDelete_Sq 的时间复杂度为 O(n)。 1.3 线性表的链式表示和实现 在pos处插入结点 在pos处删除结点 单 链 表 操 作 算 法 建立 CreateList_L 定位 GetElem_L 插入 ListInsert_L 删除 ListDelete_L 抽象数据和抽象数据类型 (ADTs:

文档评论(0)

1亿VIP精品文档

相关文档