Technology Sharing

Data Structure (Part 1) - Basic Knowledge

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Table of contents

1. Three elements of data structure

1.1 Data structure operations

1.2 Data structure storage structure

2. Data types, abstract data types

3. Algorithm

3.1 Time complexity T(n)

3.2 Space Complexity


1. Three elements of data structure

1.1 Data structure operations

That is, add, delete, modify and check

1.2 Data structure storage structure

2. Data types, abstract data types

type of data:

(1). Atomic types: bool, int...

(2). Structural type: class, structure...

Abstract Data Type (ADT):

Similar to structural types, usersOnlyNeed to know the data structurenameand the connections between their data (function)

3. Algorithm

3.1 Time complexity T(n)

The smaller the time complexity, the better the algorithm

(1) Operational regulations

addition:

Multiple additionWhen , only the highest order terms (powers) are retained

T1(n) + T2(m) = T(max(n,m))

multiplication:

T1 x T2 = O( f(n) x g(n) )

(2) Common order of magnitude comparisons

Generally, it is enough to remember the first three and the last three -Often the power index 

3.2 Space Complexity

1GB = 1024*1024*1024 bytes is about 1 billion

1GB=1024MB 1MB=1024KB 1KB=1024 bytes

In fact, there is no need to know the number of bytes required to store various data types. Just store them in numbers. After all, in the end, the coefficients will be omitted and the result will be a calculation formula containing n with a coefficient of 1.

In the function, asparameterThe incoming dataNo needare counted as part of the space complexity because the number of these parameters is known and can be omitted (except for recursive functions)

In the function, what needs to be calculated areIn the function, the declaration producesVariables.

special:

In the recursive function, each time the data is passed in,Will not coverIn its original location, it is stored inNew addressTherefore, to calculate the space complexity of a recursive function, we need to know the memory usage of the entire recursive process from the starting point to the end point.

When it comes to recursive functions on arrays, especiallyArraysoflengthOccurs with recursionChange, then you often need to useSum of Arithmetic Sequence