Summary notes of search algorithms for data structures

Source: Internet
Author: User

Find Algorithm  

First, the basic concept of the search

Lookup, also called retrieval, is the work of finding a particular data element in a large number of data elements. A lookup is an operation.

Second, sequential search

One of the simplest ways to find an unordered sequence.

The time complexity is O (n).

Third, binary search

A way to find a sorted sequence. And only applies to sequences of sequential storage structures. The elements in the sequence are required to be basically the same, and the retrieval efficiency is affected when the delete and insert operations are required.

The time complexity is O (logn).

Four, B Tree

The B-Tree is also called the binary sort tree.

1. Concept:

It is either an empty tree or a two-fork tree with the following properties:

(1) The Joz tree is not empty, then the value of all nodes on the left subtree is smaller than the root node of the tree where Zuozi is located;

(2) If the right subtree is not empty, then the value of all nodes on the right subtree is greater than the value of the root node of the tree where the right subtree is located;

(3) The left and right sub-trees are also two-fork sorting trees respectively;

2, B-Tree search:

The complexity of time is related to the depth of the tree.

Step: Joghen The keyword value of the node is equal to the keyword found, success.

Otherwise: If the key value of the small root node, recursively check the left subtree.

Jordahugen the key value of the node and recursively checks the right subtree.

If the subtree is empty, the lookup is unsuccessful.

3, B-Tree insert:

First, the search algorithm is performed to find the Father node of the inserted node.

The left son or the right son who is the father of the knot is judged by the insertion point. Insert nodes as leaf nodes.

If the binary tree is empty. First, the root node is generated separately.

Note: The newly inserted node is always the leaf node, so the algorithm complexity is O (h).

4, B-Tree deletion:

If the deleted node does not have a child, then the algorithm ends after deletion;

If the deleted node has only one child, then the child replaces the location of the deleted node after the deletion;

If the deleted node has two children, then select the node's successor (the node right child is the root of the tree in the left subtree of the lowest value of the point) as the new root, at the same time at the beginning of the subsequent node, the execution of the first two delete algorithm, delete algorithm end.

5. B + Tree

The B + Tree of an M-order satisfies the following conditions:

(1) Each node has a maximum of M children.

(2) root nodes and leaf nodes, each of the other nodes has at least ém/2ù children.

(3) The root node has at least two children.

(4) All leaf nodes are on the same layer and contain all the keyword information.

(5) A branch node with a k child contains K keywords.

For example:

Five, hash (hash) table

Keywords: hash function, filling factor, conflict, synonym;

The keyword and the stored address establish a corresponding relationship:

ADD = Hash (key);

Conflict resolution Methods:

Open addressing Method-detection mode: linear detection, two-time detection.

Detach Link Method – the way the list is used.

The lookup efficiency is not dependent on the data length n, the lookup efficiency is very fast, many can reach O (1), the efficiency of the lookup is a (filling factor) function, not n. So no matter how many n can find a suitable filling factor to limit the average lookup length to a range.

The following is the test code for the lookup algorithm, which is for communication only:

VC + + 6.0 Environment

Http://files.cnblogs.com/yyangblog/SearchAlgorithm.rar

Summary notes of search algorithms for data structures

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.