Basic Data Structure Knowledge (2)

Source: Internet
Author: User

The content is written in "basic knowledge of data structure (1)".

Classification of linked lists

Single-chain table

A single-chain table is a chained access structure. To find the I-th data element, you must first find the I-1-th data element. The shadow area in the figure indicates the data field, and the blank area indicates the pointer field. The last pointer field is empty.


Cyclic linked list

Cyclic linked list is another form of chained storage structure. It points the pointer field of the last node in the table to the header node, and the entire linked list forms a ring. Cyclic linked lists are classified into single cyclic linked lists and multi-Heavy Chain cyclic linked lists.


Double-linked table

A double-chain table, also known as a two-way linked list, is a type of linked list. Each of its data nodes has two pointers pointing to the direct successor and direct precursor respectively. Therefore, starting from any node in the two-way linked list, you can easily access its precursor node and successor node. The flexibility of a double-linked table is better than that of a single-linked table, but the cost is higher (two pointers exist ).


Comparison Between Sequence tables and linked lists

The storage location of an ordered table is adjacent to a continuous data structure that can be accessed immediately. Before using an ordered table, you must specify the starting length. Once the memory is allocated, it cannot be changed dynamically during use. Its advantage is that it is convenient to access data and can immediately access any data in the table.

A linked list is a data structure used to describe the relationship between elements. It can be a physical space with Discontinuous physical addresses. You cannot access the linked list element immediately. You must start from the header and search for the element step by step. It has the following advantages: For arrays, You can dynamically change the Data Length and allocate physical space.

In use: if an array is in use, there are many queries, but few data is inserted and deleted, and the length of the array remains unchanged, it is reasonable to select the sequence table. If you insert, delete, or have an undefined array, you can select a linked list.


Tree)

A tree is a collection K that contains n (n> 0) nodes and defines a relationship N in K. N meets the following conditions:

(1) There is only one node K0. For relation N, there is no precursor. K0 is the root node of the tree. Root for short ).

(2) Except for K0, each node in K has only one precursor for relation n.

(3) Each node in K can have m successor for relation n (m> = 0 ).

The tree has the following features:

(1) Each node has zero or multiple subnodes.

(2) Each subnode has only one parent node.

(3) A node without a parent node is called a root node.

Tree terminology
Node degree: the number of Subtrees contained in a node is called the degree of the node;

Leaf node or terminal node: A node with zero degree is called a leaf node;

Non-terminal node or branch node: A node with a non-zero degree;

Parent or parent node: If a node contains a child node, this node is called the parent node of its child node;

Child node or subnode: the root node of the subtree contained in a node is called the subnode of the node;

Sibling node: A node with the same parent node is called a sibling node;

Tree height or depth: defines the hierarchy of the root node of a tree as 1, and the hierarchy of other nodes is the hierarchy of its parent node plus 1. The maximum value of the hierarchy of all nodes in a tree is the depth of the tree. Node hierarchy: defined from the root, the root layer is 1st, the root sub-node is 2nd, and so on;

Tree degree: the highest node degree in a tree is called the tree degree;

Node ancestor: All nodes from the root node to the branch of the node;

Descendant: Any node in the subtree rooted in a node is called the descendant of the node.

Forest: a forest is a collection of trees that are separated by M (M> = 0) trees;

Tree traversal

Tree traversal can be divided into pre-order traversal, post-order traversal, and hierarchical traversal. The traversal order of pre-order traversal is to first access the root node and then the leaf node; The traversal order of post-order traversal is to first access the leaf node and then access the root node; hierarchical traversal is performed by hierarchy.


Binary Tree

A binary tree is an ordered tree with a maximum of two Subtrees. Generally, a subtree is called "Left subtree" and "right subtree ). Binary Trees are classified into full Binary Trees, full binary trees, and incomplete Binary Trees.


Graph)

A graph consists of a finite set V of a node and a set E of an edge. In order to distinguish it from the tree structure, the node is often called a vertex in the graph structure, and the edge is an ordered even pair of vertex. If there is an edge between two vertices, the two vertices are adjacent. Graphs are divided into undirected graphs and directed graphs.


Graph Traversal

Graph traversal is divided into depth-first traversal and breadth-first traversal. The idea of depth-first traversal is similar to the first-order traversal of a tree. The traversal process can be described as follows: starting from a vertex v, accessing the vertex, and then continuing to traverse the rest of the vertices in the graph with priority from the unaccessed neighbor contacts of V, until all vertices in the figure that have the same path with V are accessed.

Description of the breadth-first Traversal method: starting from a vertex v, after accessing the vertex v, all the neighboring contacts that have not been accessed by V in sequence, then, access the adjacent points of each adjacent point, and the access sequence should be maintained. The adjacent points of the first accessed vertex are also preferentially accessed until all vertices in the graph are accessed.


 

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.