Introduction to Data Structures and Algorithms (a)

1. Definitions: programming data structure is a problem in the study of non-numerical calculation, the relationship between them and the operation target and the operation subject. Is simply relationship, each data element is set, or the presence of a variety of specific relationship between.
Category 2: logical and physical structures :
logical structure: the relationship between the data elements in the data objects.
Physical structure: storage means in the form of a logical structure of data in a computer.
Classification logic structure:
A) a set of structure: set of data elements belong to the same structure except that one set, no other relations between them.
b) linear structure: linear structure between data elements one to one relationship.
c) tree structure: many relationship exists between the level of the tree structure of the elements.
d) a graph structure: pattern element data structure is a many to many relationship.
Physical structure:
according to the definition of the physical structure, how the data is actually stored in the memory element of the computer. Mainly in terms of memory for memory.
Data storage structure has two elements: sequential storage structure and chain storage structure.
Sequential storage structure:
data elements stored in consecutive addresses in the memory cell, and the logical relationships between the physical relationship which is the same data, just as the array used in programming.
Storage Structure:
in practice, due to the sequential structure more rigid structure, not flexible. Storage Structure selected, the data elements are stored at any storage unit, the group of memory cells which may be continuous or may be discontinuous. Since the element is stored is arbitrary, it does not reflect the structure of the chain stored logic, then you need a pointer address used to store data elements, so that you can be found by the associated data element position address.
Algorithm is introduced:
First look at, and by using a loop for the direct calculation of the time-consuming:

DateTime now = DateTime.Now;      
            int a = 0;
            string Time = now.ToString("yyyy-MM-dd HH:mm:ss");
            double span1 =now.Second*1000 + now.Millisecond;
            for (int i = 0; i < 500000000; i++)
            {
                a = a + 1;
            }
            DateTime now1 = DateTime.Now;
            double span2= now1.Second * 1000 + now1.Millisecond;
            Console.WriteLine("使用for连加所用时间{0},所计算结果为{1}",span2-span1,a);
            DateTime now2 = DateTime.Now;
            double b = 0;
            b = 100000*5000;
            DateTime now3 = DateTime.Now;
            double span3 = now2.Second * 1000 + now2.Millisecond;
            double span4 = now3.Second * 1000 + now3.Millisecond;
            Console.WriteLine("直接计算所用时间{0},所计算结果为{1}",span4 -span3,b);

Here Insert Picture Description
Achieve the same results using different methods they use different time, different resources consumed.
Describe a specific algorithm to solve the problem solving step, a finite sequence of instructions represented in a computer, each instruction represents one or more operations. Different problems require different algorithms, the best algorithm is not only the most suitable.
Algorithm five basic characteristics: the input (with zero or more inputs), output (output at least one or more), of the finite (limited algorithm after performing steps to end automatically without infinite loop, needs to be done within a limited period), uncertainty (each step algorithm has determined the meaning, only one execution path under certain conditions), feasibility (every step must be feasible algorithm to be limited time period is completed).
Algorithm design requirements:
the algorithm is not unique, the same question can have multiple algorithms:
1. correctness : an input, output, can get the right answer. There are the following four levels:
A) algorithm program no syntax errors;.
B) algorithm procedure can be legally imported to give an output to meet the requirements;.
C) algorithm for illegal input structure description can be given to meet specifications;.
D). for other ornery test input output requirements are satisfied;
2. readability : can facilitate other developers to understand and modify;
3. robustness : when the input data is not valid, the algorithm can also make correlation processing, Ben collapse rather than an exception.
4. The high efficiency and low storage time : good algorithm needs to have high efficiency and low time storage characteristics.

Guess you like

Origin blog.csdn.net/DOUBLE121PIG/article/details/94438274