The first section, depth and breadth first refers to whatFor the traversal of the graph.The main idea of depth-first traversal is to traverse one of the branches of the graph until the end, then back up, and then do the same traversal along another line until all the vertices have been accessed.The main idea of breadth-first traversal is to first access all of its adjacent vertices with an unused vertex, and then to each adjacent vertex, and then access their adjacent, inaccessible vertices unti
);
}
ElseIf(NL = nR)
{
For(I = F, j = T; I
{
Swap (vdata [I], vdata [J]);
}
}
}
Solution 3.But this code does not really feel like aha, maybe it should be called ouch, right. The above method requires careful programming. In fact, there can be more aha algorithms.
To convert AB to Ba, you can perform the following operations: first, reverse (A), reverse (B), and finally r
This article begins with a discussion of some simple concepts and algorithms for the "tree".Tree is a basic data structure, the reason is called the tree is derived from the bionic-branch bifurcation structure or the structure of the root fork, it is very good to express the logical relationship between the nodes, it is also a very important structure of graph theory. From the point of view of its name, we find that much of the growth of scientific thinking stems from a keen observation of natur
]++) for(a[9]=1; a[9]1; a[9]++) { for(i =1; I 9; i++) Book[i]=0; for(i =1; I 9; i++) Book[a[i]]=1; Sum=0; for(i =1; I 9; i++) Sum+=Book[a[i]]; if(sum==9 -*a[1] +Ten*a[2] + a[3] + -*a[4] +Ten*a[5] + a[6] == -*a[7] +Ten*a[8] + a[9]) { total++; }} printf ("Total =%d", total/2);//by the addition of the law of exchange we can not be difficult to understand that this should be in addition to 2, for the results of test in
The following describes the Bubble Sorting Algorithm of the AHA algorithm:
# Include
The time complexity of Bubble Sorting is O (n2), which is not a good sorting algorithm.
section colorful Little 18 4th section let the computer do the addition 21 5th section number of the home-variable 25 6th Section data output--I say I'm going to go to the 30 7th section of data input--I say what, even if 33 8th quarter How many kinds of small houses 36 9th section of the Cloud see the Moon Ming 39 10th Section Logic Challenge 1: Exchange Small house in the number of 41 11th day Ah! How can you read this? 44 Media Reviews@ Baidu Mobile Cloud Chief evangelist Zhang Hui: Learning
The running result is
0 1 6 8 15 22 50 100 999 1000
By slightly modifying the code above, you can solve the problems left behind in section 1st, as shown below.
# Include
Struct student {char name [21]; char score ;}; // a struct is created here to store the name and score int main () {struct student a [100], t; int I, j, n; scanf ("% d", n); // enter a number n for (I = 1; I
You can enter the following data for verification:
5huhu 5ha
Today began the study of the "AHA algorithm" book. Generally speaking, this book is the algorithm of the small petition, the language is very popular, the introduction of the algorithm is relatively simple, now back to see the simple things will seem to waste time? Otherwise, I recently feel that the competition is not the ultimate way, the direction of learning is also changed to book as the object ("Specific mathematics" a column of the establishmen
Quick sorting of Aha AlgorithmsEfficiency issues
The Bubble Sorting mentioned above can be said to be our first real algorithm, it solves the problem that bucket sorting occupies a large amount of space (because bucket sorting requires a specified memory according to the number of sorted data), but Bubble Sorting sacrifices a lot of efficiency, suppose we want to sort the number of 0.1 billion, because the time complexity of Bucket sorting is O (M + N
Magical conversion of the binary
Time limit:1000 MS
Memory limit:32768 K
Total submit:248(users)
Total accepted:175(147 users)
Rating:
Special Judge: No
Description
XUXU data structure to test, so he is very hard to read, one day he looked ah look, suddenly see a conversion of the topic, said to be a decim
sort is the double nesting, the outer layer is n-1, the inner is this trip to be n-i times comparedDisadvantage, the bubble sort time complexity is very high.Application scenario: Sorting out unordered columns3. Quick SortBasic idea: Determine the base number k, which is generally the 1th number in a series. On both sides of the sequence to the middle of the "exploration", according to judging conditions (such as in order), starting from the right side, when a value greater than k on the right,
;VK, VK->VJ is also based on E[i][k], e[k][j], so we actually enumerate a series of relatively optimal cases, Then we find the current optimal solutions in these relative optimal solutions, and this is the place that the dynamic programming idea embodies.Essentially, the algorithm is a clever combination of enumeration and dynamic programming.#include using namespacestd;intMain () {inte[Ten][Ten], K, I, J, N, M, t1,t2,t3; intINF =9999999; scanf ("%d%d",n,m); for(i =1; i) for(j =1; j)
".notes:fast sorting is faster because each exchange is a jump-through compared to a bubbling sort. Every time I sort.sets a datum point that places a number less than or equal to the datum point to the left of the Datum point, and a number greater than or equal to the datum pointto the right of the datum point. This will not be the same as bubble sort in each exchange, only between the number of adjacentExchange , the distance is much greater. Therefore, the total comparison and the number of e
BFS
The concept of graphs
Difficult content
Plumber's Game (SELECT, do not make mandatory)
Treasure Island Adventure (seed filling method)
Part III: 6-7 Chapters, 9 knots, total 64 pagesReading time: 1 weeks, remember to operate the machine.Key content
Dijkstra algorithm
Comparative analysis of Shortest path algorithm
Two-fork Tree
Difficult content
Bellman-ford algorithm
The use of heaps
and check Set
Written in the lastFor
correctly returned, it is important to understand.About efficiencyfast sorting is faster than the bubbling sort of each swap location is a jumping, each sorting set a base number, the less than the base number on the left, greater than the number of the base to the right, so that it does not have to be compared with the number of adjacent to a bubble sort at a time to compare the exchange location so the matter, The number of comparisons is much less, which increases efficiency. So the worst bu
Section 3 heap sorting
Create a heap of n elements. First, encode the N nodes from 1 to n in the top-down and left-right mode, in this way, N nodes can be converted into a Complete Binary Tree.
Then, from the last non-leaf node (node number is n/2)
It sounds really bad at noon. Obviously it was very hot, but I felt like I caught a cold during my lunch break. I have no plans for this afternoon. I will continue to struggle with the courseware and questions left by teacher Cao.
I just flipped
Problem Description:
Xiao-hum and Xiao-ha are playing a rather strange poker game--kitty fishing. Game rules: Divide a deck of cards evenly into two parts, no one points. Xiao Hum first took out the hands of the first card on the table, and then
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.