- [Greatest common divisor] The greatest common divisor of two non-negative integers m and n that are not all 0 is recorded as gcd (m, n) gcd(m,n)gcd(m,n ) represents the largest positive integer that can divide m and n.
- 【 E u c l i d ′ s Euclid's Euclid′s a l g o r i t h m algorithm a l g o r i t h m ]Reuse the following equationgcd (m, n) = gcd (n, gcd(m,n)=gcd(n,gcd(m,n)=gcd(n, m m m m o d mod m o d n) n)n)
- 【algorithm】
- [Sieve of Eratosthenes] Generate a sequence of continuous prime numbers not greater than a given integer n, Eratosthenes sieve method, the idea is to sieve out multiples of 2, multiples of 3...until there are no elements that can be eliminated. Considering the largest integer p whose multiple has not been eliminated, the first number that should be considered should be p 2 p^2p2 (Satisfy the conditionp 2 ≤ np^2≤np2≤n , equivalent to p not greater thann 1/2 n^{1/2}n1 / 2 rounded down value), since the smaller multiple p 2p, 3p until p (p-1) in front of the screening process to screen has gone.
- 【algorithm】
- If a sorting algorithm retains the relative order of equivalent elements in the input, it is said that the algorithm is stable (Stable). An input sequence contains two equal elements, and the corresponding positions are i, ji, ji,j , andi <j i<ji<j , after the entire sequence is sorted, the positions of the above two elements arei ′, j ′ i',j'i′,j′ , At this time alsoi ′ <j ′ i'<j'i′<j' Generally speaking, would far apart the key exchange algorithm although unstable, but the speed is often very quickly, such as Shell sort.
- If an algorithm does not require additional storage space (individual storage units can allow), we say that it is in- place (In-Place).
- [Traveling salesman problem (TSP)] is to find the shortest path to visit n cities, and to ensure that each city is only visited once. Its main applications include path planning, circuit board and VLSI manufacturing, X Ray crystallography and genetic engineering, etc.
- [Graph Coloring Problem] is to use the least kinds of colors to color the vertices in the graph, and to ensure that any adjacent two vertices have different colors. This problem stems from many practical applications, such as scheduling transaction progress: If you use Vertices represent transactions, and transactions are connected by edges. If and only when independent transactions cannot be scheduled to occur simultaneously, the solution to the graph coloring problem can generate an optimal schedule.
- [Array Array] is a sequence composed of n elements of the same data type, which are continuously stored in the computer's memory. No matter where it is in the array, the elements can be accessed with the same constant time. Arrays can be used to implement strings. A string is a sequence of letters, and a special character is used to mark the end of the string.
- [Linked List Linked List] is a sequence composed of zero or more nodes, each node contains two types of information, one is data, and the other is one or more links called pointers, pointing to other elements in the linked list (we Use a special pointer called null to indicate that a node does not point to another node). Unlike an array, the time required to access an element in a singly linked list depends on the position of the element, but insertion and deletion are very efficient. You only need to change the linked pointer, and there is no need to allocate storage space in advance.
- [Header] The linked list often starts from a special node called the header, which contains information about the linked list, such as the current length of the linked list and a pointer to the end element.
- [List] Both arrays and linked lists belong to linear lists (Linear List is referred to as List List for short), and are the most important manifestations.
- [Stack Stack] A stack is a list that can only be performed at the end of insert (push) and delete (pull) operations. This end is called the top of the stack. The stack is essential for implementing recursive algorithms and has a very important depth. The priority search DFS is also implemented using the stack.
- [Queue Queue] The delete (dequeue) operation of the queue is performed at one end, which is called the front of the queue; and the insertion (entry) operation is performed on the other end, which is called the rear of the queue, and the important breadth-first search BFS It is implemented using queues.
- Both stacks and queues are special types of lists.
- [Priority Queue] is a collection of data items from the total order domain. The most common total order domain is integer or real. A delicate implementation structure of priority queue is called Heap. Of course, it can also be implemented directly based on arrays. .
- [Adjacency matrix] The adjacency matrix of an undirected graph is an n × nn × nn×Boolean matrix A of n , if there is an edge(i, j) (i, j)(i,j ) , NajoA [i, j] = 1 A [i, j] = 1A[i,j]=1 , and for undirected graphs, A is a symmetric matrix. If the side has the right to weightWWW,那么 A [ i , j ] = W A[i,j]=W A[i,j]=W , where there is no edge, use∞ ∞∞ means.
- [Adjacent Linked List] Each vertex is represented by a linked list, which contains all the vertices connected to the vertex.
- The time efficiency of using DFS and BFS for graphs stored in an adjacency matrix is O (∣ V ∣ 2) O(|V|^2)O ( ∣ V ∣2 ); In contrast, the time efficiency of the form of adjacency linked list isO (∣ V ∣ + ∣ E ∣) O(|V|+|E|)O ( ∣ V ∣+∣E∣).
- For graphs, Connectivity and Acylicity are important. Both are based on the concept of path Path: The path from u to v is the sequence of adjacent vertices in graph G starting from u and ending with v. If there is no vertex, it is Repeatedly, the path is a simple path.
- If a graph does not have connectivity, then it will have at least two connected components, as follows:
- Free Tree Free Tree is a connected non-loop graph, the number of edges is always one less than the number of vertices, ∣ E ∣ = ∣ V ∣ + 1 |E|=|V|+1∣E∣=∣V∣+1.
- A binary tree with height h and n vertices, satisfying log 2 n ≤ h ≤ n − 1 log_2^n≤h≤n-1log2n≤h≤n−1 , wherelog 2 n log_2^nlog2nNeed to be rounded down.
[Algorithm] Notes for Chapter 1
Guess you like
Origin blog.csdn.net/weixin_44246009/article/details/108188995
Recommended
Ranking