Brother Xiong bless you data structure review

Construct a Huffman tree:

Take the ones with the smallest weights first, then find the ones that are related (usually equal or similar), put aside the ones that don’t matter, and finally combine the ones that are related and those that don’t matter to form a Huffman tree.

.

Minimum spanning tree:

Number of vertices: n
Number of edges: n-1
kruskal: Find the minimum edge
prim: Starting from a point, find the minimum edge based on the set of points

.Depth
and height do not include leaf nodes
. Difference:
Depth refers to the path length from the root node to a certain node, while height refers to the path length from a certain node to the farthest leaf node.

Related example:
A 3-order B-tree with a height of 5 has at least the number of keywords:
2**5-1=31

.Small
root pile: Each small triangle contains the smallest
root of three numbers. Large root pile: Each small triangle contains the largest root of three numbers.

The adjustment process is carried out from the bottom up.

.

Balanced binary tree:

Subtract left from right when calculating

  1. LL type:
    Insert image description here
  2. RR type:

    Replace C with D below
  3. LR type:
    Insert image description here
    E, F interchangeable
  4. RL type:
    Insert image description here
    The E on the left should be B

.Perform
k-way balanced merging of m initial merging segments:
(number of reads + number of writes) * number of passes + internal sorting (number of reads + number of writes)

Number of passes = log logarithm of m with k as the base, rounded up

In order to achieve optimal merging, the number of imaginary segments (initial merging segments with length 0) that need to be supplemented:
Formula: (m - 1)% (k - 1)
When the value of the formula is 0, there is no need to supplement
the value of the formula When it is not 0, the number of imaginary segments that need to be supplemented is: k - formula - 1

The merge plan with the least number of reads and writes to external memory:
add the number of virtual segments that need to be supplemented, 0, at the beginning of the initial merge segment to form a Huffman tree. The Huffman tree
at this time is a k-ary tree.
The number of reads and writes to external memory at this time: weighted value of Huffman tree * 2

.
Dijkstra: Find the minimum edge to form the shortest path based on the set of points.
Prim: Find the minimum edge directly and find the shortest path based on the edge.

.

Clue binary tree:

Insert image description here
First, list the traversal sequence according to the drawing method or the triangle method. They must be next to each other before they can be connected.

.For
a tree: out-degree = in-degree,
number of summary points = number of in-degrees + 1 (the root has no in-degree)

In a tree of degree n, each node can have at most n child nodes.

.Topological
sequence: Find points without in-degree each time

.

Quick sort:

  1. First trip: Set a sentry on the far right, Left on the far left, and Right on the far right except for the sentinel. Left looks for a number greater than the sentinel, and does not move after finding it, waiting for Right to find a number smaller than the sentinel, and swaps the last two numbers after it is found. When Left and Right overlap, determine the size relationship between the number pointed by Left and Right and the sentinel, and then determine whether to exchange the two numbers.
  2. Second pass: Set up a sentry in the middle and repeat the above operations. (left half)
  3. Third trip: (right half)
  4. Continue the above operations until the sorting is completed

.

Circular queue:

  • When front = rear, the queue is empty or full
  • Circular queue A [0] is not necessarily the location of the first element. Similarly, the positions of front and rear are not fixed and do not necessarily point to A [0].
  • After adding an element, the rear pointer moves backward; before adding an element, the rear pointer is at the previous position.
    Insert image description here

.

How hash tables handle collisions:

They are all hash methods:

  1. Linear detection
    Insert image description here
  2. secondary detection
    Insert image description here
  3. linking method
    Insert image description here

.

sparse matrix:

  1. Linear list of triples: ((row, column, value) for all non-zero elements)
  2. cross linked list
    Insert image description here

.

Generalized table:

Insert image description here
The head is the first element
and the tail is all other elements except the first element.

.

Critical Path:

  1. The earliest start time = the latest start time nodes are connected and the weights are added up = the value after the forward push ends
  2. Earliest start time = Max(n1,n2) Forward push
  3. Latest start time = Min(n1,n2) Backwards
  4. The earliest start time of the starting point and the end point = the latest start time
  5. The starting point is (0, 0) and the end point is the value after the forward push is completed.

example:
Insert image description here

.

Depth-first and breadth-first spanning trees:

Depth First:
Case:
Insert image description here
Breadth First:

  • Similar to level traversal
  • Any node can become a vertex, and what is connected to the vertex is the second layer, and the same goes downwards
    . Case:
    Insert image description here

.

Binary search:

Formula: mid = (low + high)/2

Example:
For an ordered list of length n, if a non-existent element is searched using binary search, what is the maximum number of comparisons?
Formula: log logarithm of n with base 2 rounded down + 1

.

Prefix, infix, and postfix expressions:

Mutual conversion:
The data structure of stack is used for the mutual conversion between prefix, infix and suffix.
Insert image description here
Prefix to infix:
Case:
Insert image description here
Infix to prefix:
Case:
Insert image description here
Infix to suffix:
Case:
Insert image description here
Suffix to infix:
Case:
Insert image description here

.

time complexity:

The space complexity of recursion is O(n) and
the space complexity of tail recursion is O(1)

Tail recursion:

  1. The final step in a recursive function is to call the function itself.
  2. The result of the recursive call does not participate in any subsequent operations, but is returned directly.

.

Sorting algorithm time and space complexity:

Insert image description here

.

B - Insertion of tree:

B - The tree is similar to a polynomial tree
in which one node can accommodate multiple numbers. B - The number of keywords in all non-terminal nodes in the tree except the root must be greater than or equal to the upper integer of m / 2 - 1, no more than m - 1
m: order
Insert image description here

.

B - Deletion of tree:

  1. If the node is the lowest non-terminal node, since its pointers are all empty, deletion will not affect other nodes and can be deleted directly.
  2. If the node is not the lowest non-terminal node, the adjacent pointer points to a subtree and cannot be deleted directly.

Guess you like

Origin blog.csdn.net/m0_64799907/article/details/131342544