Data Structure Basics

Source: Internet
Author: User
When solving a problem with a program, it is often necessary to abstract the specific problem into a mathematical model, and then solve it with the concrete algorithm, the process of the abstract mathematical model to analyze the problem of the throne. The program description mathematical model is no longer a mathematical equation, but a data structure.
First, the basic related concepts of data structure what is data structure. A data structure is a collection of basic elements, and one or more specific relationships that exist between them.
According to different data relations, can adopt different data structure, the characteristic classification of data relation:--set: except belong to some same set, have no other specific relation;--linear: There is a one-to-many relationship between data;--Tree: There is a pair of relationships between data;
Data type classification:--Basic data type: Atomic type, structure type, atomic type is non-decomposed data type;--abstract data type: Data object, data relation, basic operation--multi-shape data type: Refers to the existence of the same relationship, but the element is not determined by the type of the component; Abstract data types are divided into:-- Atomic type;--Fixed aggregation type: Determining the composition of the number and value of variables;--Variable aggregation type: The number of variables or the uncertainty of the merits; Data relations: Relationships between data elements there are two different representations of the computer: sequential and non-sequential images, This results in two different storage structures: sequential storage and chained storage.
Second, the algorithm efficiency measurement (running time/storage space complexity of large O means) T (n) =o (f (n)) S (n) =o (f (n)), the algorithm execution time or space growth rate and F (n) the same growth rate; common f (N) has Chang, linear order (e.g. F (n) =n), square order (f ( n) =n^2), logarithmic order (LOGN), exponential order (2^n), etc. usually we don't want to use exponential order.
Three, linear structure 1, linear table-Continuous storage sequence representation [atomic type array];--Chain expression: Linear list (single linked list), circular linked list, doubly linked list ... (node, head/Tail node); The list is represented by a non-pointer, and the array designator is called a static linked list.
2, Stack LIFO-there are two ways of representation (static/chain, the end of the stack, the bottom of the stack), typical: bracket matching, maze problem, solving problems and so on;--problem simplification: As the maze problem is simplified into the simplest scenario, it expands to the whole situation;--recursion and iteration: solving problems from top to bottom ; Recursive functions: Call your own functions through a series of yourself.
3, Queue FIFO-team head/Team tail; Double-ended queue, output constrained double-ended queue (both inputs one end output), input constrained double-ended queue (output one end input),--cyclic queue: Typical shared buffer/read-write pointer mode;
4, Strings-string: is a finite sequence consisting of 0 or more characters;--Continuous storage: fixed-length sequential storage, heap allocation storage, chained storage, block-chained storage (difference: storing multiple characters in nodes);--optimization algorithm of pattern matching KMP;
5, generalized array and generalized table--cross linked list: Need flag bit flag atom or sub-table;
IV. tree structure-basic definition: Roots, subtrees, leaves, children, brothers, parents ... A set of numbers is called a forest, a hierarchy;--ordered trees: each sub-grove is left to right in order, not interchangeable with trees, otherwise unordered trees;--the storage method of the tree: (array +index, linked list) parental representation, child representation, child brother representation;
Binary Tree--a maximum of two sub-trees per node;--Sequential representation: In order: From top to bottom, from left to right continuous space storage;--Chain expression: List way-traverse binary tree: First order, middle order, post order (the root of the sequence of different: left-right, left-and root-right) , left-to-right, root); --Clue two fork tree: with "clue sign" if left child does not, pointing to its precursor; Right child no, pointing behind;
Optimal binary tree (Huffman tree)-The length of the tree (root to each node path and, path length: root-to-junction branch number and) shortest tree (node weight * node depth);--huffman encoding: The larger the probability, the shorter the path; (Heuristics/backtracking = recursion)
Balanced binary trees (balancedbinary tree or heigh-balanced tree)-the equilibrium Factor (bf:balancefactor) for all nodes is 1, 0, and 1;-- The definition of the equilibrium factor of the node: the depth of the left subtree of the node minus the depth of the right subtree;
The basic definition of the graph structure: each element is a vertex; there is a direction graph: arc, starting point is arc tail, end point is Arc Head, direction graph and no direction graph, Direction complete graph, sparse graph and dense map; sub-graph; The two vertices connected by the graph are adjacent to each other; the number of arcs/edges is called right; the related edge is degree (in/out);
The same path as the last vertex and the first vertex is called a loop or a loop; the path that the vertex does not recur to is a simple path, except that the first vertex and the last vertex are different loops called simple loops or simple loops.
Any vertex has a path, the two vertices are connected, and any two points are connected to a graph called connected graph, the non-connected graph has multiple connected components, and the connected component is the maximal connected component in undirected graph. The corresponding graphs are called strong connected graphs and strong connected components.
A spanning tree is a very small connected sub-graph that contains all the vertices in the graph, but is sufficient to form a tree-containing (n-1) edge.
The storage structure of the graph:--array representation/matrix;--adjacency table: a single linked list with each vertex as the head node;--The Cross linked list: The graph, adjacency table plus inverse adjacency table; a node contains two linked lists of adjacency table and inverse adjacency table;--adjacency multiple tables: Similar to the cross list, each node represents the information of the Edge, Stores information about the next related side of each of the two vertices associated with the node, respectively;
Graph traversal: Depth priority and breadth first
Minimum spanning tree (the tree with the sum of the edge weights): Prim and Kruskal, two algorithms differ: Prim uses the vertex in the spanning tree to find the next edge, and Kruskal always takes the minimum edge to judge;
Topological sort/critical path (based on a forward-free graph)-topological ordering, AOV (activity on Vertex network vertices represent activities, and arcs represent a direction-free graph of precedence relationships). Handles the output of a non-incoming vertex in the graph, removing all arcs with this vertex as the tail, the critical path (Critical path), and AOE (activity on edge) that represents the active network. The AOE network is a forward-and-loop graph with weighted values, and the AOE network can be used to estimate the time spent on the project. The vertex of the 0-degree is called the source point, and the zero-out vertex is called the sink point. The longest path between 0 o'clock and the meeting point is called the critical path. Therefore, non-critical activities do not expedite the progress of the project.
Shortest path problem--the shortest path from one source point to another, (Dijkstra algorithm, increment by path length). -the shortest path between each vertex, (repeated execution of Dijkstra multiple/floyd algorithm, iterative n^3 ...) );
Six, dynamic memory management basic concept-has been assigned to the user to use memory called "Occupy Block", has not been divided into the user's memory block "free block" or "Available space block"--record "free block" chain structure of the available space table;--can use the spatial table according to the different distribution modes of three structural forms: 1, Fixed the same storage space size, 2, limited variable (that is, there are a number of fixed size), 3, a completely non-fixed size variable; [Storage block and storage pool]--allocation algorithm: first-time legal, best quasi-legal, worst-fit;
Boundary identification Method-the head and tail of each storage space to increase the identification information, the table knowledge of the current block information, linked list information and whether to use;--the adjacent storage area is not used in the moment can be merged;--Cyclic link list method can not have fixed linked list, according to different allocation algorithm;
Partner system-The space size is 2^k, when there is no free table to allocate space, can be split from the large space, M class space size, need m free space linked list pointer, memory block with identity header information,-only partners (that is, from a memory allocated) memory can be released at the time of the merger, That is, continuous space may not be merged;--Advantages: simple, fast, disadvantage: easy to generate memory fragmentation;
Useless units collect two ways--reference (using) The register: The space can be freed only if the value of the register is 0 o'clock--until the space table is empty, the execution of the program is interrupted, and all unused space is re-linked to the new working space table;
Storage compressed free space table for contiguous storage space (heap?) , for the release of space debris requires storage compression, generally two ways:-Once the user releases can be compressed;--Indicates that the free space pointer has been increased upward and compressed only when there is no remaining free space.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.