Data structure - the first chapter, the second chapter

  === === Data Structure

  Data structures: bluntly speaking, is to study how data is stored.

  Data storage is only one purpose, which is to facilitate post for data reuse.

  For a complex relationship between the data store, or if a variable or array to store the data storage is not a problem, but can not reflect the logical relationships between the data, the latter can not be used.

  Data structure to solve how to store data with complex relationships but also help re-use the data late.

===

  Data structure comprising: a linear form, a tree structure, the structure of FIG.

  Linear table comprising: a table sequence, linked lists, stacks, queues

  Tree structure including: ordinary tree, binary tree, threaded binary, etc.

  FIG structure comprising: a storage structure of FIG.

=== linear table

  Data stored in the linear list structure is often arranged in sequence, only one of both front and back data, including such data can be one to one relationship using a linear table to store.

  Table is divided into a linear sequence table and linked list.

  Sequence table: common array. The order of the underlying table structure is implemented by the array, for beginners, the order of the table can be fully equivalent to the array, but this is not practical.

  List: We know that using the order form (the underlying implementation by the array), the need to apply in advance a certain amount of storage space, the physical address of this storage space is continuous. List is completely different when using a linked list to store data, is used with the application, the data storage location is therefore separated from each other, in other words, where data is stored is random.

  In order to establish "sequentially arranged" in relation to the respective data blocks, each data block list to the addition of a pointer, each pointer points to the next data block are a data block (data block last pointer points to NULL), so that, seemingly mM unrelated data block is established "sequentially arranged" relationship, and then form a linked list.

=== === stacks and queues

  Stacks and queues belonging to the linear form, is a special linear form, because they made a clear demand for out of linear elements in the table.

  The only elements out of the stack from one end of the linear form, and the other end sealed. And to follow the principle of "first in, last out", that is advanced after the element stack the stack.

  Queues: queue elements can only enter from one end of the linear form, brought out from the other, and to follow the "first in, last out" characteristics, i.e., queue elements are also advanced the first queue.

=== ===== tree storage structure

  Tree storage structure adapted to store data having a relation "one to many."

===== === FIG storage structure

  FIG storage structure adapted to store data having a relationship of "many to many."

=== algorithm time complexity and space complexity ===

  Algorithm, to solve the problem. The same question, using different algorithms, although get the same results, but it takes time and resources are different.

  Algorithm requirements:

    Accuracy: you must be able to solve this problem.

    Robustness: Ben can not collapse under any circumstances.

    Efficiency: time complexity and space. [Required by the algorithm run time and memory space to run the algorithm. ]

Sort ==== time complexity: O (1) <O (logN) <O (n) <O (n side) <O (N-th power of 2, the order index)

==== Detailed ===== linear form

 Linear tables: a data structure stored in one of the simplest structure, specifically designed to store a logical relationship: one data.

  Linear table, based on data stored in the actual state of the physical space, and can be subdivided into the order list table.

  The success of data stored or not, depending on whether data integrity can be restored to its original look.

  Having a "one to one" relationship data is linearly stored in the physical space, this storage structure is called a linear memory structure.

  Using a linear table storage structure, so as to store the data array, the data type requirements must be consistent.

=== === predecessor and successor

  In the data structure, a set of data is referred to each individual: a data element.

  The left side of an element adjacent elements known as: immediate predecessor, on the left all the elements of this element are collectively referred to as: the precursor elements.

  The right of an element adjacent elements known as: direct successor, located to the right of this element are all elements collectively referred to as: the successor element.

=== === initialization sequence table

  Before using sequence table storage data, in addition to the physical space of sufficient size to apply the outside, in order to facilitate later use the data in the table, the order table also requires real time recording both of the following data:
  the storage capacity of the order of 1 meter application.

  2. The length of the sequence table, i.e. the number of data elements stored in the table.

== So, we need to customize the order of the table, C language codes are as follows:

  typedef struct Table {

    int * head: // declare an array of indefinite length named head, also known as: dynamic arrays.

    int length; // record the current length of the sequence table

    int size; // allocation order table storage capacity of the recording

  }table;

Note: head dynamic array is an uninitialized our declaration.

==== === establish a sequence table

  1. The dynamic data to the head of sufficient magnitude to apply the physical space;

  2. The size and length assigned to the initial value;

=== === Sample Code

  #define Size 5 // size of the macro is defined, the size of the table represents the order of the application space

  table initTable() {

    table t;

    t.head = (int*) malloc();

  }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

  

 

 

 

 

 

 

 

 

 

 

 

 

    

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

  

  

Guess you like

Origin www.cnblogs.com/dagailun/p/12361683.html