Data Structures and Algorithms (a) the logical structure, physical structure, time complexity

data structure


Data structure is the operation target programming problems a study in non-numerical calculation, and the subject-related issues and the relationship between the operation thereof.

Why study the data structure?
Learning data structure is the ability to learn logical thinking and abstract thinking. Programming Algorithms + data structures =, and the underlying source development is inseparable from the data structure. Want to learn more in-depth study is necessary data structures.

What is a data structure?
Data structures: is the presence of one or more data elements of the particular relationship between each set.


The logical structure and physical structure of the data structure

Logical structure data structure refers to the relationship between data elements, the logical structure is divided into the following four:

  • A set of configuration: a data structure in addition to the set belonging to a same set, no other relations between them
  • Linear Structure: linear structure between data elements is a one to one relationship
  • Tree: the presence of many hierarchical relationship of data between elements in the tree structure
  • Graph structure: graphical data element structure is many to many - relationship

The physical structure of a data structure of the storage means in the form of a logical structure in the computer

  • Sequential storage structure; open a set of contiguous space to store data, typically implemented using an array, the array is a continuous space itself, to ensure that the relationship between the data
  • Storage Structure: opens a random set of space to store data, usually node to achieve, not only the position of the nodes to store data, but also store the next node to ensure that the relationships between data

We want the most appropriate data structure in accordance with the flexibility to choose different scenarios


algorithm

Describe a specific algorithm to solve the problem solving, the ordered sequence of instructions in a computer, and each step represents one or more instruction operations, it is to solve a problem.

How to evaluate the quality of an algorithm?

Later statistical methods : by designing good programs and data, using a computer running time for the timer program compares different algorithms to determine the level of efficiency of the algorithm

Prior analysis estimation method : in front of computer programming, according to the statistical method of estimation algorithm, a program running on a computer, the time consumed depends on the following factors:

  • Strategies and methods used by the algorithm
  • The quality of the code generated by the compiler
  • Enter the scale of the problem
  • Instruction execution speed of the machine to perform

time complexity

Time complexity, known as time complexity, time complexity of the algorithm is a function that describes qualitatively the running time of the algorithm.

During the algorithm, the statement of the total number of executions T (n) is a function of n is the problem size, and then analyze T (n) with the change of n and determine the order of magnitude, the algorithm time complexity T (n), which is the time metric, denoted by: T (n) = O (f (n)). N represents a problem which increases with the size, execution time of the algorithm is the same growth rates and f (n) growth, called progressive time complexity of the algorithm, referred to as time complexity. Where f (n) is a function of problem size n. T (n) is a specific number, O (n) is not performed a specified number, to see growth.

Several common time complexity

  • Constant order O (1) no circulating

  • Circulation of the order O (logn), acceleration decrease the acceleration

  • Linear order O (n) cycle where

  • nlogn order O (nlog n) in the binary tree by

  • Squared order O (n ^ 2)

  • The cubic order O (n ^ 3)

  • Exponential order O (2 ^ n)

    Time complexity increases from top to bottom

We consider the time complexity is the worst case

Published 70 original articles · won praise 56 · views 1989

Guess you like

Origin blog.csdn.net/qq_43624033/article/details/103517847