Chapter6. Data structure

来源:互联网 发布:猎豹浏览器有mac版吗 编辑:程序博客网 时间:2024/05/29 10:53

数据结构是计算机中存储,组织数据的方式,精心选择的数据结构可以带来最优效率算法。

C++, Java, Python 等面向对象的编程语言可使用类完成这一功能。现代编程语言及其运行环境在标准库中都包含了多种数据结构,例如C++标准模版库中的容器,Java集合框架以及微软的.NET Framework.

数据结构意味着接口或封装:一个数据结构可被视为两个函数之间的接口,或者是由数据类型联合组成的存储内容的访问方法封装。

Usually, efficient data structures are key to designing efficient algorithms. Some formal design methods and programming languages emphasize data structures, rather than algorithms, as the key organizing factor in software design.

Data structures are generally based on the ability of a computer to fetch and store data at any place in its memory, specified by apointer--a bit string, representing a memory address, that can be itself stored in memory and manipulated by the program. Thus, the array record data structures are based on computing the addresses of data items with arithmetic operations; while the linked data structures are based on storing addresses of data items within the structure itself. A data structure that is defined indirectly by the operations that may be performed on it, and the mathematical properties of those operations (including theirspace and time cost).

常见的数据结构:

数组  (Array) 

A array is a number of elements in a specific order, typically all of thesame type. Elements are accessed using an integer index to specify which element is required (although the elements may be of almost any type). Typical implementations allocate contiguous memory words for the elements of arrays (but this is not always a necessity). Arrays may be fixed-length or resizable.

Record (tuple or struct)

A record  is an aggregate data structure. A record isa value that contains other values, typically in fixed number and sequence and typically indexed by names. The elements of records are usually called fields or members.

Associative array (dictionary or map)

An associative array is a more flexible variation on an array, in which name-value pairs can be added and deleted freely. A hash table is a common implementation of an associative array.

Union

A union type specifies which of a number of permitted primitive types may be stored in its instances. Contrast with a record, which could be defined tocontain a float and an integer; whereas in a union, there isonly one value at a time. Enough space is allocated to contain the widest member datatype.

Tagged union (variant)

A tagged union contains an additional field indicating its current type, for enhanced type safety.

Set

A set is an abstract data structure that can store specific values, in no particular order and with no duplicate values.

堆栈  (Stack)

A stack or LIFO (last in, first out) is an abstract data type that serves asa collection of elements, with two principal operations:push adds an element to the collection; pop removes the last element that was added.


队列  (Queue)

A queue is a particular kind of abstract data type or collection in which the entities in the collection are kept in order and the principal operations (or only) on the collection are the addition of entities to therear terminal position, know asenqueue, and removal of entities from the front terminal position, known as dequeue. This makes the queue aFIFO(First-In-First-Out) data structure. 


链表  (Linked List)

A linked list is a data structure consisting of a group of nodes which together represent a sequence. Under the simplest form, each node is composed of a data and a reference (in other words, a link) to the next node in the sequence; more complex variants add additional links.This structure allows for efficient insertion or removal of elements from any position in the sequence.


树  (Tree) and 图  (Graph)

Graphs and trees are linked abstract data structures composed of nodes. Each node contains a value and one or more pointers to other nodes arranged in a hierarchy. Graphs can be used to represent networks, while variants of trees can be used for sorting and searching, having their nodes arranged in some relative order based on their values.

堆  (Heap)

A heap is a specialized tree-based data structure that satisfies the heap property: If A is a parent node of B then the key of node A is ordered with respect to the key of node B with the same ordering applying across the heap. Heaps can then be classified further as either "max heap" and "min heap". In a max heap, the keys of parent nodes are always greater than or equal to those of the children and the highest key is in the root node. In a min heap, the keys of parent nodes are less than or equal to those of the children and the lowest key is in the root node. Heaps are crucial in several efficient graph algorithms such as Dijkstra's algorithm and in the sorting algorithm heap sort. 

散列表  (Hash)

A hash table (hash map) is a data structure used to implement an associative array,a structure that can map keys to values. A hash tableuses a hash function to compute an index into an array of buckets or slots, from which the correct value can be found. Ideally, the hash function will assign each key to a unique bucket, but this situation is rarely achievable in practice. (usually some keys will hash to the same bucket) The average cost for each lookup is independent of the number of elements stored in the table.More efficient than search trees or any other table lookup structure.




0 0
原创粉丝点击