You are on page 1of 1

Linked list:why another list data type:Python’s list class is highly optimized, and often a great called doubly

ly linked listThese “dummy” nodes are known as sentinels (or guards), and they if it has no fundamental data structureA queue is a collection of objects that are inserted and removed

choice for storag many programming languages do not support this kind of optimized list data do not store elements of the primary sequence.可以在中间直接插删 child , according to the first-in, first-out (FIFO) principle Elements can be inserted at any time, but

type|List in Python is a referential structure(Python 的列表实际上是一个包含指向其他对象 otherwise an only the element that has been in the queue the longest can be next removed The primary

的引用的数组。这意味着列表本身并不直接存储元素的实际值,而是存储了指向实际值 internal analysis of algorithms involves

所在内存地址的引用),但在 compact array in languages such as C/C++ and Java|singly linked node。A tree is orderedusually visualized by arranging siblings from left to right,binary characterizing the running times and

listis a collection of nodes that collectively form a linear sequence(node stores a reference to tree:1. Every node has at most two childre2. Each child node is labeled as being either space usage of algorithms and data

an object that is an element of the sequence, as well as a reference to the next node of the a left child or a right chil3. A left child precedes a right child in the order of children of structure operations Principle of algorithm analysis 1: Counting primitive operations To

list)|Because the next reference of a node can be viewed as a link or pointer to another node, a node,proper\full if each node has either zero or two children\Each node contains analyse the running time of an algorithm without performing experiments We define a set of

the process of traversing a list is also known as three references, one pointing to the parent node, two pointing to the child nodes primitive operations such as the following: Assigning an identifier to an object Determining

Bubble sort 遍历数列中的每个数字,比较 Depth-first search (DFS) is a fundamental algorithm for traversing or searching tree data the object associated with an identifier Performing an arithmetic operation (for example,
link hopping or pointer

元素 i 和其后面的元素 i+1,如果 i 大于 structures One starts at the root and explores as deep as possible along each branch before adding two numbers) Comparing two numbers Accessing a single element of a Python list by

hopping。|stack:栈,queue, i+1,就交换它们的位置。再次遍历数列,重复步骤 1,但是忽略数列结尾的最后一个元 index Calling a function Principle of algorithm analysis 2: Measuring Operations as a Function

素。不断遍历数列,但是每次忽略数列末尾的一个元素,直到只剩下一个元素为止。
(每 of Input Size a function f (n) that characterizes the number of primitive operations that are

次把最大的放在队尾)Quick performed as a function of the input size n We may use the following 7 functions to measure

the time complexity 从快到慢:2^n> n^3 > n^2 > nlogn > n > logn To differentiate efficient

and inefficient algorithms, the general line is between polynomial time algorithms and

backtrackingEX:maze. Breadth-first exponential time algorithms The distinction between polynomial-time and exponential-time
队列(前面差不多)init

search (BFS) is another very important algorithms is considered a robust measure of tractability Principle of algorithm analysis 3:
sort:从数组中选择一个元素
的时候不输入参数,首

algorithm for traversing or searching Focusing on the Worst-Case Input In algorithm analysis, we focus on the growth rate of the
作为枢轴(pivot)。partition
尾都是 none,size=0.

tree data structure.Starts at the root and we visit all the positions at depth d before we visit running time as a function of the input size n, taking a “big-picture” approach,Sharp enough
分区:重新排列数组,使得所
其中队列是一种先进先出(First In First Out,FIFO)的数据结构(就像排队),而栈则是

the positions at depth d +1(EX: finding the best move in a game) If a recursive function is to make meaningful comparisons between algorithms Let f(n) and g(n) be functions mapping
有小于枢轴值的元素位于枢
一种后进先出(Last In First Out,LIFO)的数据结构 Circularly Linked ListThe tail of a linked list

designed so that each invocation of positive integers to positive real numbers. We say that f(n) is O(g(n)) if there is a real constant
轴之前,所有大于枢轴值的元素位于枢轴之后(相等的元素可以位于任意一边)
。在这个
can use its next reference to point back to the head of the list。EX:A round-robin scheduler

the body makes at most one new c > 0 and an integer constant n0 ≥ 1 such that f(n) ≤ cg(n), for n ≥ n0 This definition is often
分区操作之后,枢轴就处于最终的位置上。这个步骤被称为分区操作(partition operation)

iterates through a collection of elements in a circular fashion and “serves” each element by

recursive call, this is known as referred to as the “big-Oh” notation 大 O 符号表示算法的上界,即当输入规模趋近无穷时,


对小于枢轴值的元素组成的子数组和大于枢轴值的元素组成的子数组分别递归地应用上
performing a given action on it.A round-robin scheduler could be implemented with the

linear recursion,When a function makes two or more recursive calls, we say that it uses 算法的时间复杂度 不会超过大 O 表示的复杂度 When the sequence is unsorted, the
述步骤。A tree is a data structure that stores
standard queue:e = Q.dequeue(),Service element ,Q.enqueue(e) head =
multiple recursionA stack is a collection standard approach to search for a target value is to use a loop to examine every element,
elements hierarchically , a

ofobjects that are inserted and removed until either finding the target or exhausting the data set; This is known as the sequential
parent element and zero or

according to the last-in, first-out (LIFO) HTML search algorithm When the sequence is sorted and indexable, binary search is a much more
more children elements ,

efficient algorithm For any index j, we know that all the values stored at indices 0, . . . , j−1 are
typically call the top

less than or equal to the value at index j, and all the values stored at indices j+1, . . . ,n−1 are
element the root of the treeIf T is nonempty, it has a special node, called the root of T, that

greater than or equal to that at index j : The binary search algorithm runs in O(logn) Recursion
self.__tail.pointer(circular),head 是 tail 后一个入队(Enqueue)
:将一个元素添加到队列的 has no parent.Each node v of T different from the root has a unique parent node w; every is the standard format for hyperlinked

a function makes one or more calls to itself during execution def: First, a recursive definition
末尾。出队(Dequeue)
:从队列的头部移除一个元素,并返回它。For a singly linked list, we node with parent w is a child of w. 树 T 的边(edge)是一个节点对(u,v),其中 u 是 v 的父 documents on the InternetIn an HTML

contains one or more base cases, which are defined non-recursively in terms of fixed
cannot efficiently delete a node at the tail of the list(可以首尾加,只能首删)We can define 节点,边表示树中两个节点之间的连接关系。树 T 的路径(path)是一个节点序列,其 document, portions of text are delimited

quantities Second, it also contains one or more recursive cases, which are defined by
a linked list in which each node keeps an explicit reference(显式引用指的是在数据结构中明 中任意两个连续的节点在序列中形成一条边。路径表示从一个节点到另一个节点的路由。 by HTML tags. A simple opening HTML tag has the form “<name>” and the corresponding

appealing to the definition of the function being defined In Python, each time a function
确地存储指向其他节点的引用) to the node before it and a reference to the node after it, is 节点 v 的深度 depth 是连接根节点和 v 的路径的长度。它表示节点距离树的根节点的级 closing tag has the form

(recursive or otherwise) is called, a structure known as an activation record or frame is


根节点本身的深度为 0,每个下一级的深度增加 1|A node is called a leaf node
别或距离。 “</name>” Queue is another

You might also like