c ++ data structures 01 notes

The origin of the data structure

       The computer calculates from solving numerical problems to solve life's problems

       Real life problems involving complex relationships between different individuals

       Life contact between individuals need to be described in a computer program

       The main data structure relationship between the objects they operate in non-numerical procedures and

       Not the study of complex algorithms

 

The basic concept data structure

       Data - Operating target program, used to describe objective things

       Data features:

              You can be entered into the computer

              The computer program may be processed

       Data is an abstract concept, which is obtained after classifying the type of programming language. Such as: int, float ......

       Data elements: the basic unit of data consisting of

       Data items: a plurality of data elements from the data items

       Data objects - the same properties as the set of data elements (for example: arrays, linked lists)

       Are not independent, there is a specific relationship between the data elements, i.e., the relationship between these structures

       It refers to the relationship between the data structure of the data object data element

       Data Structure: Relationship

              The relationship between the node and the node (arrays, linked lists, trees, graphs)

 

The logical structure of the data

It refers to the logical relationships between data elements. I.e., from a logic description data, which is independent of storing data, it is independent of the computer. Logical structure can be subdivided into four categories:

       (Set) between data elements other ---- "belong to a set of" outside, no other relations

       ---- one a linear structure, such as a linear table, stack, queue

       ---- one pair of the plurality of tree structures, such as trees

       FIG plurality ---- structure of a plurality of, as shown in

The physical structure of the data

       Also known as the physical structure of storage structures, logical structure data representation (or image) within a computer memory. It relies on computer

       Storage structure can be divided into four categories: sequential, chain, indexing, hashing

              The most commonly used storage structure:

              ---- sequential storage structure by means of the relative position of an element in memory to represent logical relationships among data elements

              Storage Structure ---- element storage address indicated by the pointer indicates the logical relationships between data elements

       And is closely related to the logical structure of the data storage structure

              Algorithm Design Logical Structure à

              À algorithm storage structure

Data operations

       Operation defined in the logical structure data, which is implemented on the data storage structure

       The most common data operations there are five:

              Insert, delete, modify, search, sort

 

 

The concept algorithm

Algorithm is a description of the specific problem-solving steps

In the performance of the computer as a finite sequence of instructions

Algorithm is independent of the presence of a problem-solving methods and ideas

For the algorithm, language is not important, important is the idea

The difference between algorithms and data structures

       Only static data structure describes the relationship between data elements

       Efficient procedures need to design and selection algorithms on the basis of the data structure

       Algorithms + data structures = programs

to sum up:

       Algorithm to solve practical problems and design

       Data structure is a vector algorithm problems need to be addressed

       Data Structures and Algorithms complement each other

Algorithm properties

       Input: 0 or algorithm having a plurality of inputs

       Output: algorithm outputs at least one or more of

       There are poor: the algorithm automatically end after a limited step without infinite loop

       Uncertainty: Algorithms Each step has a definite meaning, does not appear ambiguous

       Feasibility: Each step of the algorithm are feasible

A measure of the efficiency of the algorithm

  1. Later statistics

Comparison of different algorithms running on the same set of input data processing time

              defect

                     In order to obtain a running time of different algorithms must write the corresponding program

                     Running time is heavily dependent on the hardware and environmental factors running time

                     Select the test data algorithm considerable difficulties

              Later statistics While intuitive, but difficult to implement and deficit

  1. Prior analysis estimates

An estimate of the efficiency of the algorithm based on statistical methods

The main factors that affect the efficiency of the algorithm

       Strategies and methods used by the algorithm

       Enter the scale of the problem

       Code compiler generated

       Computer execution speed

       When determining the efficiency of an algorithm, often only need to focus on operating the highest number of times a term, other minor items and the constant term can be ignored.

       In the absence of special note, the time complexity of the algorithm we analyzed it refers worst time complexity.

Big O notation

       Efficiency of the algorithm relies heavily on (Operation) Operation Number

       In determining the number of operating primarily concerned with the highest degree term

       Estimating the number of operations can be used as the estimated time complexity

      

       O (5) = O (1)

       O (2n + 1) = O (2n) = O (n)

  O (n 2 + n + 1) = O (n 2 )

  O (3n 3 + 1) = o (3n 3 ) = o (N 3 )

Common time complexity

The number of function execution

Rank

Informal term

12

O (1)

Constant Order

2n + 3

O (n)

Linear Order

3n 2 + 2n + 1

O (N 2 )

Order of the square

5log2n + 20

O (logn)

To order

2n + 3nlog 2 N + 19

O (nlogn)

nlogn order

6n 3 + 2n 2 + 3n + 4

O(n3)

Cubic order

2 N

O (2 N )

Index order

 General relationship:

O(1)< O(logn)< O(n)< O(nlogn)< O(n2)< O(n3)< O(2n)<O(n!)<O(nn) 

 

1  // this code is to run successfully at 17.12 CodeBlocks 
2 #include <the iostream>
 . 3  
. 4  the using  namespace STD;
 . 5  // time for space 
6  / * 
7      issues:
 8      in a natural number in a certain digit number 1-1000 array, each number may appear zero
 9      or more times. Design an algorithm to find the highest number of numbers appear
 10  * / 
. 11  
12 is  void Search ( int * A, int len);
 13 is  
14  int main ()
 15  {
 16      int ary [] = { . 1 , . 1 , 2 ,8,8,8,9,4,4,5,6,7,9,9,9,9};
17     Search(ary,sizeof(ary)/sizeof(*ary));
18     return 0;
19 }
20 
21 void Search(int *a, int len)
22 {
23     int sp[1000] = {0};
 24      int I = 0 ;
 25      int Max = 0 ;
 26 is  
27      // the values in the array assigned to another index minus 1, i.e., an array index 
28      for (I = 0 ; I <len; I ++ )
 29      {
 30          int index = a [I] - . 1 ;
 31 is          SP [index] ++;   // number of occurrence of each number calculated 
32      }
 33 is  
34 is      // find new array space within a maximum number of 
35      for (I = 0 ; I < 1000 ; I ++ )
 36      {
 37 [         IF (Max < SP [I])
 38 is          {
 39              Max = SP [I];
 40          }
 41 is      }
 42 is  
43 is      // output digital up the number of occurrences 
44 is      for (I = 0 ; I < 1000 ; I ++ )
 45      {
 46 is          IF (Max == SP [I])
 47          {
 48              // COUT << "digital largest number of occurrences of" Max << << endl; 
49              COUT << " most frequent number of times " << I + . 1 << endl;
50         }
51     }
52 }

 

Guess you like

Origin www.cnblogs.com/yang901112/p/11468673.html