Java Fundamentals-Data Structure summary

Source: Internet
Author: User

Objective: To strengthen the understanding of the memory allocation of classes and objects, to enhance the operational ability and to understand data structure.

Structure:  The relationship between data elements. Data structures are:  with structures. The linear structure:  the logic between each data element to appear with a simple expression of a linear sequence. The inverse is a nonlinear structure. It is divided into:  linear structure and nonlinear structure according to logical structure. Linear structures include: linear tables-arrays (sequential tables), linked lists (chained tables) + single-chain, double-stranded                          Linear table-queue, stack nonlinear structure includes: tree, graph   Linear table:        Linear table sequential storage structure: (array)                      uses a contiguous set of addresses to store data elements for linear tables at once.                 features:                     Physically adjacent data elements are stored in the same location.         Linear table chain storage structure: (linked list)                      Use a set of arbitrary storage units, storing the data elements of a linear table, and connecting a sequence of nodes by a pointer. The first element is the head node (the head node must be protected from movement, it can be saved with a third variable, and then the third variable is used for actual operation). The last one is the tail node.                     nodes contain    data fields: The information stored by itself.                                      Pointer field (chain domain, reference domain): stores the storage address of the successor element.         stacks: a linear table that can only be inserted and deleted at one end of the table.          Stack top: Allows one end of the stack to be pushed out.          Bottom of stack: not allowed on one end of the stack.          Features: Advanced out     first in last out  queue: a linear table that can only be inserted at one end of a table and delete operations at the other end of the table.         To top: deleted one end (out of line)          Team tail: one end of the insertion (queued)     & nbsp   Features: FIFO first out  Create a linked list: ① first determine the header Reference object    ② in the process of establishing the table, each data element contains an address that points to the next data element. Ways to create a linked list: ①    ②    ③ insert between two nodes.   Single Linked list: If the node in the list contains a pointer field pointing to the successor node.         Cons: Only follow the node's direct successor. Doubly linked list: The nodes in the list contain two references, respectively, to direct precursors and direct successors.         Two-strand composition: Data domain, direct forward, direct successor   single-chain vs. Double-stranded: Single-linked lists are one-way access, and doubly-linked lists can be accessed in both directions.          &NBsp                        single-linked list deletion, You must know the direct precursor, while the double-linked list is deleted by simply knowing the deleted node.   Sequence table (array) differs from linked list:           ① storage space, arrays are statically allocated memory space, all elements are stored in a contiguous set of storage units , once assigned, immutable, and not extensible, the sequence number of the data element in the array determines its position in the storage unit. Therefore, the order table does not require a pointer field, and the linked list is dynamically allocated memory space, storage space is indeterminate.            ② arrays are easy to find and modify (subscript positioning), but are not conducive to insertion and deletion (too much data movement) and are not easy to expand (continuous address, static storage structure). The list is not easy to find and modify (from the chain head to the end of the chain), but easy to insert and delete and fast (broken chain).   Tree: A finite set of N (n>0) nodes. There is only one root node. Root node: A node in a tree that has no parent nodes. leaf node (terminal node): There are no sub-nodes in a tree. Sibling node: All nodes of the same parent node. Node degree (degree of branching): The number of nodes that each one has. The degree of the tree (the branching degree of the tree): The largest node in a tree. Ancestor: All nodes on the path from a node x to a root node are ancestors of x nodes.   Two fork tree (two tree or binary tree): nodes up to two. Binary tree to satisfy the condition: ① have and only have a node called the root.                                 ② The remaining nodes are divided into two disjoint collections, called Saozi right subtrees. In a binary tree, the total number of nodes in layer I does not exceed 2^ (i-1); full two tree: all the nodes in the tree are in the same stratum and the other non-terminal nodes are "2", the height of the tree is K, the node is 2^k-1; a complete binary tree: If the height of the two fork tree is H, the other layers except the H layer (1~h-1), the number of nodes reached the maximum, the H layer has leaf nodes, and leaf nodes are arranged from left to right in order.      a tree if it is full of two fork tree, then it must be a completely binary tree, a tree if it is a complete binary tree, it is not necessarily full of two fork trees.      (small Zoda right) binary tree traversal: ① First Order: root around if the binary tree is not empty, then access to the root node, according to the first sequence to traverse the left subtree, and then traverse the right subtree.                      ②: Zogen Right if the binary tree is not empty, by the middle sequence to traverse the left subtree, and then access the root node, and then traverse the right sub-tree by the middle sequence.                      ③ post-order: Left and right root if the binary tree is non-empty, according to the post-secondary traversal of the left subtree, and then traverse the tree, and then access the root node.   Two fork Tree Delete: ① no left no right: divided into: root node non-root node, but is the leaf node (divided into: Zuo right leaf)                       ② has left no right: divided into: root node non-root node (divided into: Left node right node)                       ③ There is no right left: divided into: root node non-root node (divided into: Left node right node)                       ④ has left and right: divided into: root node non-root node (divided into: Left node right node) (judge is to move up the left node of the rightmost or right node leftmost)  &nbsP

Java Fundamentals-Data structure summary

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.