Preparation 1: socket + common algorithms + Common Data Structures

Source: Internet
Author: User

Socket:
1. Layer 7 from bottom up: physical layer, data link layer, network layer, transmission layer, Session Layer, presentation layer and application layer
2. IP protocol-network layer tcp protocol-Transport Layer http protocol (based on tcp links)-Application Layer
3. TCP/IP is the transport layer protocol, which solves the problem of how data is transmitted over the network. http encapsulates data.

4. tcp protocol, IP address + port encapsulated by socket

5. the socket connection process involves three steps: server listening, client request, and connection confirmation.

 

Algorithm:
1. Divide and conquer: divide a big problem that is difficult to solve directly into the same problems of small scale, and break through them individually.
Features: ① the problem can be easily solved by narrowing down to a certain extent.
② Decomposition into several smaller issues
③ Subproblem solutions can be combined into problem solutions (key)
④ Each sub-problem is independent of each other
2. Dynamic Planning Algorithm:

  

② No aftereffect is satisfied (the current status is irrelevant to the frontend and backend)
Step: initial status → │ Decision 1 │ → │ Decision 2 │ →... → │ Decision n │ → end status (optimal route)
① Division of stages (by time/space)
② Determine the status and variables (indicate the status of the problem that develops to different stages. Status selection must be ineffective)
③ Determine the decision and write the state transition equation
④ Finding the boundary condition: the state transition equation is a recursive equation and requires a recursive termination boundary condition.
Three elements: the status of the stage/stage of the problem/the recurrence relationship between phase Conversions
3. Greedy Algorithm: always makes the best choice for solving the problem.
Train of Thought: ① resume mathematical model to describe the problem
② Divide the problem into several subproblems
③ Find the optimal solution for each subproblem
④ Merge the subproblem into the original problem
It is worth noting that the greedy algorithm is not completely unusable. Once proven, the greedy policy is an efficient algorithm that relies on previous choices, however, it cannot be selected later.
Greedy algorithms are still one of the most common algorithms. This is because they are easy to implement and it is not very difficult to construct greedy policies. Unfortunately, it must be proved before it can be applied to the question algorithm.
4. backtracking Method: it is an optimization search method that searches forward based on the optimization conditions to achieve the goal. if you find that the previous selection is not worrying or fails to reach the goal, you can select again. (example: Walking through the maze)
Step: ① define the solution space for the given problem
② Space structure that is easy to search
③ Search space, and use the pruning function during the search process to avoid invalid search
5. exhaustive method: lists the possible solutions to the problem and identifies them one by one to find solutions that meet the conditions.
Key: How to list all possible solutions
How to determine whether the possible solution meets the conditions

 

Data Structure: The relationship between data elements is structured.
Four basic structures: Set, linear, tree, and graphic
Set:
Linear: one-to-one between elements, such as arrays, linked lists, queues, and stacks
Tree: One-to-multiple relationships, such as binary trees and Search Trees
Graphics: many-to-many relationships,
Features
Array: The length is immutable. You can directly calculate the inner and middle-size addresses to read data. Therefore, index-based access is highly efficient.
List: an extension of an array with Variable Length
| -- ArrayList has a high access efficiency through index, but the efficiency of data insertion in the middle is low (the data after the insertion point needs to be moved back)
| -- The efficiency of inserting data in the middle of the sorted list is high (only the pointer pointing is changed), and the index access is not faster than the ArrayList.
Set: the data is unique and the sequence of elements is not guaranteed.
Sorted hashset, fast query, and deduplication of Elements
Bag: similar to Set, the difference is that each key is counted in the Bag, therefore, if the same key is added multiple times, you can use the interface to obtain the number of keys in the bag.
Tree ):
Heap: the value of any node is larger than that of its subnode.
Binary search tree: all the keys on the left of the tree are smaller than the keys on the root node. Therefore, the keys on the right are larger than the keys on the root node. traverse from left to right to get an ordered sequence.
Merkle Tree (Hash Tree)
Merkle tree is mainly used for data validation. When a large file is transmitted between two machines, it is cut into many small pieces, then calculate the hash value for each piece and then make these hash into a tree structure: each leaf node in the tree corresponds to the hash of the specific file block, the value of a non-leaf node is the hash of its subnode. After the data is transmitted, the hash tree is calculated, compare the hash tree with the previously transmitted hash tree to find the data that is faulty during the logN comparison.
B-/B + Tree
B-tree is a generalization of the Binary Search Tree. Each node can have more than two subnodes. The B-/B + tree is mostly used in the design of database/file systems. The data stored in the tree is actually the first-level index, second-level index, and third-level index of the actual data, in this way, you can find a specific data within the specified time. The specific time depends on the data volume on each node and the number of indexes.
Red/black tree
The red/black tree is a special Binary Search Tree that automatically adjusts the tree structure during data insertion and deletion to ensure tree structure balance. It is weaker than the AVL Tree in balance requirements, so it is faster than the AVL Tree in data insertion, and it may be a little slower than AVL in data query. TreeMap uses the red/black tree to store data.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.