1.07k likes | 1.27k Views
Chapter 8. Algorithms. 天津大学软件学院. 8.1 CONCEPT. INFORMAL DEFINITION Algorithm (算法) : a step-by-step method for solving a problem or doing a task. (逐步解决问题或完成任务的方法)
E N D
Chapter 8 Algorithms 天津大学软件学院
8.1 CONCEPT INFORMAL DEFINITION Algorithm(算法): a step-by-step method for solving a problem or doing a task.(逐步解决问题或完成任务的方法) In this definition, an algorithm is independent of the computer system(独立于计算机系统). More specifically, we should also note that the algorithm accepts a list of input data and creates a list of output data.(输入一组数据,产生一组输出数据)
Input The algorithm accepts the list of five integer as input. Processing The algorithm uses five steps to find the largest integer. Output Because there are no more integers to be processed, the algorithm outputs the value of Largest, which is 13.
8.2 THREE CONSTRUCTS 顺序 判断 循环
8.3 ALGORITHM REPRESENTATION FLOWCHART(流程图) A flowchart is a pictorial representation of an algorithm. It shows how the algorithm flows from beginning to end.
PSEUDOCODE(伪代码) Pseudocode is an Englishlike representation of an algorithm. It is part English and part structured code.(类似英语的表示方法)
Example 1 Solution Write an algorithm in pseudocode that finds the average of two numbers. Algorithm 8.1: Average of two • AverageOfTwo • Input:Two numbers • Add the two numbers • Divide the result by 2 • Return the result by step 2 • End
8.4 MORE FORMAL DEFINITION Algorithm: an ordered set of unambiguous steps that produces a result and terminates in a finite time(一组明确步骤的有序集合,它产生结果并在有限时间内终止). ORDERED SET(有序集合)An algorithm must be a well-defined, ordered set of instruction. UNAMBIGUOUS STEPS(明确步骤)Each algorithm must be clearly and unambiguously defined. PRODUCE A RESULT(产生结果)An algorithm must produce a result; otherwise, it is useless. The result can be data that are returned to the calling algorithm or same other effect (e.g., printing). TERMINATE IN A FINITE TIME(在有限时间内终止)An algorithm must terminate (halt). If it does not (e.g., has an infinite loop), you have not created an algorithm.
8.5 SUBALGORITHMS(子算法) The principles of structured programming, require that an algorithm be broken into small units called subalgorithms (the terms subprograms, subroutines, procedures, function, methods, and modules are also used). Each subalgorithm is in turn divided into smaller subalgorithms. The process continues until the subalgorithms become intrinsic (understood immediately).
Algorithm 8.6: Find largest • FindLargest • Input:A list of positive integers • Set Largest to 0 • while (more integers) 2.1 FindLargerEnd while • Return Largest • End • FindLarger • Input:Largest and current integer • if (the integer is greater than Largest)then 1.1 Set Largest to the value of the integerEnd ifEnd
8.6 BASIC ALGORITHMS Summation Product
Bubble sort Selection sort 选择排序 Insertion sort 插入排序
Correctness and Efficiency two that should linger in your mind as you develop algorithms on your own: • Correctness(正确性) • Efficiency(效率)
Graph of the worst-case analysis of the insertion sort algorithm
Graph of the worst-case analysis of the binary search algorithm
Chapter 11 Data Structures 天津大学软件学院
A data structure uses a collection of related variables that can be accessed individually or as a whole. In other words, a data structure represents a set of data items with a specific relationship between then. 数据结构使用相关变量的集合,这些变量能够单独或作为整体被访问。 数据结构代表了有特殊关系的数据的集合。
ARRAYS(数组) Imagine you have a problem that requires 20 numbers to be processed. You need to read them, process them, and print them. You must also keep these 20 numbers in memory for the duration of the program.
RECORDS(记录) A record is a collection of related elements, possibly of different types, having a single name. Each element in a record is called a field(域). A field is the smallest element of values, which in turn can be accessed for selection or manipulation. A field differs from a variable primarily in that it is part of a record. 记录是一组相关元素的集合,它们的类型可能不同,整个记录有一个名字 域是具有含义的命名数据的最小元素 域不同于变量,它是记录的一部分; 数组中所有元素都是同一类型的;记录中的元素是相同或不同的类型
广义表 限制列表 无序表 有序表 队列 堆栈 Linear list(线性列表)具有顺序结构,每个元素都有唯一的后继元素 Categories of linear lists 广义表对处理列表的操作没有任何限制,数据可在任意地方进行插入和删除操作
Insertion in a linear list Deletion from a linear list
Retrieval from a linear list(检索) Traversal of a linear list(遍历)
LINKED LISTS(链表) A linked list is an ordered collection of data in which each element contains the location of the next element; that is, each element contains two parts: data and link. 链表是一个有序数据的集合,每个元素包含下个元素的地址 带有头指针的Plist链表 空链表
Queue representation(队列) 删除(出列) 插入(入列)
Enqueue operation Dequeue operation
Push operation in a stack Pop operation in a stack
Chapter 14 Databases 天津大学软件学院
A database is a collection of data that is logically, but not necessarily physically, coherent. 数据库是数据在逻辑上的集合 14.1 DATABASE MANAGEMENT SYSTEM A database management system (DBMS) defines, creates, and maintains a database. The DBMS also allows users controlled access to data in the database数据库管理系统是定义、创建、维护数据库的一种工具,也允许用户控制数据库中数据的存取. A DBMS is a combination of five components: hardware, software, data, users, and procedures.
涉及到的课程 • 数据结构 • 算法分析 • 数据库原理 • 数据库应用技术 • 数据仓库与数据挖掘
作业 • 8-16——8-23 • 11-2, 11-17,11-18, 11-20,11-22——11-30 • 12-19——12-23 • 14-18——14-22
Chapter 10 SoftwareEngineering 天津大学软件学院
SOFTWARE LIFE CYCLE (软件生命周期) 开发系统 过时吗? 使用该系统 修正该系统
ANALYSIS PHASE(分析阶段) The development process starts with the analysis phase, which shows what the package should do显示程序应该做什么. In this phase, the systems analyst defines requirements that specify what the proposed system is to accomplish系统分析员定义需求,指出系统所要实现的目标. The requirements are usually stated in terms that the user understands.
ANALYSIS PHASE(分析阶段) Define the User(定义用户)A software package may be designed for a generic user or a specific user. The user of the package must be clearly defined. Define the Needs(定义要求)In this step, the best answer comes from the user. The user, or the representative of the user, clearly defines his/her expectations of the package. Define the Requirements(定义需求)Based on the needs of the user, the analyst can exactly define the requirements for the system. Define the Methods(定义方法)Finally, after the requirements are defined in clear terms, the analyst can choose the appropriate methods to meet those requirements.
DESIGN PHASE(设计阶段) The design phase defines how the system will accomplish what was defined in the analysis phase.定义系统如何完成在分析阶段所定义的需求In the design phase, the systems are determined, and the design of the files and/or the databases is completed. 完成文件和数据库的设计 Modularity(模块化)The whole package is divided into small modules. Each module is designed and tested and is linked to other modules through a main program. ToolsThe design phase uses several tools, the most common being a structure chart(结构图). A structure chart shows how to break your package into logical steps; each step is a separate module. The structure chart also shows the interaction between all the parts (modules).
IMPLEMENTATION PHASE(实现阶段) In this phase, you create the actual programs. ToolsThis phase uses several tools to show the logical flow of the programs before the actual writing of code. 在编码之前使用工具来显示程序的逻辑流程One tool, still popular, is the flowchart. A flowchart uses standard graphical symbols to represent the logical flow of data through a module. The second tool used by programmers is pseudocode. Pseudocode is part English and part program logic that describes, in precise algorithmic detail, what the program is to do. Coding The choice of the language is based on the efficiency of the language for that particular application.编程语言的选择是基于针对特殊应用程序的效率