1th Chapter A big wave is approaching--sort of ................................................................................................... 1
The fastest and simplest sort in the 1th section--The bucket sort ..... ..... ..... ................ ..... ..... ..... ..... ..... .............. .......... 2
2nd-neighbor Good talk-bubble sort ................................................................................................. 7
The 3rd section is the most commonly used sort--quick sort ..... ..... ..... ..... .............. ..... ..... ..... ..... ..... ............... ......... 12
The 4th quarter Hum buys the book ......................................................................................................................... . 20
2nd Chapter stack, queue, linked list ..................................................................................................................... 25
The 1th section decrypts QQ number--queue ....................................................................................................... 26
The 2nd section decrypts the Palindrome--stack ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... ....... 32
3rd card Game-Kitty fishing ................................................................................................... 35
4th section linked list ......................................................................................................................... ......... 44
The 5th section simulates the linked list ......................................................................................................................... . 54
3rd Zhang Yi Lift! It is very violent ..... ..... ..... .................................. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... ..... .... 57
1th, the Olympic number of the pit daddy ...................................................................................................................... 58
2nd quarter bomber. ......................................................................................................................... ..... 61
3rd match Stick equation ...................................................................................................................... 67
The full arrangement of the 4th quarter ...................................................................................................................... 70
The 4th chapter of Universal Search ......................................................................................................................... .... 72
The 1th section does not hit the south wall does not look back--depth first search ..... ..... ........... ....... ..... .................. ......... 73
2nd, save Xiao Ha ......................................................................................................................... . 81
The 3rd section is progressive--breadth first search ...... ..... ..... ..... ..... ............. ..... ..... ..... ..... ..... ............... ......... 88
4th, then the bomber. ...................................................................................................................... 95
5th section of the Treasure Island adventure ........................................................................................................................ 106
6th Water-saving plumber game .................................................................................................................... 117
The 5th chapter of the graph's traversal ......................................................................................................................... ...... 128
The 1th section, depth and breadth, what is the first point of ... ...................... ..... ..... ..... ..... ..... ............. .......... 129
The 2nd section City Map--The depth of the chart is first traversed ..... ..... ..... ..... ........ ....... ..... .................. ......... 136
Ah ha! Algorithm
8
The 3rd section has the least turnaround--the breadth of the chart is first traversed ..... .... ..... ..... ....... ....... ..... .................. ......... 142
6th Chapter Shortest Path ......................................................................................................................... ...... 147
The 1th section is only the five elements of the algorithm--floyd-warshall ...... ..... ........... ............................. 148
The 2nd section Dijkstra algorithm--through the edge to achieve relaxation ....... ..... ....... ....... ....... ..... ....................... 155
The 3rd section bellman-ford--to solve the negative right side ........ .................... ..... ..... ..... ................. .......... 163
Queue optimization for section 4th Bellman-ford .............................................................................................. 171
The 5th section of the shortest path algorithm is compared and analyzed ...... ..... ..... ..... ..... ............ ..... ..... ..... ..... ..... ..... ............ ........... 177
The 7th chapter of the Magical tree ......................................................................................................................... ...... 178
The 1th section opens the "Tree" tour ..... ..... ..... ..... ..... ..... ..... ..... ..... ...... ....... ....... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... ....... 179
2nd Two-fork Tree ......................................................................................................................... .... 183
The 3rd heap--The magical priority queue ..... ..... ..... ..... ..... .................. ..... ..... ..... ..... ..... ..... ..... ....... .............. 185
The 4th section is the first to seize the king--and to check the collection ... ..... ..... ..... ..... ..... .......... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... ....... 200
The 8th chapter more exciting algorithms ....................................................................................................................... 211
1th Section Biaoju Dart--the smallest spanning tree of the graph ...... ..... ..... .............. ..... ..... ..... ..... ..... ............. .......... 212
The 2nd section discusses the minimum spanning tree ..... ..... ..... ..... ..... ..... ..... ..... ..... ...... ....... ....... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... ....... 219
The 3rd section of the important city-the cutting point of the map ..... ..... ..... ............ ......... ..... ..... ..... ..... ..... ..... ..... ....... .............. 229
The 4th section of the key road--the cutting edge of the picture ..... ..... ..... .................. ..... ..... ..... ..... ..... ..... ..... ....... .............. 234
In the 5th section I'm going to do the matchmaker--two-point chart maximum match ....... ..... ......... ..... ..... ..... ................. .......... 237
The 9th chapter is still better----Microsoft Research Asia interview ....... ..... ............. ....... ..... ................. ......... 243
1.1 Barrels Sorted---O (n+m)
1.2 Bubble Sort---O (n^2)
1.3 Quick Sort---O (nlogn)
1, find the base number 2, first from the right to the left to find a number less than 6, and then from left to right to find a number greater than 6, exchange
1.4 de-weight, sort
The first method: bucket sorting,
Second method: Sort first, post-heavy, bubble sort or quick sort
2.1 Queues
Linear structure, only the first head of the queue is allowed to delete, at the end of the queue tail insert
Example: Buy a ticket; FIFO first
struct type:
struct queue{int data[]; // the body of the queue, used to store the content int head; // Team First int tail; // team Tail };
2.2 Stacks
Example: A small bucket to put a ball;
Top: A variable pointing to the top of the stack
Purpose: To judge palindrome words,
2.4 Linked List
In the C language, you can use pointers and function malloc to implement.
You can also use an array to simulate a linked list
struct node, two members, data and pointers
structNode *Head;head= NULL;//the head pointer is emptystructNode *p;//dynamically request a space to hold a node and point it to this node with a temporary pointer p .p = (structNode *)malloc(sizeof(structnode)); scanf ("%d",&a);p->data = A;//store the data in the current node in the data domainP->next = NULL;//the subsequent pointer to the current node points to null, which is the next node of the current node is empty
, called the struct pointer operator, is also used to access members within a struct. Because P is a pointer here, you cannot use the. Number to access internal members.
2.5 Analog Link List
Simulating a linked list with an array
Two arrays, data and left
3.1 Enumeration
3.2 Bomb man
Using arrays to simulate maps
3.3 Match Stick Mode
The core is to solve the equation,
3.4-digit Full array
4.1 Deep Priority Search (Depth first search, DFS)
Basic model
void dfs (int step) { // judgment Boundary // for (i=1; i<=n;i++) { continue to the next Dfs (step+1); } return}
Ah ha! Algorithms >>