Introduction to the algorithm (8) The tenth chapter basic data Structure __java

Source: Internet
Author: User

This chapter describes several basic structures: stacks, queues, linked lists, and a root tree. Stacks and Queues (10.1,p129)

Stacks and queues are dynamic collections. Stack Stack

concept definition : Stack adopts advanced back out strategy (LIFO). The basic operation is pressing (push) and pop (pop). If s.top=0 indicates that the stack is empty, an underflow (underflow) will occur if you attempt to perform a pop operation on an empty stack. If s.top>n, which means the stack is full, an overflow (overflow) occurs if a push operation takes place.

Stack of Python implementation code links: introduction_to_algorihtms/stack_my.py queue queues

Concept definition : The queue adopts advanced first out strategy (FIFO). Basic operations are the team (enqueue) and the Outbound (dequeue). If Head=tail indicates that the queue is empty, an underflow (underflow) occurs if an attempt is made to enqueue an empty queue. If head=tail+1 indicates that the queue is full, an overflow (overflow) occurs if the dequeue operation is performed.

Python implementation of queues: introduction_to_algorihtms/queue_my.py list (10.2,p131)

A linked list is a discontinuous, non sequential storage structure on a physical storage unit, and the logical order of data elements is achieved through the sequence of pointers in the linked list. A list consists of a series of nodes (each of which is called a node), which can be generated dynamically at runtime.

Each node of a two-way list (doubly linked list) consists of two parts: one is the data field where the data element is stored, and the other is the pointer field that stores the next (previous) node address.

The Python implementation code for unsorted two-way lists: introduction_to_algorihtms/list_my.py Pointers and object implementations (10.3,p134)

When pointers and object data types are not supported in some languages, we can construct objects and pointers using arrays and array subscripts. This list is called a static linked list. The majority group representation of an object

Use three array next key prev to represent the successor/data/precursor of the linked list, respectively.
Most group representations can only represent homogeneous objects (all objects have the same attributes). The singular group representation can represent heterogeneous objects (such as objects with different lengths). the singular group representation of an object

A double linked list can be represented by an array, which is more flexible because it allows objects of different lengths to be stored in the same array. Most of the data structures we consider are composed of isomorphic elements, so the majority representation of objects is sufficient to meet our needs. allocation and release of objects

Save the free object in a single linked list, called the free list.

The free table uses only the next array, which stores only the next pointer in the list. The head of the free table is stored in the global variable freedom.

The implementation of the free table is similar to the stack: The next object to be allocated is the last object to be freed (LIFO). a representation of a root tree (10.4,p137)

A chain structure is used to indicate a root tree. Two fork Tree

The binary tree T has three attributes: P,left,right a pointer to the parent node, the left child node, and the right child node.
If X.p=nil, then x is the root node. Property T.root point to the root node of the entire tree T.

More about the binary tree content will be introduced in the 12th chapter. This time does not realize two fork tree. Branch Unrestricted has a root tree

Two methods of representation. One is to extend Left,right to CHILD1,⋯,CHILDK Child_1,\cdots,child_k, the disadvantage of which is that if K is large, most nodes have only a small number of children and waste a lot of storage space.

The second method is the right sibling representation of the left child (left-child,right-sibling representation). Each node has two pointers in addition to the parent node pointer:
X.left-child represents node X's leftmost child node, and x.right-sibling represents the adjacent sibling node on the right. reference materials

1. Algorithm Introduction Chinese third edition
2. Introduction to the algorithm tenth chapter basic data structure

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.