The beauty of programming in Reading Notes-Microsoft technical interview experience (I)

Source: Internet
Author: User

TitleBeauty of programming-Microsoft technical interview experienceThe beauty of Programming Group

 

From the title of the book, you can know the general content of the book. About 60 articles are collected in the book.AlgorithmAndProgramDesign question. You can find some chapters in the book andSource codeBut I still like reading books. The following is an exampleStructure MethodThe Reading Notes of this section, which brings together common questions about operations on strings, linked lists, queues, and trees.

 

3.1 string shifting and Inclusion Problems

The question requires determining whether a character string can be obtained through cyclic shift.

The intuitive idea is to traverse the search cyclically. The optimized algorithm is to find the regular expression of the shift result, and obtain that all the strings produced by the cyclic shift of ABCD are abcdabcd strings, thus calling strstr () you can make a decision.

This is similar to the AB array inversion problem, where (a 'B') '= ba

 

3.2 English words for phone numbers

The question is given. Each digit on the mobile phone number button corresponds to several English letters and requires a combination of letters corresponding to the specified number.

After ing numbers and letters with a two-dimensional array, you can select loop or deep search for traversal. If the method is faster, tables are saved into dictionaries in advance, and numbers and words can be saved.

 

3.3 calculate string Similarity

A given string can be obtained by adding, deleting, modifying, and deleting a string in several steps.

Deep Search traversal + pruning. If the problem of such a given rule is small, you do not have to think about it. The question is not optimizedCodeIn fact, the pre-stored results can be used to determine the pruning, And the similarity size can be compared to the pruning. If the current operand has exceeded the obtained similarity result, it must have taken a detour, pruning is supported.

 

3.4 delete a node from a single-chain table with no Headers

If a pointer is given to a node in a single-chain table, you must delete it.

The key is to clarify the concept of drawing the linked list pointer. This non-mainstream delete node method represents the beauty of programming.

 

3.5 generate the shortest Digest

Question Requirements for the given web pageArticleTo generate the shortest summary so that it contains all the query keywords.

After word segmentation modeling, it is converted into a string matching problem. The intuitive idea is to traverse the search cyclically. The optimization method is similar to the wide search. Maintain a queue with a first pointer and a tail pointer to avoid repeated scans.

 

3.6 programming to determine whether two linked lists are intersecting

The question is given with two single-chain table header pointers. It is required to determine whether the two linked lists are intersecting.

This question is based on algorithm diversity, node-by-node judgment, Node Address hash judgment, two linked lists connected together to determine whether there is a ring, a better way is to determine whether the tail node is the same.

Two expansion problems: 1. How to judge if a ring exists on the linked list; 2. If the first intersection node is required.

 

3.7 maximum values in a queue

The topic provides one queue and three operations: adding a queue, deleting the first element, and returning the largest element. The data structure and algorithm must be designed to minimize the time complexity of the return maximum operation.

The maximum value is obtained. One is to directly traverse the queue; the other is to maintain the largest heap with an index; the other is to simulate the queue with two stacks, at the same time, a suffix array is used to store values from large to small (forget whether it is called a suffix array, but actually the value of the array is used as the subscript of the next element, as long as you know the subscript of the first element, you can find all the elements in order. For example, the suffix array of the question sequence {, 50, 80} is a [0] = 2, a [2] = 1 ).

 

3.8 calculate the maximum distance between nodes in a binary tree

You must obtain the number of edges between the two farthest nodes in the binary tree.

Deep Search traversal. At the end of the question, we summarize the formula for applying recursive problems.

 

3.9 rebuilding a binary tree

The question shows the result of pre-order and mid-order traversal, and the tree needs to be rebuilt.

Problems in the data structure book. Locate the root node in the forward order, and divide the middle order into two subsequences.

Several expansion problems: 1. If there are duplicate letters on the node, determine whether the binary tree is unique; 2. Determine whether the results of the forward and middle order traversal are reasonable; 3. Check whether the tree can be reconstructed through pre-order traversal and post-order traversal.

 

3.10 layered traversal of Binary Trees

The topic provides a binary tree. It is required to traverse the binary tree from top to bottom and from left to right and output it. The second is to print a certain level of nodes.

Search and traverse.

Two extension problems: 1. Access from bottom to top, left to right; 2. Access from bottom to top, right to left.

 

3.11 program correction

The question actually requires an error in finding a binary string program.

The first program error is midindex = (minindex + maxindex)/2. The result will overflow when the boundary value is added. It should be changed to midindex = minindex + (maxindex-minindex)/2; I have never considered this before. I have learned it.

Error 2: in some cases, the program will be in an endless loop.

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.