Basic knowledge of data structures (1)

Source: Internet
Author: User
Tags arrays data structures

The data structure is the way that the computer stores and organizes it. A data structure is a collection of elements that have one or more specific relationships to each other. Typically, a well-chosen data structure can lead to higher operational or storage efficiency. Data structures are often associated with efficient retrieval algorithms and indexing techniques.

Data structure refers to the relationship between the elements, including two components, the logical structure of data and the storage structure of data. The logical structure includes: set, linear structure, tree structure, graphic structure. Storage structure refers to the storage space of the logical structure of data, including: sequential storage structure, chain storage structure, index storage structure, hash storage structure.

Linear Table

Linear tables are the most basic, simplest, and most commonly used data structures. The relationship between data elements in a linear table is a one-to-one relationship, that is, except for the first and last data elements, the other data elements are both end-to-tail. The logic structure of linear table is simple and easy to implement and operate. Therefore, the data structure of linear table is widely used in practical application.

A linear table is a linear structure, which is a finite sequence of n≥0 nodes, for which there is only one starting node without a precursor but there is a successor, and only one terminal node has no successor but there is a precursor node, and the other nodes have only one precursor and one successor node. In general, a linear table can be expressed as a linear sequence: K1,k2,..., kn, where K1 is the starting node, and KN is the terminal node.

In practical applications, linear tables are used in the form of stacks, queues, strings, arrays and other special linear tables. Here is a brief introduction.

Arrays (Array)

In the program design, in order to deal with the convenience, the same type of a number of variables organized in an orderly form. The collection of these ordered, homogeneous data elements is called an array. In the C language, an array is a constructed data type. An array can be decomposed into multiple array elements, which can be either basic data types or constructed types. Therefore, according to the type of array elements, the array can be divided into numerical array, character array, pointer array, array of structures and other categories.

Stacks (Stack)

A stack is a special linear table that can be inserted and deleted only at one end. It stores the data according to the advanced principle, the first data is pressed into the bottom of the stack, the final data is at the top of the stack, and the data is read from the top of the stack (the last data is read first).


Queuing (queue)

A special linear table that allows for deletion only at the front end of the table (front), and in the back end of the table (rear). The end of the insert operation is called the tail of the queue, and the end of the delete operation is called the team header. The queue organizes the data according to the principle of "FIFO" or "Backward out". When there are no elements in the queue, it is called an empty queue.


Among them, there is a special form in the queue, that is, the loop queue. In order to make full use of vector space in computer, the method of overcoming "false overflow" is to think of vector space as a ring with the end-to-end, and call this vector as a cyclic vector. The queue in which it is stored is known as the circular queue (Circular queues). The operational characteristics of the queue are "FIFO". The loop queue is mainly the use of the head pointer and the tail pointer, and the decision condition of the queue empty and full, and the implementation of the queue and queue operation.


From the storage structure, the linear structure can be divided into sequential tables and linked lists. Here's a quick introduction:

Sequential Table

A sequential table is a linear table that is stored as an array in the computer's memory, which stores the linear structure of the data elements sequentially, using a contiguous set of storage units. Linear tables are stored in sequential storage, which is called sequential tables. A sequential table is one in which nodes in a table are stored sequentially in a contiguous set of storage cells in the computer's memory.

Elements are stored sequentially in memory, and the area of memory is a contiguous chunk.


Linked list

A linked list is a non-sequential, non-sequential storage structure on a physical storage unit, and the logical order of the data elements is achieved through the order of the pointers in the linked list. A linked list consists of a series of nodes (each element in the list is called a node) that can be dynamically generated at run time. Each node consists of two parts: one is the data field that stores the data element, and the other is the pointer field that stores the next node address. The list is easier to insert and delete than the linear table order structure.

A linked list is a discrete, separate space that is connected by a logical pointer to form a whole.


Not to be continued ...

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.