[Introduction to Algorithms] Chapter 10, Basic Data Structures

10.1 Stacks and queues

All are dynamic collections, and the Delete operation is preset.

stack

Insert:push Delete: pop

Implementation, a counter keeps track of the number of elements

Similarly, the queue implementation is a counter to record the position of the first and last elements. If the first element is too far behind, the tail element can come over.

 

10.2 Linked list

Doubly linked list: each element is an object, there are two pointers prev, next, and the value of the element itself, the elements on both sides are None

L.head points to the first element.

linked list search, insert, delete,

Sentinel: Main role: Simplify the processing of boundary values!

  It also looks like an element, but the value is empty, so a doubly linked list can be turned into a doubly linked list with a sentinel, and the sentinel is located between the header and the end of the table.

Do not abuse sentinels: if there are many very short linked lists, the extra storage space occupied by sentinels will be a waste of storage.

 

10.3 Implementation of pointers and objects

Objects are represented by multiple arrays, and positions are represented by subscripts in the other direction

The object is represented by a single array, and the continuous array stores all the information, and the position is represented by a subscript. Advantage: Allows objects of different lengths to be stored in the same array.

Object allocation and release: generally by gc

  The following does a doubly linked list for a multiarray representation:

  Maintain a singly linked list: free list, only next array, each object is either in the linked list or in the free list. The free list is like a stack, and the next allocation is the one that has just been freed.

 

10.4 Representation of Rooted Trees

Represented in a chained data structure:

Binary tree: easy

Unlimited number of nodes: left child right sibling notation

Other representations: as the case may be, e.g. a complete binary tree is represented by an array in heapsort.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324975769&siteId=291194637