Data structure learning Week1-1: What is a data structure?

  

The first question: books and find and insert placement

1, display: ① ② put casually put a sequence of characters

2. Find: ① ② find a a dichotomy

3, is inserted: according to the above methods are not OK, then we shelves into a few regions, each display region of some sort book, books placed by each sequence of characters, each operation by bipartite look subclasses

4, how to classify it that?

 

1 concluded:

Efficiency of the process to solve the problem, with the organization of the relevant data

 

The second problem: Print all positive integers of 1 ~ n

1, cycle implementation:

2, recursive:

#include <bits/stdc++.h>
using namespace std;
void Printn(int n)
{
    if(n)
    {
       Printn(n-1);
       printf("%d ",n);
    }
}
int main()
{
    int n;
    scanf("%d",&n);
   //法一:直接法
   for(int i=1;i<=n;i++)
    printf("%d ",i);
   puts("");

   //法二:递归调用
   Printn(n);
   
return 0;
}

 

After each running two tags: When n = 10 \ 100 \ 10000 okay, but when n = 100000; recursive direct explode

 

n=100000;
//直接法
99952 99953 99954 99955 99956 99957 99958 99959 99960 99961 99962 99963 99964 99965 99966 99967 99968 99969 99970 99971 99972 99973 99974 99975 99976 99977 99978 99979 99980 99981 99982 99983 99984 99985 99986 99987 99988 99989 99990 99991 99992 99993 99994 99995 99996 99997 99998 99999 100000

Process returned 0 (0x0)   execution time : 23.423 s
Press any key to continue.

//递归法

Process returned -1073741571 (0xC00000FD)   execution time : 8.180 s
Press any key to continue.

2 concluded:

Efficiency of the process to solve the problem, with the utilization of space-related

 

The third question: Write a program to calculate the value of a given point at a polynomial in x;f(x)=a_{0}+a_{1}x+.....+a_{n-1}x^{n-1}+a_{n}x^{n}

1, directly translated meaning of the questions (will be despised ....)

2, Qin Jiuzhaof(x)=a_{0}+x(a_{1}+x(.....(a_{n-1}+x(a_{n}))....))

 

double f1( int n,double a[],double x)
{

    double p=a[0];
    for(int i=1;i<=n;i++)
        p+=(a[i]*pow(x,i));
    return p;
}


double f2( int n,double a[],double x)
{
    double p=a[n];
    for(int i=n;i>0;i--)
        p=a[i-1]+x*p;
    return p;

}

() Is calculated by the clock time

Template below

//clock()模板
#include <bits/stdc++.h>
#include <time.h>
using namespace std;

clock_t  start ,stop;//clock_t是变量类型
double duration;
void Myfunction();

int main()
{
    start=clock();
    Myfunction();
    stop=clock();
    duration=((double)(stop-start))/CLK_TCK;

return 0;
}

 

f1 f2 slower than an order of magnitude

3 concluded:

The efficiency of problem-solving approach, with clever algorithms related degree;

 

 

What is a data structure? ? ?

A data object in a computer in the organization:

   1, the logical structure:

     ① linear structure (one)

     ② tree (one to many)

   2, the physical storage structure

Second, abstract data types:

   1, the data type:

        ① set of data objects

        ②, data collection set of operations associated with: books close connection with the placing and operating together.

   2, Abstract: Description of data types not rely on specific implementation. ( Only describe what type of data is not including what to do )

Third, a "matrix" of abstract data type definitions

Abstract: that is the equivalent of the frame.

Abstract benefits: ① improve the reusability of code, easy to replace the data type

 

Published 32 original articles · won praise 1 · views 1323

Guess you like

Origin blog.csdn.net/QXK_Jack/article/details/104355292