Java Road --- Day17 (data structures)

2019-11-04-23:03:13

table of Contents:

  1. The common data structures

  2. Stack

  3. Queue

  4. Array

  5. list

  6. The red-black tree


 

Common data structures:

  Comprising: a stack, queue, array, linked list, and red-black tree

Stack:

  Stack: stack, known as a stack, which is limited by a linear operation table, with the restriction that only permits insertion and deletion operations in the subject at one end, is not allowed to add any other location, find, delete, etc.

  Features:

    1. FILO (i.e., into the memory element to the element after it has successively taken back, in order to remove the element). For example, the bullet pressed into the clip, the first bullet under pressure to go after pressing into the bullets above, when shot, the first bullet above pop, pop before following bullets.

    2. The stack inlet, an outlet of the stack is the top position.

      Noun Note:

        1. push: that is stored elements. That is, the element the tip position onto the stack, the stack moves sequentially existing element position to a bottom of stack direction

        2. popped: it is to take elements. That is, the position of the top stack element is taken out, the elements already in the stack sequentially moves one place to the direction of stack. 

        

queue:

  Queues: queue, referred to as the team, it is the same as a stack, the linear form is also a restricted operation, the restriction that only permits insertion of the end of the table, and delete the table at the other end.

  Features:

    1. FIFO (i.e., into the memory element to the front element after it has successively taken out, in order to remove the element). For example, the train went through the tunnel, the front go in, go in the rear; the front first came out, came out after the rear.

    2. queue entry, each accounted outlet side. For example, the left side of the figure is an inlet, an outlet for the right

    

Array: 

  Array: Array, is an ordered sequence of elements, an array is a contiguous open space in memory, and storage elements in this space. The B & B is like a discharge, there are 100 rooms, has a fixed number from 001,100 to each room by number can quickly find people to rent.

  Features:

    1. Find an element fast: by the index, you can quickly access the location of the element

    

    2. Slow additions of elements:

      Specified index adding elements: the need to create a new array, specify the new elements stored in the specified index position, and then the original array elements according to the index, is copied to the new array corresponding to the index. As shown below

      

      To delete the specified index elements: the need to create a new array, the original array elements according to the index, copied to the array corresponding to the location of the new index, the original index location specified in the array element is not copied to the new array. As shown below

    

List:

  List: linked list, a series junction node (referred to as a node for each element in the list), with node i can be dynamically generated at runtime

    Node:

      1 is a data field for storing data elements

      2 is a next node address stored in a pointer field.

    Features:

      1. among a plurality of nodes, connected by an address. For example, more than one person hand in hand, each person using his right hand, left hand pull the next person, and so on, so many individuals and even together.

    

      2. Find the element slow: Want to find an element, you need to connect the node, and then click Find specified element back

      3. quickly add or delete elements

        Adding elements: only need to change the address to connect the next element

        

        Removing elements: only need to change the address to connect the next element

        

Red-black tree:

  Binary: binary tree, each node is not more than 2 ordered tree (Tree) 

  Features:

    1. The binary tree each node has two sub-trees multiple tree structure. Called the top of the root, both sides called "left sub-tree" and "right sub-tree."

    

  Red-black tree: One of the more interesting binary tree is called red-black tree, red-black tree itself is a binary search tree, the nodes were inserted into the tree still is a binary search tree. It means that the key value of the tree is still orderly

    Red-black tree constraints:

      1. The nodes may be red or black

      2. The root is black

      3. leaf nodes (especially empty node) is black

      4. The child nodes of each node are black red

      The same on all paths each of which a node to the leaf node points to any black section

    Red-black tree features:

      Very fast, reaching a balanced tree, look for the elements and leaves little more than twice the number of times 

Guess you like

Origin www.cnblogs.com/hpcz190911/p/11795798.html