data structure
data structure:
Data structure _ stack : last out
- Inlet and outlet on the same side
_ Queue data structures: FIFO
- Set on both sides of the inlet and outlet
_ An array of data structures:
- Fast query: address of the array is continuous, we can find an array by the first address of the array, you can quickly find a particular element of the array by index.
- Slow additions: length of the array is fixed, we want to add / delete an element, you must create a new array, copy the data over the original array
例:
you [] arr = new you [] {1,2,3,4};
Element 3 array index should be deleted
- You must create a new array length is the length of the original array -1
- Copy the other elements of the original array to a new array
- Assigned to the variable in the address of the new array arr
- Original array will be destroyed (recycled garbage collection) in memory
_ Linked list data structure:
- Slow query: linked list address is not continuous, elements each query, the query must start from scratch.
- Additions and deletions fast: chain structure, add / delete an element, there is no impact on the overall structure of the chain, so fast additions and deletions
Each element of the list is also known as a node
a node contains a data source (memory array), two pointer field (storage address)
- Unidirectional chain: only one strand of the chain, we can not guarantee the order of elements (memory elements and the order of the elements removed may be inconsistent)
- Bidirectional chain: the chain has two chains, one strand has a sequence specifically recording element, an ordered set
Binary tree: branches no more than two
- Sort tree / search trees: On the basis of the binary tree, there is an element of the order (left child small tree, right subtree large)
- Balanced tree: left child and right child equal
- Unbalanced tree: left child and right child are not equal
Red-black tree:
Features: close to a balanced tree, the query speed is very fast, the maximum number of queries leaf node and can not exceed twice the minimum number of
constraints:
- Node can be red or black
- The root node is black
- Leaf node (null node) is black
- Each red node's children are black
- Any node on all paths to each of which a leaf node is equal to the number of nodes black