ACM Course Summary

Source: Internet
Author: User

ACM Course Summary

A semester later, this semester of ACM is I think the most difficult subject, although the most difficult, but I think the most useful or it, although did not master the four topics, but in the process of doing the exercise is very useful for thinking, and benefited. For this course summary, I will summarize from these four topics, there is something wrong in the place also hope that the teacher to correct me. Now you have the deepest impression of the picture, start with the illustration.

Related algorithms of graphs

We are mainly dealing with figures in this topic. In the whole sophomore, can say has been dealing with the figure, discrete mathematics inseparable from the diagram, data structure inseparable from the diagram,ACM Of course also inseparable from the diagram. Figure really is very important ah, it deep into all aspects of our lives, the figure in our life has great use, like some network cable laying, as well as the shortest length of roads or minimum costs, these problems are reflected in the topic.

In this topic, trees and graphs are the whole of this topic. For the tree, our aim is to give a tree, and then according to the requirements of the minimum spanning tree, which mainly has prim algorithm and kruscal algorithm, I personally think kruscal more easily understood and mastered than the prim algorithm,kruscal is a combination of point and check, this is very convenient,Prim algorithm to use the queue, which is invisible to increase the difficulty of understanding the algorithm, here is the main talk about the kruscal algorithm. The basic idea of this algorithm is

1. sort all sides from small to large;

2. In turn, the edge and its endpoint are added to the spanning tree, and if no circle is created after joining the Edge, the edge and its endpoints are added to the spanning tree; otherwise, it is deleted;

3. The n-1 Edge is terminated until the spanning tree is available .

The time complexity of this algorithm O (eloge), while the time complexity of prim is o (n2), in this regard, the former is more efficient.

In this topic, the first few questions I use and check set +kruscal to solve, the general problem solving procedure of this kind of problem is to set up the data model first, how to store, how to store nodes, like this one is about the two-dimensional plane map of the shortest distance point, The above points are represented by two-dimensional coordinates, which are completely different from the previous one-dimensional array to store the edges. After the data model is established, the weights of the edges are sorted according to the rules, usually from small to large, and then each node is treated as a separate tree, then the method of using and checking the set is not merged with the edge of a tree, plus the weight value. This way until all the nodes are in a tree. The algorithm ends.

The problem of finding the minimum spanning tree compared to the single source point shortest path is relatively simple in this topic, for single source point shortest path problem, this is involved in the diagram. To find the shortest path of single source point I do not much, which only used the SPFA algorithm and Dijkstra algorithm, I think the latter's understanding although still can but the code is too complex, a no attention on the faint, And this algorithm for the weight is negative when the time is not applicable, the limitations are too large, so the cloth recommended that everyone use this algorithm. In contrast, the SPFA algorithm cost-effective is very high, with the last queue, set up a data model, everything is done, easy to understand, and the limitations of small.

SPFA is actually The Bellman-ford of a queue implementation, reducing redundancy, that is, the edge of the lax is not at least a D -∞ Point as the starting point.

Algorithm:

1. queue Q={s}

2. Remove team head u, Enumerate all u d (v) >d (u) +w (u,v) pre (v) =u d (v) decreased, v May improve the other points later, so if v q v joined the queue.

3. Iterate 2until the queue Q is empty ( normal end ), or the number of times a point is enqueued >=n(contains a negative circle).

Generally used to find the negative circle ( more efficient than Bellman-ford), sparse graph of the shortest.

SPFA Algorithm Popular point is to start the queue, then the element s out of the team, traverse all the nodes, and then find the node associated with s , judge the starting point to the length and beginning of the node to s the length +s to the length of the node which is small, if the former small, do not do processing, the latter small words, modify the distance, at the same time the point of the queue, so the loop continues to know that the queuing element is empty.

Personally, it may be that the topic is relatively easy to understand because of the reasons why I've been there before.

Greedy algorithm

What is the greedy algorithm? The official definition is this: in the process of solving the problem of optimal solution, according to some greedy standard, from the initial state of the problem, directly to seek the optimal solution of each step, through a number of greedy choice, the ultimate solution of the whole problem, the solution is greedy algorithm. Popular point, the so-called greedy algorithm, is in the process of solving a problem, in every step of solving this problem, according to the principles stipulated in the topic, according to some algorithm to get the optimal solution of this step, and then every step to do so, until the problem solved, the final solution is generally the whole problem of the optimal solution. Why do you use "general" here? It can be seen from the definition of greedy algorithm that the greedy algorithm is not considered as a whole, and the choice made is only a local optimal solution in some sense, and the problem's own characteristics determine the optimal solution by using the greedy algorithm. So some of the topics, although each step is the optimal solution, but perhaps the final solution of the problem is not the optimal solution, which requires us to judge according to the characteristics of the problem itself. For example, you can analyze the nature of the problem yourself to determine whether the greedy algorithm, but also by testing some examples to determine whether to match the greedy algorithm. In contrast, if a problem can be solved in several ways at the same time, the greedy algorithm should be one of the best choices.

Therefore, in general, the greedy algorithm is a choice in each step to take in the current state of the best or optimal selection, hope to get the result is the best or optimal algorithm. Greedy algorithm is a kind of hierarchical processing method which can get the optimal solution of some measure meaning, and the solution of a problem is obtained through a series of choices, and every choice it makes is the best choice of some meaning in the current state. It is hoped that the optimal solution of the whole problem is obtained by the local optimal solution of the problem. This strategy is a very concise method, for many problems it can produce the overall optimal solution, but not guaranteed to always be effective, because it is not all problems can get the overall optimal solution.

If we have determined that the current problem is appropriate and greedy to deal with, then our task is how to choose the greedy standard, that is, how to use the rules to screen out the optimal solution.

It is also important to note that if we use greed to solve problems, then we must understand that the greedy algorithm understands that each step results in a direct impact on the final outcome. Greedy is to solve each sub-problem at the time to give the optimal solution of each problem, the solution of each problem to make choices, is not back, so we choose the greedy standard when it must be cautious, the standard selection of a good multiplier, otherwise it will be less than.

Comprehensive: The use of greedy strategy to solve the problem, there are two problems:

(1) Whether the problem is suitable for solving with greedy strategy;

(2) How to choose the greedy standard to get the best / better solution of the problem.

So what is the specific process of greed?

There are a few things to consider when solving problems with greedy algorithms:

(1) candidate set a: In order to construct a solution to the problem, there is a candidate set a as a possible solution to the problem, that is, the final solution of the problem is taken from the candidate set A.

(2) The solution set s: Along with the greedy choice, the solution set s expands continuously until it constitutes the complete solution of the satisfying problem.

(3) solve the function solution: Check whether the solution set S constitutes the complete solution of the problem.

(4) Choose function Select: Greedy strategy, which is the key to the greedy method, it points out which candidate is the most promising solution to the problem, the selection function is usually related to the object function.

(5) feasible function feasible: It is feasible to check whether a candidate object is added to the solution set, that is, whether the constraint is satisfied after the solution set expands.

In general, the greedy algorithm for some of the problems is undoubtedly the most convenient algorithm, in solving some problems, we should first consider whether the problem can go with the greedy algorithm, in determining the problem may be greedy, we next time to solve is the greedy principle how to choose. Choose the greedy principle, then the problem is solved. I remember when I was doing practice I had a little trick on the subject. It should be said that when using the sort function in STL , it ismore convenient to use the out-of-the-box function to sort the work than to write another function to sort. Through this evil, I also feel that the STL is really convenient.

Search

After the greedy algorithm is over, we have a second topic, search. In this topic, we learned some search algorithms like binary search, three-point search, depth and breadth-first search. Search is essential when writing programs. The search algorithm is a way to take advantage of the high performance of a computer to have a part or all of the possible situations where a problem is to be solved.

Compared to the simple enumeration algorithm has a certain direction and objective. The algorithm is in the solution of the space, from a state transfer (expand as required) to other states, so go on, the solution of the space in the state traversal, to find the answer (the state of the target).

Binary search algorithm, this algorithm should be said to be the simplest of the topic, I personally think that this algorithm is to take a limit of the idea, and constantly search interval to sub-find, so that each time you can discard half of the elements, the algorithm is still very efficient, it is important to note that when we look for two points, is based on the sort of rules that have been sorted to find the waiting range. The binary algorithm is used to find the valuexIntermediate value with unknown origin intervalmto compare, seexwith themthe size of the relationship, ifx=m, the search ends;x>m, indicatingxin the lower half of the range;x<m, indicatingxin the upper half of the interval, so that goes on, knowing to findXSo far.

Three-point search algorithm, for the three-point search algorithm, I think this is an improvement in the binary search, the efficiency is higher than the binary, this is mainly used to find some of the functions of the extremum or critical point, at this point, the three-order correlation is greater.

As for depth and breadth first search, I think that the most difficult of these four topics is BFS and DFS, anyway, I personally think so. So my understanding of these two algorithms is not very deep.

Breadth-First search (BFS), the basic idea: start with the initial state S and use the rules to generate all possible states. constitute the next layer of nodes, check whether the target State G, if not present, on the layer of all state nodes, the order of the use of rules. Generate the next layer of all state nodes, the level of all state nodes check whether G, if not, continue to the above thought to generate the next layer of all state nodes, so that a layer down. Until the target State is present. Breadth-First search is done using a queue, because it is a layer of search, the first layer of all expansion, and then the next layer, so that the use of the first-in-one-out nature of the queue can accomplish this task.

Its specific process is this:

1 each time the first element of the queue is removed (initial state), to expand, take the first element of the team to Judge

2 and put the expansion of the feasible state into the queue

3 Deleting the initial state

4 continue with the above three steps until the queue is empty.

Depth First search (DFS), the basic idea: from the initial state, the use of rules to generate a search tree next layer of any node, check whether the target State, if not appear, in this state using rules to generate another layer of any node, and then check, The repeating process goes all the way to the leaf node (that is, it cannot regenerate into a new state node), and when it is still not the target state, it goes back to the previous level, taking another branch that might extend the search. Use the same approach until the target State is found.

Depth first is done with a stack, because it must traverse through all the sub-states of a state to traverse the next state in the same layer, which conforms to the advanced post-out characteristics of the stack.

The implementation process is as follows:

1 Each time you remove the top element of the stack, expand it.

2 If the top element of the stack cannot continue to expand, eject it from the stack. Continue with the 1 process.

3 Repeat until the target state is obtained (to obtain a workable solution)

Or the stack is empty (no solution).

This is about the whole topic two, which is the worst topic I have learned, so I have limited comprehension.

Dynamic planning

When I learned this topic, I felt that the basic idea of dynamic programming was almost the same as the greedy principle, and dynamic programming was a method to solve multiple decision-making problems. So what is the multi-stage decision-making problem? Multi-stage decision-making: if the solving process of a class of problems can be divided into several interrelated phases, it is necessary to make a decision at each stage and affect the decision of the next stage. The multi-stage decision-making problem is to choose an optimal strategy among the strategies that can be selected, so as to achieve the best results under the predetermined standard. In layman's words, the problem is divided into multiple stages, and then there are multiple selectable strategies at each stage, and we are choosing the optimal strategy. In a thought, this and the greedy principle can be said to be identical. Regardless of the initial state and the first step, the remaining decisions form an optimal decision sequence relative to the new state created by the previous decision. The sub-sequence of the optimal decision sequence must be the local optimal decision sub-sequence.

It is not the optimal decision sequence to include the decision sub-sequences with nonlocal optimality. From this point of view, it is different from the principle of greed. We all know that for some problems can not be greedy principle, if we are dealing with these problems with the greedy principle, then although each step of the results are guaranteed to be optimal, but sometimes the result is not the correct answer to the problem. The guiding ideology of dynamic programming is to list various possible local solutions when making every step of the decision.

According to a certain criterion, we discard the local solutions which are not sure to get the optimal solution. Each step is optimal to ensure that the global is optimal.

In the topic of dynamic planning, I think to do a good job in the topic, The most important thing is to find the state transfer equation of each topic, of course, this is the aspect of thinking, as to the technical aspects, I think must master recursion, this is the fundamental to write these topics, and I think the dynamic planning and mathematics are closely related, like some mathematical aspects of the recursive formula can be applied in this respect, I remember that there are several such topics in this topic, for similar topics like this, as long as we find the formula, the code is very simple, and some only a few lines, can be said to be more than a multiplier. Then, in this topic, some knapsack problems are involved, like 01 backpack, full backpack and packet backpack, for this 3 3

As soon as the semester was over, it meant ACM also want to take a class, think back to the beginning of the school, the teacher's rhetoric so I was really determined to be in the ACM this road to a road to the black, then I would like to concentrate on ACM, after going out to participate in provincial races, regional races and so on, at that time is really ignorant ah. These four topics have come to the discovery that ACM is really not something that ordinary people can do. We first learn a topic and then do the topic, because we know that the topic of the topic is definitely used just learn the method, so it is relatively easy to do. But if we do not tell us which topic these topics are, random out of the topics we have studied, I believe most people still do not know how to do.

Through the four topics, the hardest I think should be the search there, and then the simplest should be the map here, it may also be because the search for the topic did not seriously do the problem. Four topics came, although with their own lofty sentiments gradually away, but this really exercise my thinking ability, understand some algorithms also really improve my programming ability, I think this is the harvest. Although the future may not touch ACM, but with the students to brush the problem, in order to suppress a problem I spent the night of this experience I will never forget.

ACM Course Summary

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.