Data Structure - Introduction Exercises

  • The data item is the smallest unit of data, the data element is a basic unit of data
  • Completed within the stipulated time is not the algorithm of the basic special new
  • Computer data processing generally have some kind of internal relations, which means that there is a relationship between elements and elements
  • An algorithm has correctness, readability, robustness, efficiency and storage capacity requirements
  • It refers to a logical structure data of the logical relationships among data elements of  the whole
  • Time complexity and scale of the problem related to
  • The time complexity of an algorithm is O (n- 2 ), the algorithm indicates a problem with the size of n- 2 is proportional to
  • In the data storage structure, a node typically stores a data element
  • When using the chain data storage structure, it requires each node occupies a contiguous memory area

 

  • It refers to a logical structure data between the data elements of logic whole
  • Data structures generally divided into four basic categories structure: collection, linear structure, a tree structure and a mesh structure
  • Sequentially stores images and non-sequential storage impression, give two different storage structure: the linear memory structure and Storage Structure
  • Linear structure, the first node without predecessor node, and each remaining node has only a
  • A predecessor node; terminal node no successor node, the remaining successor node of each node can have a plurality of
  • In FIG like structure, the precursor of nodes and the number of nodes of each subsequent node may have a plurality of
  • An algorithm has five characteristics: finite, certainty, feasibility, input and output
  • Algorithms each instruction must have a precise meaning, can not have ambiguity, the algorithm performance characteristics of uncertainty
  • Represents data in memory of a computer, two logically adjacent data elements corresponding to the physical address is contiguous, this storage configuration is called sequential storage structure
  • The purpose algorithm analysis is to identify the reasonableness of the data structure, the two main aspects of the analysis of algorithms is space complexity and time complexity
  • Data object is a collection of arbitrary data elements (×) data object is a collection of data elements having the same properties
  • Data object is limited by the same types of data elements constituting the (√)
  • Logical structure data with each data element in a computer to store information about how the (×)
  • Logical data structure is not the same, must use different types of storage (×)
  • It refers to a logical structure data of the logical relationship between each data item data (√)
  • Merits and algorithm description language independent of the algorithm, but with the relevant computer (×)
  • Algorithm program must (×)
  • Must ultimately be implemented by computer algorithm (×)
  • Robust algorithm does not inexplicable status since the emergence of illegal input data (√)

Analysis of time complexity of the following algorithm

void func(int n){
    int i, k = 110;
    while(i <= n){
        k++;
        i += 2;
    }  
}

O (n)

void fun(int n){
    int i = 1;
    while(i <= n){
        i = i*3;
    }
}

O(log3(n))

void fun(int n){
    int i, j, k;
    for(i = 1; i <= n; i++){
        for(j = 1; j < = n; j++){
            k = 1;
            while(k <= n){
                k = 5*k;
            }
        }
    }
}

O (n 2 log5 (n))

void func(int n){
    int i, j, k  = 0;
    for(i = 1;i < n; i++){
        for(j = i + 1; j <= n; j++){
             k++;
        }
    }
}

O (N 2 )

void fun(int n){
    int s = 0, i, j, k;
    for(i = 0; i <= n; i++){
        for(j = 0; j <= i; j++){
            for(k = 0; k < j; k++){
                s++;
            }
        }
    }      
}

O (N 3 )

void func(int n){
    int i = 0, s = 0;
    while(s <= n){
        i++;
        s = s + 1;
    }
}

O (n)

Let n is an even number, calculate the value of m is run after the following block, this block is given time complexity

int m = 0, i, j;
for(i = 1; i <= n; i++){
    for(j = 2*i; j <= n; j++){
         m++;
    }
}

O (N 2 )

int fact(int a[], int n, int x){
    int i = 0;
    while(i < n){
        if(a[i] == x){
            return i;
        }
        i++;
    }
    return -1;
}

O (n)

Hanoi algorithm design a problem: There are three columns a, b, c, there are n different disk radii middle hole, the n discs in the column a, a radius increasing from top to bottom

Requires all target disk moved the disk C, b may be used as an auxiliary column by column, you must obey the following rules when the movable disc:

  • A time can move a disc
  • Any large disk are not allowed in the column above the small disk

Analysis algorithm time complexity

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/YC-L/p/12168272.html