[Soft test software designer] [] [] [Knowledge Module Chapter 3: Data Structure]

Chapter 3: Data Structure:

 

Data structure is an important foundation for program design

Learn the purpose of the data structure:

  Learn from the nature of the data, analyze and study computer processing,

  Logic to select the appropriate configuration, the storage structure and method of operation data corresponding application involved;

  [For a data structure, consider three factors: the logical structure of the storage structure, operation method (operation method)]

  In order to improve the efficiency of the use of computers to solve the problem of service;

 

  Data structure refers to: the relationship between the collection and the method of construction elements and data elements.

    The relationship between the elements: the logical structure of the data

    Storing the relationship between elements: storage structure (or physical structure referred to)

    

  Data structures Category:

    Linear structure

    Nonlinear structure

      It is divided into a tree structure, the structure of FIG;

  

  Data structure is the basis for algorithm design.

 

  Linear structure: linear structure mainly used for the objective world has a single predecessor and successor data relationships described.

    Linear table

      According to storage Category:

        Sequential storing: a group of data elements with consecutive addresses stored in the storage unit sequentially stores the linear table,

          Phenomenon: two adjacent logic elements, also adjacent physical locations.

          Advantage: a random access elements in the table, i.e., random access to data.

          Cons: insertions and deletions need to move other elements; (the amount of movement sometimes big)

          Features:

            Space of each node should require pre-allocated, whether or not there is follow-up data, this space will not change, delete guidance until the entire data structure.

        

        Using chain store: linked by a pointer with the node to store data elements;

          Basic structure: a data source and the target domain; and each node has two;

            Data field to store values ​​of data elements;

            Direct precursor pointer field current element location information is stored or immediately subsequent. Pointer to domain information is referred to (or chain)

          Features: the storage node of each element does not require a physical address is continuous.

            While storage elements must be stored logic elements.

            Junction space will only be required when the application filed, without prior distribution.

            Head requires a head pointer, points to the first node, the order can have access to any element of a table.

            Linear chain storage table, if necessary inserted or deleted, but the actual pointer for the modification, there is no data field to make the necessary modifications.

            In practice, in order to simplify processing and determination of the status list, in particular the introduction of an element of the data storage node, the first node is called, as the first node of the linked list head pointer to the node to make .

          Disadvantages: not random access to data elements

          A little: insert and delete operations without moving elements.

          Find a singly linked list, insert, delete operations, refer to P102

          

          Several other chain storage structure:

            Doubly linked list: each node contains two pointers, a direct precursor, it is a direct successor.

              Features: arbitrary node from the table, to traverse the entire list.

            Circular list: On the basis of the one-way linked list (or a doubly linked list) on the end of the table so that the pointer points to the first node in the node list, constituting a circular list.

              Features: You can start from any node to traverse the entire list.

            Static lists: an array will be described by means of a linear chain structure of a table stored with the subscript of the array elements to represent the node where the pointer element.

          

      The basic operation of the linear form: insert, delete, search;

        

 

 

  Stacks and queues

    Linear form and the same logical structure;

    Features: operational restrictions;

      Stack: the advanced nature of the LIFO

      Queue: last-out FIFO

 

 

    Stack:

      It can be achieved only of a linear data storage and retrieval by accessing the data structure at one end.

      Top of the stack: Insert one end and be deleted

      Bottom of the stack: the stack corresponding to the other end

      Empty stack: the stack containing no data elements

      Stack operations:

        Initialize the stack InitStack (S): Create an empty stack

        Judgment empty stack isEmpty (S): When the stack is empty, it returns "true", otherwise "false"

        Stack Push (S, x): x added to the top of the stack element, and updates the stack pointer.

        Pop Pop (S): The top of the stack element from the stack, and the stack pointer is updated.

          If a value needs to be top of the stack, it may be Pop (S) is defined as a return value of the function element stack.

        Top (S): Returns the value of the top element, but does not modify the stack pointer.

      doubt:

      Number of elements in the stack by stack pointer defined it? Element types in the stack is a specification defined how?

      Initialize the stack, the stack will define the space.

    

      Stack storage structure:

        Sequential storage

          A group of consecutive addresses stored in the storage unit sequentially stores the data elements from the stack to the bottom of the stack.

          Indicating the top position of the top element is provided pointer.

          Requires a predefined storage space (or application) stack,

        The chain storage (link stack)

          A linked list as a stack memory structure

          Do not set the head pointer list, the stack pointer is the head pointer list.

        Stack of applications

          Typical applications: expression evaluation, matching bracket;

          In the implementation of computer languages, will use the stack.

          The recursive procedure into a non-recursive process of processing, the stack will have important applications.

        

    queue:

      A linear FIFO table;

      FIFO First In First Out;

      characteristic:

        Inserted only at one end of the element, deleting an element in the other end.

        Element allows the insertion end, called the tail (Rear).

        Delete allows the end element, called the head (Front).

        Have a head and the tail pointer. (HOL pointer front, the tail pointer REAR;)

      The basic operation of the queue:

        Queue initialization InitQueue (Q): Create an empty queue Q;

        Analyzing empty isEmpty (Q): When the queue is empty, returns a "true", otherwise "false."

        Enqueue EnQueue (Q, x): x is added to the queue Q element of the tail, and the tail pointer is updated.

        The team DelQueue (Q): header element will be removed from the queue Q and updates the head pointer.

        Read head elements FrontQue (Q): Returns the value of the head elements, without updating the head pointer.

        Queue storage structure:

          Sequential storage structure :( sequentially with other data structures)

 

            To reduce computational complexity, only the modified elements enqueue queue tail pointer; Elemental dequeued only modify head pointer.

              However, since the storage capacity of the queues are set in advance, so that the tail pointer will have an upper limit, when the tail pointer reaches the upper limit, it can not only modify the tail pointer of the element increases.

            Circular queue :( divisible achieved by modulo arithmetic.)

              Maintaining a simple arithmetic operation can enqueue dequeue.

              According to the definition of the operation queue, when Q.rear == Q.front, namely the head pointer and the tail pointer are equal, the queue may be empty or may queue is full, this situation is obviously a problem.

                Two outcomes: 1, set a flag when this occurs, as representatives of the queue is empty or full;

                       2, a sacrificial storage unit convention: the next location of the queue tail pointer position indicates that the queue is full when the queue head pointer. (A question that comes to mind, if the queue length is 1, then the queue is not never insert elements?)

          Chain store queue queue :( chain)

            For ease of operation, the queue chain is added to a header node, and to make the head pointer to the head node.

            Queue is empty determination condition is: the same value of the head and tail pointers, and all point to the head node.

        Queue of applications:

          Commonly used in the treatment occasions to wait in line, such as a print job, the computer simulation of discrete events

 

      

    string:

      String, is a special linear form;

      Whose elements are characters.

      In operation, when a string is often viewed as a whole to be processed.

    

      String, consisting of only the priority sequence of characters;

      String of several concepts:  

        Empty string: string length of 0;

        Space string: string consists of one or more spaces.

        Substring: sequence composed of a continuous string of arbitrary length

          

 

        Main string: string containing substrings           

          Substring in the position of the main string, substring refers to when the first time, the first character of substring position in the main string.

          Empty string is an arbitrary string of sub-string.

        The string is equal to: two strings of equal length, and the number corresponding to the character are equal;

        String comparison: Comparison of two character string of a first operation from the start, a character string code value is greater where large, comparing the ASCII value of the character code;

      Basic Operation string:

        Assignment StrAssign (s, t): the value assigned to string the string s t.

        Connecting operation Concat (s, t): j t the series connection at the end of the string s to form a new string;

        Seeking string length StrLength (s): returns the length of the string s;

        String comparison StrCompare (s, t): comparing two strings.

          Return value -1, 0, respectively s <t, s = t, s> t;

        Qiuzi string SubString (s, strat, len): Returns the string s starting from the start for len character sequence.

      String storage structure:

        Sequential storage structure: a set of successive addresses of the storage unit to store a sequence of characters of string values;

          Since the string is composed of characters, may be defined character string memory array provided by the programming language,

          It may also be dynamically according to the application space string string length needs.

        Storage Structure: list stored string characters.

          Each node can be stored in a character, a plurality of characters may be stored.

          Considering the problems storage density, the size of the selected node will directly affect the efficiency of the process string.

      String pattern matching: positioning operation substring

        Substring also known pattern string;

        Simple pattern matching algorithm: bruit - Fox algorithm;

        Improved pattern matching algorithm: KMP algorithm;

 

      

    Arrays, matrices and generalized table:

      Array, generalized list can be seen as the promotion of the linear form.

        Data element is still a table;

      

      Array: given extension of the long dimension of the table.

        Linear elements in the table is a linear table.

        n-dimensional array is a "homogeneous" data structure, each data element of the same type, consistent with the structure.

        Array structure features:

          A fixed number of elements, an array is defined, the number of its elements is fixed.

          Elements of the same type.

          Relationship constraint index having upper and lower bounds, and the subscript ordered;

        An array of basic operations:

          Given an index, to access the corresponding data element.

          Given an index, modifying a data item value of the corresponding data elements.

 

        Sequential storage array:

          Arrays generally do not insert and delete operations, once the definition of the array, the relationship between the number of elements in the data structure and the element is no longer subject to change, and therefore suitable for sequential storage array structure.

        

 

 

      matrix:

        Data structure, the main concern is: how to make a variety of matrix operations in a case where saving storage space can be efficiently performed.

          Compressed storage: in some matrix, there are many elements of the same value or 0 elements, in order to save storage space, it can be compressed to such memory matrix.

            A plurality of the same element value is assigned only one memory cell, the memory cell 0 is not allocated.

          Special Matrix: Distribution of the same element (or elements 0) values ​​in the matrix have a certain regularity

          Sparse matrix: the matrix is ​​relatively specific, irregular distribution;

        

      General List: promotion of the linear form;

        Table generalized linear form and the difference between:

          Generalized table element can be either a single element, there may be a table structure.

          Elements are non-linear form of the single element of the sub-structure.

        Generally referred to as generalized list:     

 

        

 

        

        Generalized list of attributes:

          Generalized number of elements in the table: Table length generalized

          The maximum number of layers contained in parentheses after the general list expansion: generalized table depth.

        

        The basic operation of the generalized table:

          Take header: head (LS): the first element is non-empty generalized table header;

          Take footer: tail (LS): non-empty generalized table, in addition to the header, the table is referred to by other elements footer.

          

 

 

  

 

  

 

          

 

 


      [##### on some of the characteristics of, and then add it follow, reference books P #####]

    

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

-------- (I am dividing line) --------

reference:

1. "Software Designers Guide" (fifth edition, Tsinghua University Press, Chu Hua, Huoqiu Yan editor)

2. SEOUL school: www.ccidedu.com (teaching video resources)

3. River learning online buy US group: www.eimhe.com (teaching video source)

4.  

 

 

Remarks:

Initial modified: October 30, 2019 15:31:32

Environment: Windows 7 / Python 3.7.2 

Guess you like

Origin www.cnblogs.com/kaixin2018/p/11767093.html