Surface by summary (first battle)

Today was an interview, job byte is beating back-end development, cross-examination found really difficult to prove safety only brush by a third, dynamic programming topics will not do harm, not by the final result, but also the first interview, own all aspects of a problem.

And when the first time you may say it

Computer Network Related: How to ensure that the information received TCP?

At that time I did not remember, it should be timeout retransmission, latecomer once the packet, the server to be confirmation, send ACK, the client receives, and then send the next packet, each send a packet, the client will be timed beyond time will retransmit

1.  Checksum: binary data packet transmission is then the sum of negate the purpose of detecting any change in the data transmission process . If you receive a section of the test and an error, TCP discards this segment and do not acknowledge receipt of this segment. 

+ 2. acknowledgment sequence number (SEQ + cumulative acknowledgment): the receiver receives the acknowledgment packet will (cumulative acknowledgment: acknowledges all the data sequentially received). TCP transmitted to each packet number , the recipient of the data packet sort , order data to the application layer. 

4.  Retransmission: When TCP is issued a segment, it starts a timer , waits for the destination to acknowledge receipt of the segment . If you can not receive a confirmation, it will retransmit this segment

3. Flow control: each party TCP connection has a fixed size of buffer space , TCP of the receiving terminal receives only sending end side buffer can accept data . When the receiver a chance to process the data sender, the sender can tell reduce the rate of transmission, to prevent packet loss. Flow control protocol TCP is used a variable size sliding window protocol . Now the receiver has a window (sliding window), with the ACK message transmission. If the received window size is 0, then the sender to stop sending data. And regularly sending window probe segment data to the receiving end, the receiving end so that the size of the window tells the sender. 

4. Congestion Control: If the network is congested, packets will be lost, then the sender will retransmit continue, resulting in a higher level of network congestion. Therefore, when congestion occurs, the sender should be controlled rate. This and much like flow control, but a different starting point. Flow control is to allow enough time to receive in order to receive, and congestion control is to reduce the degree of congestion throughout the network.

Operating system: how to distinguish between kernel mode and user mode?

CPU status:

Kernel mode (Kernel Mode): running an operating system program, a hardware operation

User mode (User Mode): The user program running

Privilege rings: R0, R1, R2 and R3

R0 corresponds to the kernel mode, R3 corresponding to the user state;

Different levels can run a different set of instructions;

User mode ---> Kernel Mode: the only way is through interrupts, exceptions, into a mechanism (visit pipe instruction)

Kernel mode ---> user mode: setting the program status word PSW

the difference:

  • Kernel mode and user mode are two running operating system level, when the program is run on three privilege levels, can be called to run in user mode. Because this is the lowest privilege level, the privilege level is normal user processes running, most programs are run directly to the user in user mode;

  • When the program is run on privilege level 0, it can be called running in kernel mode.

  • Run the program in user mode can not directly access the operating system kernel data structures and procedures. When we execute a program in the system, most of the time it will switch to kernel mode when running in user mode, in which the operating system needs some help to complete the work it does not have the power and ability to complete (such as the operating hardware) .

  • The main difference between these two states is

    When executed in user mode, memory space and process can access the object is limited, it is in possession of a processor that may be preempted

    While in kernel mode execution, is able to access all of the memory space and objects, and share some processors are not allowed to be preempted.

A state switching mode occurs

  • System calls

This is a user mode processes volunteered to switch to a way of kernel mode , user mode processes using the service provided by the operating system program calls the work done by the application system. For example, the previous example, fork () is actually implemented a process to create a new system call.

The mechanism of its core system calls or use the operating system for the user open a special interrupt to achieve, such as the Linux int 80h interruption.

User programs usually call the library functions, the library function call and then call the system, so some library functions a user program will enter the kernel mode (as long as the library function call somewhere in the system call), while others will not.

  • abnormal

When the CPU is running at the user when the program under the state unknowable in advance of certain exception occurred, then will trigger a switch from the current running process to handle this exception kernel-related programs, was turned into kernel mode, such as missing page exception.

  • Peripheral interrupt

When the user requests the peripheral device to complete the operation, the CPU will send corresponding interrupt signal , then the CPU executing the next instruction to suspend program to be executed and instead to execute the interrupt handler corresponding to the signal,

If the program was previously executed instruction in the user mode, then the transformation process is a naturally occurring state switch by the user to the kernel mode. Such as hard disk write operation is completed, the system will switch to the interrupt handler drives the reader in subsequent operations and the like.

The three ways to the system at run time by the user mode kernel mode of the main ways in which the system calls the user process can be considered to be actively initiated, exceptions and interrupts the peripheral device is passive.

Also want to ask the interviewer file system-related issues, I feel like I never learned, too hard, look back carefully review a wave, come on!

Online programming is a major piece of two problems:

1, an array number is the number of days, the value of the stock price, how to trade, maximum profit, output buy a few days, and the number of days to sell, and profit.

This subject will be made out

2, find the maximum number of columns number of columns and sub-questions, he asked to return the maximum number of sub-columns and start-stop and maximum.

Problem Description: An integer array, the array has a positive but also negative. A continuous array or a plurality of sub-array of integers, and each sub-array has a, and selecting the maximum value of all sub-arrays. Note: When the whole situation is negative, returns the largest of the negative

  This problem is most start thinking about is brute force, after the exchange with the interviewer, found that you can not use brute force method, the problem is a dynamic programming problem.

Scanning the array from left to right, during scanning, the number of record array and negative maximum values ​​scanned data, and accumulates the data for each scan and, by assuming variables thisSum (initial value is 0) save the maximum value (e.g., a variable sum recording, the initial value is 0) if the accumulated value before the current accumulated value is greater than the current maximum value stored put a maximum value (sum = thisSum), if thisSum smaller than 0, thisSum set to 0 and the re-accumulated. Such has been scanned array, the array until scanned. Since thisSum has less than 0, that is to say before the statistics and can be discarded, because the elements after the current cumulative result, they are smaller. For example, the array is divided into three parts Aib, because the value of A is larger than 0, A + i is smaller than 0, if the new accumulated from the beginning B, its value is large result certain ratio comprising i and then to accumulate B, because i is less than 0 while B is larger than and not necessarily before the a and accumulated. Because if the whole array is negative, to return to the biggest negative number, and from the above mentioned statement, we can see the current cumulative sum (thisSum) is always compared with 0, if less than 0 put thisSum set to 0, so when the array is negative when full, and the largest sub-sequences thisSum and arrays (sum) is always 0, and the reality is a bit different, so we'll record a negative number, when the number equal to the number of negative elements ( i.e. all negative), the maximum continuous subsequence it is imperative to set maximum and negative. It is also previously mentioned, and the maximum number of elements in the recorded negative scan process.

Code:

MaxSum int (int * A, n-int) 
{ 
    int SUM = 0; // for recording the largest contiguous subarray and 
    int flag = 0; // for recording the number of negative 
    int MaxNum = * a; // with an array of records in the largest number of 
    int ThisSum = 0; // current for recording successive sub-arrays and 
    for (int I = 0; I <n-; I ++) 
    { 
        IF (a [I] <0) // If no element is negative, put the flag added to the value. 1 
            ++ flag; 
        IF (MaxNum <a [I]) // record the current maximum array 
            MaxNum = a [I]; 
        ThisSum = a + [I]; / / update the current accumulated sub-array sum and 
        IF (ThisSum> sUM) 
        { 
            // if the current is greater than the sum of successive sub-arrays of sub-arrays of the recording and 
            // then set the maximum continuous current for the sub-arrays sum and 
            sum = ThisSum; 
        } 
        the else IF (ThisSum <0)  
        {
            // if the successive sub-array before the current consecutive sub-array sum is less than 0, is discarded,
            // next element from element subarray continuously recalculated sum 
            ThisSum = 0; 
        } 
    } 
    // if all negative, the maximum value is not the maximum element of the array 
    IF (n-In Flag ==) 
        SUM = MaxNum; 
    return SUM ; 
}

  The time complexity of the algorithm is only O (N), and a constant, i.e., only one scanning array to complete the task. And the use of auxiliary space is very small, only four variables, the space complexity is O (1).

 

Today a wave of summary:

  I did not test interview preparation, or foundation is not solid, had to prove safety brush, brush their topic too little, while knowledge of operating systems and computer networks, there are many forgotten.

   Select the back-end development, is currently no way to do, cv and recommendation system feels a lot to learn, and many times will not help tutor, mentor saying research with cv direction still a little gap. It was not very interested.

The road is long, happiness and earth.

Guess you like

Origin www.cnblogs.com/lvpengbo/p/12592387.html