《数据结构与算法分析》课程教学资源(PPT讲稿)Lists, Stacks and Queues

Lists. Stacks and Queues
Lists, Stacks and Queues

More com plete listADT List(i / const List(const List& list)i copy constructor List( destructor ist& operator=(const List& list)i // assignment operator // plus other overloaded operators void add (double x)i double head(consti // get the head element bool search(double x search for a given x void insert(double x) / insert x in a sorted list void delete(double x / delete x in a sorted list void addEnd (double x)i add to the end d deleteD(; delete the end and get the end element double end( / get the element at the end void display ()consti //output it length()consti / count the number of elements
2 struct Node{ double data; Node* next; }; class List { public: List(); // constructor List(const List& list); // copy constructor ~List(); // destructor List& operator=(const List& list); // assignment operator // plus other overloaded operators bool empty() const; // boolean function void add(double x); // add to the head void delete(); // delete the head and get the head element double head() const; // get the head element bool search(double x); // search for a given x void insert(double x); // insert x in a sorted list void delete(double x); // delete x in a sorted list void addEnd(double x); // add to the end void deleteEnd(); // delete the end and get the end element double end(); // get the element at the end void display() const; // output int length() const; // count the number of elements private: Node* head; }; More complete list ADT

list ADT (a general list) class list ublic t() List(const List& list) copy constructor LIston // destructor bool empty() consti double head( const // get the head element void add(double x)i // add to the head void delete(i // delete the head element void display() consti // output private: Or to define one function Double delete 0; Which deletes and returns the head element
3 class List { public: List(); // constructor List(const List& list); // copy constructor ~List(); // destructor bool empty() const; // boolean function double head() const; // get the head element void add(double x); // add to the head void delete(); // delete the head element void display() const; // output private: … }; list ADT (a general list) Or to define one function: Double delete(); Which deletes and returns the head element

list ADT (a sorted list lass list public Liston // constructor List(const List& list)i // copy constructor sto // destructor bool empty ()consti // boolean function double headon consti // get the first element void insert(double x) // insert x in a sorted list void delete (double x sorted list void display()col //output bool search(double x) // search for a given x
4 class List { public: List(); // constructor List(const List& list); // copy constructor ~List(); // destructor bool empty() const; // boolean function double head(); const; // get the first element void insert(double x); // insert x in a sorted list void delete(double x); // delete x in a sorted list void display() const; // output bool search(double x); // search for a given x private: … }; list ADT (a sorted list)

Implementation and efficiency Implementation Static array DynamIc array Linked lists e with and without dummy head tricks Efficiency Insertion> construction, composition Deletion> destruction, decomposition Search application, usage
5 Implementation Static array Dynamic array Linked lists with and without ‘dummy head’ tricks Efficiency Insertion → construction, composition Deletion → destruction, decomposition Search → application, usage Implementation and Efficiency

Efficiency: Algorithm Analysis Roughly 'counting the number of operations, assuming all basis operations are of the same unit one
6 Roughly ‘counting’ the number of operations, assuming all basis operations are of the same, unit one. Efficiency: Algorithm Analysis

A Few Simple rules Loops at most the running time of the statements inside the for-loop (including tests ) times the number of iterations O(N) Nested loops for(i=0; i<n; i ++ for (=0; j<n;j ++) k++; the running time of the statement multiplied by the product of the sizes of all the for-loops O(N2)
7 A Few Simple Rules Loops at most the running time of the statements inside the for-loop (including tests) times the number of iterations. O(N) Nested loops the running time of the statement multiplied by the product of the sizes of all the for-loops. O(N2 )

Consecutive statements for(=0;i<n;+) These just add a[i=0; O(N)+O(N2)=O(N2) for (i=0:; k<n:; ++ for (=0; j<n j ++ a+=a]++ Conditional: If s1 else s2 never more than the running time of the test plus the larger of the running times of S1 and S2 O(1)
8 Consecutive statements These just add O(N) + O(N2 ) = O(N2 ) Conditional: If S1 else S2 never more than the running time of the test plus the larger of the running times of S1 and S2. O(1)

Our first example: search of an ordered array Linear search and binary search Upper bound, lower bound and tight bound
9 Our first example: search of an ordered array Linear search and binary search Upper bound, lower bound and tight bound

10 Linear search: // Given an array of 'size, in increasing order, find int linearsearch(int* a[l, int size int x)i int low=0, high=size-li for (int i=0; i<size; i++) O(N) if (a[i]==x return i t
10 O(N) // Given an array of ‘size’ in increasing order, find ‘x’ int linearsearch(int* a[], int size,int x) { int low=0, high=size-1; for (int i=0; i<size;i++) if (a[i]==x) return i; return -1; } Linear search:
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《计算机网络与通信》课程教学资源(PPT课件)Chapter 8 传输层.ppt
- 《计算机网络 Computer Networking》课程教学资源(PPT课件讲稿)Chapter 08 Network Security.ppt
- 《计算导论与程序设计》课程教学资源(PPT课件讲稿)Chap 5 函数.ppt
- 贵州大学:计算机应用基础(PPT课件讲稿)计算机基础知识.pdf
- 《计算机组装与维护》课程教学资源(PPT课件讲稿)第十一章 计算机数据恢复技术.ppt
- 《C语言程序设计》课程教学资源(PPT讲稿)第1章 程序设计和C语言.pptx
- 北京师范大学:《计算机文化基础》课程教学资源(PPT课件讲稿)08 网页制作基础知识(赵国庆).ppt
- 水平集方法与图像分割 Level set method and image segmentation.pptx
- 《计算机网络》课程教学资源(PPT讲稿)网络安全(访问控制、加密、防火墙).ppt
- 同济大学:《大数据分析与数据挖掘 Big Data Analysis and Mining》课程教学资源(PPT课件讲稿)Platforms for Big Data Mining(主讲:饶卫雄).ppt
- 《数据结构》课程教学资源(PPT课件讲稿)第八章 图.ppt
- 《单片机应用技术》课程PPT教学课件(C语言版)第3章 MCS-51指令系统及汇编程序设计.ppt
- 《编译原理与技术》课程教学资源(PPT课件讲稿)代码优化.ppt
- Progress of Concurrent Objects with Partial Methods.pptx
- 《网络搜索和挖掘关键技术 Web Search and Mining》课程教学资源(PPT讲稿)Lecture 12 Language Models.ppt
- 四川大学:《操作系统 Operating System》课程教学资源(PPT课件讲稿)Chapter 6 Concurrency - Deadlock(死锁)and Starvation(饥饿).ppt
- 《操作系统》课程教学资源(PPT课件讲稿)实时调度 Real-Time Scheduling.ppt
- 白城师范学院:《数据库系统概论 An Introduction to Database System》课程教学资源(PPT课件讲稿)第二章 关系数据库(2.1-2.3).ppt
- 《计算机算法设计与分析》课程教学资源(PPT课件)第8章回溯法.ppt
- 清华大学出版社:《计算机应用基础实例教程》课程教学资源(PPT课件讲稿,第二版,共七章,主编:吴霞,制作:李晓新).ppt
- 沈阳理工大学:《Visual Basic 6.0程序设计》课程教学资源(PPT课件讲稿)第三章 VB基本语言.ppt
- 南京大学:《计算机网络 Computer Networks》课程教学资源(PPT课件讲稿)简介、第一章 引论(谭晓阳).ppt
- 中国科学技术大学:《Linux操作系统分析》课程教学资源(PPT课件讲稿)第一章 绪论(主讲:陈香兰).ppt
- 西华大学:《电子商务概论》课程教学资源(PPT课件讲稿)第4章 电子商务的安全问题.ppt
- 北京大学:未来互联网体系结构(PPT讲稿)Future Internet Architecture(Introduction).pptx
- 《计算机组成原理》课程教学资源(PPT课件讲稿)第5章 输入输出系统.ppt
- 清华大学出版社:《物流电子商务》课程教学资源(PPT课件讲稿,共八章,主编:董铁,制作:李晓新).ppt
- 电子工业出版社:《计算机网络》课程教学资源(第五版,PPT课件讲稿)第三章 数据链路层.ppt
- 电子工业出版社:《计算机网络》课程教学资源(第五版,PPT课件讲稿)第四章 网络层.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)契约式设计 Design by Contract.ppt
- 《计算机网络安全》课程教学资源(PPT课件讲稿)第三章 网络防病毒.ppt
- 同济大学:《软件测试》课程教学资源(PPT课件讲稿)第5章 单元测试(朱少民).ppt
- 香港科技大学:Information-Agnostic Flow Scheduling for Commodity Data Centers.pptx
- 南京航空航天大学:《数据结构》课程教学资源(PPT课件讲稿)第九章 查找.ppt
- 《数字图像处理 Digital Image Processing》课程教学资源(PPT课件讲稿)第10章数字图像处理的应用.ppt
- 北京大学信息学院:《高级软件工程》课程教学资源(PPT课件讲稿)第五讲 新运行平台——云计算平台.pptx
- 视觉系统(PPT课件讲稿)The Visual System.ppt
- 谈模式识别方法在林业管理问题中的应用(PPT讲稿).pptx
- 山东大学:《微机原理及单片机接口技术》课程教学资源(PPT课件讲稿)第十章 人机交互接口(主讲:刘忠国).ppt
- 深圳大学:《编译原理》课程教学资源(PPT课件讲稿,共四章,尹剑飞).ppt