Home > other >  "Data structure and algorithm" knowledge summary
"Data structure and algorithm" knowledge summary

Time:09-20

Data structure is logical structure in the study, which include linear structure, tree structure, graph structure,
Linear structure: the structure of the one-to-one linear relationship exists between the data elements,
Tree structure: the structure of the level of the one-to-many relationship exists between the data elements,
Graph structure: the structure of the data elements exist between arbitrary many-to-many relationship,
Algorithm is to a specific problem solving an overview of the steps, it is the directive finite sequence, which each instruction said one or more actions,
Algorithm characteristics: there is poor, certainty, feasibility, input, output,
Algorithm design requirements to be met: correctness, readability, robustness, low efficiency and storage capacity needs,
Above is the data structure and algorithm of a simple introduction, here is around to learn some knowledge of the data structure and algorithm,

Linear table 1:
Linear table about the sequence table and singly linked lists, respectively, also speak their insertion and deletion,
Order table insertion feature is what position do you want to insert, it will move from the last element in the future, until an empty the position to insert, delete, delete the location of the element removed, then the back of the each element will move forward, a singly linked list insert is positioned in the characteristics of insert position before an insert, delete it is simple, direct delete the location element,

2 the stack and queue:
The characteristics of the stack is very obvious, lifo,
Stack basic operations: initialization stack, determine whether the stack S is empty, find the length of the stack S, get the value of the stack elements, the element e into and out of the stack,
Stack storage structure: order stack, stack chain
Queue is referred to as "team, of which the insert is called team again, delete a team, a queue of storage structure is also order queue and chain queue,
When inserted into the queue if the queue is full will query overflow, solve this problem is to use circular queue,
Circular queue for full condition is: front==(rear + 1) % MaxSize

3 string:
String is composed of zero or more characters finite sequence, as s="s0s1... "Sn - 1 n 0 or higher), which s is string name, character number n is called the length of the string, double apostrophe enclosed sequences of characters" s0s1... Sn - 1 "is the list of values, each character can be letters, Numbers, or any other symbols, zero the string of characters (i.e.," ") as an empty string, an empty string does not contain any character, it is worth noting:
(1) the length of 1 blank string "" is not the same as an empty string" ";
(2) the value of a single character string is not the same as a single character, such as "a" and 'a';
(3) string value does not contain double apostrophe, double apostrophe is the string delimiter,

4 array and matrix:
Arrays is orderly sequence of elements in the Java language has many features: distributed storage space, get the length of the array, array element, array element, array includes a one-dimensional array, a two-dimensional array, three dimensional array, four dimensional array, etc.,
How to understand the array? A dimension of each element in the array is a one-dimensional array, the two dimensional array is the two elements in a three dimensional array, you can compare two dimensional array to is a sheet of paper, the three dimensional array is a book and so on, four dimensional array is to put a book shelf, five dimensional array is the library,
Matrix in mathematics is a according to the rectangular array of plural or the set of real Numbers, matrix in life generally applied to image processing, information encryption, and so on, there will be some special matrices, zero matrix, the square matrix, diagonal matrix, the unit matrix, up/down triangle matrix and row/column matrix,

5 the tree:
Everyone know see tree is very level, the roots, branches, leaves, and it is as if a company's general manager, department managers, employees, tree structure is a kind of nonlinear structure, they are widely used in the objective world widely exist, so how to represent a tree in the computer, the definition is that the tree is made up of n (n 0 or higher) a finite set of nodes, if n=0, that is called the empty tree, if n> 0, the content:
There is a specific node called the root (root), it only immediate successor, but there is no direct precursor;
Except the thought of other nodes are divided into m (m> 0) a finite set of mutually disjoint T1, T2, T3... Tm, each set is a tree, and is called the root of the subtree, (every one and only one KeZi root of the tree nodes directly precursors, but it can have zero or more immediate successor)
There are some basic terms: tree node, the node degrees, degrees of trees, leaves, branches, children, parents, brothers, ordered and unordered trees and forests, the depth of the tree, these basic terms can let us study tree is more convenient and quick understanding and memory,
There is a special kind of tree, in line with the second child policy tree - binary tree; Binary tree is n (n 0 or higher) a finite set of nodes BT, it is an empty set, or, or by a root node and two respectively called right sub tree and left subtree of mutually disjoint of binary tree,
Binary tree traversal also there are several ways: first, the root traversal (TLR), traversal (LTR) in the root, root after traversal (LRT);
Chain store structure of binary tree, is the most commonly used binary chain table and the trifurcate linked list, as well as the creation of a binary tree, as shown in the figure below:

There is a known as the optimal binary tree: Huffman tree
The basic concept of Huffman tree with the path length and tree path length
Nodes in the weighted path length: from the root node to the path length of a node and the node with the weight of the product,
Tree of weighted path length is so the sum of weighted path length of the leaf nodes, usually as shown in the figure below:


Construct the Huffman tree method as shown in the figure below:


Figure 6:
In practice, there is a lot to use graph structure to describe problems, such as travel route can be used on the picture, but we study this diagram can help us with the least amount of money and time to plan a good travel plan,
? Diagram is composed of the vertices and edges, fixed-point representation of the data elements, and says the relationship between the data elements for G=(V, E), in which V is a set of vertices is not empty have poor, E is a finite set of vertices of the said, can be null,
Figure in the basic terms: adjacent points, vertex degree, into and out of the degrees, complete graph, dense, thin figure, son figure, the path and connected graph, connected component, strongly connected graph, strongly connected component, power, network,
Photo storage structure: adjacency matrix and adjacency table,
? Graph traversal: starting from a vertex traversal graph the remaining vertices, and make each vertex is accessed only once,
Algorithm design need to be aware of a few questions: 1, the parameters of the algorithm is the first vertex to specify access; 2, want to consider traversal path possible infinite loop problem; All 3, want to make every vertex of the adjacent vertices in a certain order is accessed,
The basic method of traversing the graph: depth-first search and breadth-first search,
See below connected graph depth first search traversal DFS and a sample, as shown in the figure below:


The method to solve the problem of figure of the shortest path: the Dijkstra algorithm and Floyd algorithm,
Dijkstra algorithm: according to the order of increasing of the path length gradually produce the shortest path algorithm, first calculate the shortest length of a shortest path, and then follow it to find the short length of time a shortest path and so on, until the vertex V to each other of the shortest path and so far, the following look at a sample, as shown in the figure below:



7 find:
Divided into static search, dynamic lookup and hash lookup, let's one by one to see,
? Static lookup and include: sequential search, binary search, partition to retrieve,
Sequential search: lookup table storage structure is linear table; Lookup process is in turn use to find the condition of the given value and find the key data elements in the table value comparison,
Let's have a look at the complete algorithm of sequential search, as shown in the figure below:

Binary search: binary search is only applicable to lookup for orderly sequence table; Each a binary search, or to find success, end find; Or to find half range, continue to find; Repeat until find success or search range is empty or lookup failure, binary search, also known as binary search,
Chunked retrieval: block search is also called the indexed sequential search, it is a kind of performance between sequential search and binary search search method, linear table lookup table by 'block orderly and "orderly" index table,

? Dynamic lookup: is dynamically generated in the lookup table structure itself, for a given value of K, if there is in the table lookup is successful, otherwise the insert K in proper place, its main structure binary tree structure and tree structure of two types,
Binary sort tree, also known as binary search trees, tree or it is empty, or is to satisfy the following properties: 1, if it left subtree is not empty, the left child tree nodes are less than the root of all values; 2, if its right subtree is not empty, the right sub tree nodes are less than the root of all values; 3, left and right subtrees itself and each is a binary sort tree,
In the binary sort tree to find the basic idea: with a given K value compared with the root node keyword value, if K is less than the value of the root node, will continue to look for in the left subtree, otherwise will continue to look for in the right subtree and so on, has been to find, until find success or search failure,
See below a complete binary sort tree search algorithm, as shown in the figure below:



Hash lookup, a simple introduction, as shown in the figure below:

Hash lookup in the method, as shown in the figure below:


8 sorts:
Sorting is divided into several kinds: insertion sort, exchange and selection,
? Insertion sort: at the beginning of the order in the table contains only one element, unordered list contains n - 1 element; Every time in the process of sorting table to retrieve the first element from the chaos, in an orderly table to insert it into the appropriate position, making it the new order list; Every trip is in front of a record is inserted into the orderly segment, until all the records are inserted into the orderly segment, the need for n - 1,
Note: the order of elements of the mobile is directly inserted into the algorithm, the method is stable,
Direct insertion sort is suitable for sorting fewer elements, and the basic order of sorting data element,
Direct insertion sort algorithm description as shown in the figure below:

? Exchange sorting: also known as quick sort, the basic idea is to collating sequence from n record in take a R, as the benchmark records, benchmark records as boundaries, will be ordered to be divided into two sub sequences, so the key words less than the record moved to the front of the Ri of Ki, on the other hand, moved to behind, this process is called a quick sort, and then use the same method of two sequence sorting, get four sequence; So on, until there is only one
each subsequenceRecord, at the moment you get n record orderly sequence,
Quick sort algorithm description and quick sort of recursive algorithm as shown in the figure below:
nullnullnullnullnullnullnullnullnullnull
  • Related