the design and analysis of algorithms ---- 1.introduction

1. 什么是算法

An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time.

算法是一系列用于解决问题的明确指令,即在有限时间内为任何合法输入获得所需的输出。

 

2.fundamntals of algorithmic problem solving(算法问题求解的基本方法)

Although some algorithms are indeed better than others, there is no algorithm that would be the best solution in all situations.

# understanding the problem

理清问题。考虑到所有可能的input

# ascertaining the capabilities of the computational device

包括sequential algorithm(顺序)和parallel algorithm(并行)

#  choosing the exact and approximate problem solving

确定使用精确的算法,还是模糊大约的计算算法

# algorithm design techniques

learning such techniques is akin to learning to fish as opposed to being given a fish caught by somebody else

积累传统的算法是基础

# designing an algorithm and data structures

# methods of specifying an algorithm

Pseudocode(伪代码) is a mixture of a natural language and programming language like constructs

For the sake of simplicity, we omit declarations of variables and use indentation(缩进) to show the scope of such statements as for, if, and while. As you saw in the previous section, we use an arrow “←” for the assignment operation and two slashes “//” for comments.

# proving an algorithm correctness

# analyzing an algorithm

1.efficiency-- time efficiency( indicating how fast the algorithm runs) +  space efficiency( indicating how much extra memory it uses)

2.Another desirable characteristic of an algorithm is simplicity.

Why?Because simpler algorithms are easier to understand and easier to program; consequently, the resulting programs usually contain fewer bugs.

3.Yet another desirable characteristic of an algorithm is generality.

# coding an algorithm

 an algorithm’s optimality(最优性)

Actually, this question is not about the efficiency of an algorithm but about the complexity of the problem it solves: What is the minimum amount of effort(最小的工作量) any algorithm will need to exert to solve the problem

 

3.important problem types

3.1 sort(排序)

  we usually need to sort lists of numbers, characters from an alphabet(字母表), character strings

关于常见排序算法详解

3.2 searching

   & The searching problem deals with finding a given value, called a search key, in a given set

   & For searching, too, there is no single algorithm that fits all situations best. Some algorithms work faster than others but require more memory; some are very fast but applicable only to sorted arrays; and so on

  & Searching has to be considered in conjunction with two other operations: an addition to and deletion from the data set of an item(对项目数据集的添加和删除)

3. String processing

   & A string is a sequence of characters from an alphabet

   & String matching --- searching for a given word in a text

4. Graph problem

 & A graph(图) can be thought of as a collection of points called vertices(顶点),some of which are connected by line segments called edges(边)

& Basic graph algorithms

   --> graph-traversal algorithms(BFS+DFS)(如何遍历完network中的所有节点)

    -->shortest-path algorithms(最短路径算法--两个地点的最短路径)

   --> topological sorting for graphs with directed edges (有向边图的拓扑排序)

&  the most well-known examples are the traveling salesman problem and the graph-coloring problem

      --> The traveling salesman problem (TSP) is the problem of finding the shortest tour through n cities that visits every city exactly once.In addition to obvious appli cations involving route planning

      --> The graph-coloring problem seeks to assign the smallest number of colors to the vertices of a graph so that no two adjacent vertices are the same color. This problem arises in several applications, such as event scheduling

5. combinatorial problem(组合问题)

    & combinatorial problems. --- the traveling salesman problem(旅行者问题) and the graph-coloring problem(颜色填充)

    & These are problems that ask, explicitly(明确) or implicitly, to find a combinatorial object—such as a permutation(排列), a combination(组合), or a subset(分组)—that satisfies certain constraints.(满足某些限制)

   & A desired combinatorial object may also be required to have some additional property(附加的属性) such as a maximum value or a minimum cost.

6. geometric problem(几何问题)

    & The closest-pair problem is self-explanatory: given n points in the plane, find the closest pair among them

    & The convex-hull problem asks to find the smallest convex polygon that would include all the points of a given set

7. numerical problem

     & Numerical problems are problems that involve mathematical objects of continuous nature: solving equations and
system sofequations(解方程),computing definite integrals(定积分),evaluating functions(评估函数),and so on.

----------------------------------------------------------------------------------------------------------------------------------------------------

4.Fundamental data structures(基本的数据结构)

4.1 Linear data structures(线性数据结构)

1) A list is a finite sequence of data items (列表是数据项的有限序列。)

 

2) array(数组): a sequence of n items of the same data type that are stored contiguously in computer memory and made accessible by specifying a value of the array’s index(连续存储并且通过特定的index进行搜索)

 

3) linked(链表):A linked list is a sequence of zero or more elements called nodes, each containing two kinds of information: some data and one or more links called pointers to other nodes of the linked list. (A special pointer called “null” is used to indicate the absence of a node’s successor.)

      -->Singly linked list(单链表):each node except the last one contains a single pointer to the next element(两个元素之间只有一个指针)

       -->Doubly linked list(双向链表):in which every node, except the first and the last, contains pointers to both its successor(后继节点) and its predecessor(前节点  )(对于每个节点,都有一个指针连接后继节点 和前节点 

     On the positive side, linked lists donot require any preliminary(预留的) reservation of the computer memory, and insertions and deletions can be made quite efficiently in a linked list by reconnecting a few appropriate pointers.(使用指针可以高效的删除或者添加节点)

 

4) Two special types of lists, stacks(堆栈) and queues(队列)

4.1)A stack is a list in which insertions and deletions can be done only at the end.

         (堆栈是一个列表,其中只能在末尾进行插入和删除。)

      -->when elements are added to (pushed onto) a stack and deleted from (popped off) it, the structure operates in a “last-in–first-out” (LIFO--后进先出) fashion— exactly like a stack of plates if we can add or remove a plate only from the top.(添加和移除元素都是在top处进行)

    -->Stacks have a multitude of applications; in particular, they are indispensable for implementing recursive algorithms.(递归算法)

4.2)A queue, on the other hand, is a list from which elements are deleted from one end of the structure, called the front (this operation is called dequeue入队), and new elements are added to the other end, called the rear (this operation is called enqueue出队). (从front移除元素,在rear部分添加元素)

    --> Consequently, a queue operates in a “first-in–first-out” (FIFO先进先出) fashion—akin to a queue of customers served by a single teller in a bank.

    -->  Queues  also have many important applications, including several algorithms for graph problems.

    --> Priority queue(优先队列):  require selection of an item of the highest priority among a dynamically changing set of candidates  (要求在动态变化的候选集中选择优先级最高的项)

 

4.2 graphs

1)graphG = <V, E>,V--vertices(顶点);E-- edges(边)

     顶点(u,v)和(v,u)相同,都表示顶点u和v彼此相连,并且由无向边连接

     顶点(u,v)和(v,u)不相同时,连接的边有有向边,(u,v)表示从顶点u指向顶点v

     Undirected graphs无向图:边为无向边的图

     Directed graphs(有向图):没有边都是有向的

    a)

    b)

             

 

持续更新中!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值