Take you to understand learning data structures and algorithms (speaking human version)

1. Data structure

1.1. Basic concepts

The data structure is a collection of data and the relationship between the data. It is the way the computer stores and organizes the data. It is like different boxes for storing things. Different things are packed in different boxes, which will play a role. The effect of getting twice the result with half the effort,

1.2 Classification of data structures

According to the logical structure, it is divided into: collection, linear, tree, graph,

Logical structure: The connection between data and data is called the logical structure of data

 Set structure: the data are all placed in the same place, there is no connection between them, just like you go to a bus, the passengers in the bus are a set

Linear structure: There is a one-to-one relationship between the data in this structure, just like queuing up to make nucleic acids, one to one, there is a sequential relationship between them

Tree structure: The data in this structure has a one-to-many relationship, just like a teacher in a school, a teacher teaches a class of students

Graphical structure: The data in this structure has a many-to-many relationship, just like a person can have multiple identities, and one identity can be owned by multiple people at the same time

1.3 Classification of physical structure

According to the physical structure, it is divided into: sequential storage structure, link storage structure, data index storage structure, data hash storage structure (hash)

Physical structure: the logical structure of data stored in the computer is called the physical structure of data

A--sequential storage structure: when stored on the computer, it is a continuous memory space to store each data element put in

 Advantages: Random access is possible, only the address of the memory is known

Insufficient: insertion and deletion are inefficient and the size is fixed

Representative: array

B--linked storage structure: when stored on the computer, the positions of each placed element are adjacent to each other in the memory and also adjacent to each other

 Advantages: dynamic expansion of size, high insertion and deletion efficiency

Disadvantages: Random access, low query efficiency, easy to cause fragmentation, not very friendly to memory management

Representative: linked list

C--Data index storage structure: As the name suggests, it is to give an index, and you use the index to place it at the position indicated by the corresponding index. For example, when you go to the library to find a book, you will be given a search card for the book (on which layer or which level? indivual).

 This picture is a sparse index (that is, a group of nodes corresponds to a search code item in the index table) otherwise it is a dense index

Pros: fast retrieval

Disadvantages: Because redundant index tables will be added, it will take up more storage space

D--data hash storage structure (hash storage): convert data to another value through a function, this value is the address value of this data on the computer, this function is a hash function, and the place where the converted data is placed is a list

Advantages: This is similar to an array, but the query speed is faster than an array

Insufficient: random access, not easy to search sequentially

2. Common data structures

2.1 Collection structure

Set ,Hashset  TreeSet

2.2 Linear structure

Arrays, Stacks (FIFO), Queues (FIFO), Strings and Lists

2.3 Tree structure

1. What is a tree?

It is composed of one or more nodes, and there will be a data structure in the form of a root node

A: is the root node

B, C, D: are child nodes of A, but they are sibling nodes, and there are no child nodes under BCD, which can also be called leaf nodes

2. What is a binary tree?

That is, the degree of each node in the tree does not exceed 2, (that is, each has two children)

 Full binary tree (both sides are full)

 Complete binary tree (satisfies: 1. Except for the last layer, the other is a full binary tree, 2. The nodes in the last layer are distributed from left to right in turn)

 Unsafe Binary Tree (Nothing)

 Red-black tree:

Features: 1. The root node is black 2. The leaf nodes are black 3. The one next to the red must be black 4. The black of the line on both sides starting from the root node is the same

The red-black tree also belongs to the binary tree, which ensures balance by rotating and changing colors

Representative: the bottom layer of TreeSet and TreeMap in java

3. B tree and B + tree

The B tree is a multi-fork tree (to avoid too high a tree level, causing disk IO, frequent read and write), and a balanced tree.

Features: 1. Each node has more than 2 stores

           2. The data is stored on the node, and the data will not be stored repeatedly

           3. The B-tree is relatively short, the fewer IO times, the better the search performance

The B+ tree is an enhanced version of the B tree. Only addresses are recorded on internal nodes and data is stored on leaf nodes. The leaf nodes have a doubly linked list, which connects the leaf nodes. The query efficiency is relatively high, and the height of the tree is only 3 layers

Representative: mysql uses B+ tree

3. Algorithms

3.1 What is the algorithm?

It is a step to solve the problem. Generally, it can be used to optimize the efficiency of our interface. For example, after fewer steps, the return efficiency will be correspondingly higher.

3.2 Algorithm complexity

Saying how an algorithm is based on time complexity and space complexity

Time complexity : including time frequency, constant order O(1), logarithmic order O(log2n), linear order O(n). . . wait

Space complexity : It is a measure of the size of the storage space temporarily occupied by the algorithm during the running process 

For example: the cache we know is space for time

3.3 Common Algorithms

A--Hash algorithm : You give me data of any length, and I convert it to a fixed length through a hash algorithm (but it may appear that the converted values ​​are consistent and produce hash collisions)

For example: MD5 SHA-1, etc.

B--Recursion : It is to call itself, and when a condition is reached, it will jump out of this loop, otherwise it will continue to call

Note: Be sure to give an exit, otherwise your computer will be GG

C--Sorting: There are various sorting methods as follows

 Below I am talking about sorting in java:

Keyword: Arrays.sort (element <47, use insertion sort, element <286 use quick sort)

Keyword: Arrars.aslist (sort in ascending order according to natural order)

The actual time in java is only the use of some functions, and the method is called to solve it.

For a detailed and in-depth study of the 10 classic algorithms, take a look at the following articles

https://www.runoob.com/w3cnote/ten-sorting-algorithm.html

I only have a general understanding of the algorithm. This chapter is a shallow study and understanding of the algorithm. Of course, these are just the tip of the iceberg of the algorithm.

Welcome to study and exchange, please point out the shortcomings, if you like it, please like + bookmark, thank you guys

Guess you like

Origin blog.csdn.net/m0_67601895/article/details/125997907