Algorithm-Summary of Basic Data Structure

Source: Internet
Author: User

Algorithm-Summary of Basic Data Structure

In fact, the data structure and algorithms are really important, and they have never been very concerned about before, so every written test interview is despised. "Programming is the algorithm and data structure, and the algorithm and data structure are the soul of programming." I feel that this sentence is still a bit reasonable. Today, I have reviewed some basic data structures, recorded some basic properties, and summarized some common search and sorting algorithms.

1. Linear Structure

Sequential storage linear table: stores elements in sequential storage units,Physically adjacent;

Chain Stores linear tables: Links elements in the order of logic,Address continuity not required;

STACK: a linear table that is inserted or deleted only at one end of the table,"Back-to-first-out";

Queue: a linear table that is inserted at one end of the table and deleted at the other end,"First-in-first-out"

Sometimes the written test of stacks and queues has problems with the "FIFO" features, but it is easy to understand.

Ii. Concepts of tree 2.1

A binary tree is a tree structure with a maximum of two Subtrees ("Left subtree" and "right subtree") on each node.

Full Binary Tree: the number of nodes in each layer of the binary tree reaches the maximum (that is, the depth of k, and there are 2 ^ K-1 nodes );

Full Binary Tree: only the level of the bottom two nodes can be less than 2, and the nodes at the bottom layer are concentrated on the left side (the depth is k, and there is a binary tree with n nodes, if and only when each of its nodes corresponds to a full binary tree with a depth of k, the number of nodes ranging from 1 to n ).

Full binary trees are a special case of full Binary Trees, such:

Balanced Binary Tree: Also known as AVL Tree. It is an empty tree or its left and right subtree. The absolute value of the height difference cannot exceed 1, and both left and right Subtrees are a balanced binary tree (the full Binary Tree is a balanced binary tree), such

2.2 Binary Tree nature: a. The I layer of the binary tree has at most 2 ^ {I-1} nodes;
B. A k-depth binary tree can have at most 2 ^ K-1 nodes;
C. Depth of A Complete Binary Tree with n nodes k = log2n + 1;
D. For any binary tree T, if the number of terminal nodes is n0 and the number of nodes with the degree of 2 is n2, n0 = n2 + 1.
2.3 binary tree traversal

Just remember one thing about binary tree traversal, that is, the traversal order is for the root node. For example, first access the root node, then traverse the left subtree, and finally traverse the right subtree. In combination with instances, such:

First traverse result: abdgcefh

Result of the Middle-order traversal: dgbaechf

Result of post-order traversal: gdbehfca

Iii. Diagram

Undirected full graph: any two vertices have a direct edge connected. n (n-1)/two edges exist in an undirected complete graph containing n vertices;

Directed full graph: any two vertices are connected by two arcs in the opposite direction. n (n-1) edges exist in an directed full graph containing n vertices.

Depth-first traversal: similar to the first-order traversal of a tree, this shows the order in which depth-first search vertices are accessed:

Graph breadth-first traversal: similar to hierarchy traversal of a tree, it shows the order in which the breadth-first search vertex is 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.