Data structures and algorithms-Learning Note 1

Source: Internet
Author: User

What is a data structure?

Data structure is a subject that studies the problem of programming in non-numerical computing, and the related problems such as the relation and operation between them.

Program Design = data structure + algorithm (simply said is the relationship, the data elements exist between one or more of the specific relationship of the collection)

The data structure is divided into logical structure and physical structure

Logical Structure ( set structure, linear structure, tree structure, graphic structure )

The interrelationship between data elements in a data object

Collection agencies

Elements in a collection structure are not related to each other except for the same collection

650) this.width=650; "title=" 11.jpg "src=" http://s3.51cto.com/wyfs02/M01/54/9D/wKiom1SHwtjhRMItAACbLPS48cE440.jpg "alt=" Wkiom1shwtjhrmitaacblps48ce440.jpg "/>

Linear structure

The relationship between data elements in a linear structure

650) this.width=650; "title=" 11.jpg "src=" http://s3.51cto.com/wyfs02/M02/54/9D/wKiom1SHw-2Qt3ieAABJsy-18cM955.jpg "alt=" Wkiom1shw-2qt3ieaabjsy-18cm955.jpg "/>

Tree-shaped structure

A one-to-many hierarchical relationship exists between data elements in a tree structure

650) this.width=650; "title=" 11.jpg "src=" http://s3.51cto.com/wyfs02/M02/54/9D/wKiom1SHxNiy9XJKAAC18ZPvnks819.jpg "alt=" Wkiom1shxniy9xjkaac18zpvnks819.jpg "/>

Graphic structure

The data element is a many-to-many relationship

650) this.width=650; "title=" 11.jpg "src=" http://s3.51cto.com/wyfs02/M00/54/9D/wKiom1SHxYfRUc0MAACvlNS2Id8137.jpg "alt=" Wkiom1shxyfruc0maacvlns2id8137.jpg "/>

Physical structure (sequential storage,)

The storage form of logical structure of data in computer

Sequential storage

is to store data elements in contiguous storage units, and the logical and physical relationships between the data are consistent.

Chain-Store (flexible)

is to store data elements in arbitrary storage units, which can be contiguous or discontinuous.

Algorithm

First look at a primary school problem "figure out 1 plus to 100, and result 5050"

Analysis: This problem with the finger count is definitely not, see the law: 1+100=101,2+99=101 .... Do you see the law?

50*101 the final result.

So what do we do with the program language output?

int sum =0,n = 100;

for (int i=1;i<=n;i++)

{

Sum =sum+i;

}

cout<<sum<<endl;//to Loop 100 times

Gaussian algorithm

int i,sum=0,n=100;

sum = (1+n) *N/2;

cout<<sum<<endl; Execute only once

What is an algorithm?

A description of the solution steps for a specific problem, represented as a finite sequence of instructions in the computer, and each instruction represents one or more operations

Five basic features

Input, output, poor, deterministic and feasible

Input

Algorithm Local area 0 or more inputs

void Test ()

{

cout<< "Hello" <<endl

}//No parameters Required

Output

The algorithm has at least one or more outputs, which can be either printout or return a value or multiple values, etc.

have poor sex

The algorithm automatically ends without an infinite loop after performing a limited number of steps, and each step is completed within an acceptable time

Certainty

Each step of the algorithm has a definite meaning and does not appear ambiguity

Algorithm under certain conditions, there is only one execution path, want to pass the input can only have a unique output results

Each step of the algorithm should be precisely defined

Feasibility

Every step of the algorithm must be feasible.

Algorithm Design Requirements

Correctness: The algorithm should at least have input, output and processing, can correctly reflect the needs of the problem, can get the correct answer to the problem.

Readability: Easy to read, understand and communicate

High time efficiency and low storage (e.g. just Gaussian algorithm)

Data structures and algorithms-Learning note 1

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.