About the Author |
|
xvii | |
About the Technical Reviewer |
|
xix | |
Acknowledgments |
|
xxi | |
Introduction |
|
xxiii | |
|
Chapter 1 A Tour of Generics and Concurrency in Go |
|
|
1 | (54) |
|
1.1 Brief History and Description of Go |
|
|
1 | (1) |
|
1.2 Introducing Generic Parameters |
|
|
2 | (17) |
|
Adding a New Student by Name |
|
|
3 | (1) |
|
Adding a New Student by ID Number |
|
|
4 | (1) |
|
Adding a New Student by Student Struct |
|
|
5 | (1) |
|
|
6 | (2) |
|
|
8 | (1) |
|
|
8 | (1) |
|
Implementing an Interface |
|
|
9 | (1) |
|
Instantiating a Generic Type |
|
|
9 | (1) |
|
Unconstrained Generic Type any |
|
|
9 | (1) |
|
|
10 | (1) |
|
|
11 | (1) |
|
|
12 | (3) |
|
|
15 | (1) |
|
|
16 | (1) |
|
|
16 | (1) |
|
|
17 | (2) |
|
|
19 | (18) |
|
|
19 | (2) |
|
|
21 | (3) |
|
|
24 | (2) |
|
|
26 | (1) |
|
Use a quit Channel to Avoid Using WaitGroup |
|
|
26 | (2) |
|
|
28 | (2) |
|
|
30 | (1) |
|
|
31 | (1) |
|
Playing Chess Using Goroutines |
|
|
32 | (3) |
|
Fibonacci Numbers Using Goroutines |
|
|
35 | (2) |
|
1.4 Benchmarking Concurrent Applications |
|
|
37 | (17) |
|
Generating Prime Numbers Using Concurrency |
|
|
42 | (1) |
|
Sieve of Eratosthenes Algorithm |
|
|
42 | (4) |
|
Segmented Sieve Algorithm |
|
|
46 | (4) |
|
Concurrent Sieve Solution |
|
|
50 | (4) |
|
|
54 | (1) |
|
Chapter 2 Algorithm Efficiency: Sorting and Searching |
|
|
55 | (36) |
|
2.1 Describing the Speed Efficiency of an Algorithm ; |
|
|
55 | (9) |
|
|
55 | (1) |
|
Determining Whether a Slice of Numbers Is Sorted |
|
|
56 | (4) |
|
|
60 | (4) |
|
|
64 | (18) |
|
|
64 | (2) |
|
|
66 | (2) |
|
|
68 | (1) |
|
|
68 | (1) |
|
Comparing Bubblesort to Quicksort |
|
|
69 | (1) |
|
|
70 | (5) |
|
|
75 | (3) |
|
|
78 | (4) |
|
|
82 | (1) |
|
2.3 Searching Array Slices |
|
|
82 | (7) |
|
|
83 | (1) |
|
|
84 | (3) |
|
|
87 | (2) |
|
|
89 | (2) |
|
Chapter 3 Abstract Data Types: OOP Without Classes in Go |
|
|
91 | (32) |
|
3.1 Abstract Data Type Using Classes |
|
|
91 | (3) |
|
3.2 Abstract Data Types in Go |
|
|
94 | (12) |
|
|
94 | (4) |
|
Creating a counter Package |
|
|
98 | (1) |
|
Mechanics of Creating a Package |
|
|
98 | (3) |
|
Another Example of Implementing an ADT |
|
|
101 | (2) |
|
|
103 | (3) |
|
|
106 | (3) |
|
Using Interfaces to Achieve Polymorphism |
|
|
107 | (2) |
|
3.4 OOP Application: Simplified Game of Blackjack |
|
|
109 | (8) |
|
3.5 Another OOP Application: Permutation Group of Words |
|
|
117 | (4) |
|
Using the Standard map Data Structure |
|
|
117 | (4) |
|
|
121 | (2) |
|
Chapter 4 ADT in Action: Game of Life |
|
|
123 | (18) |
|
|
123 | (5) |
|
Rules of Grid Cell Evolution |
|
|
123 | (5) |
|
|
128 | (1) |
|
4.3 Console Implementation of the Game |
|
|
128 | (7) |
|
4.4 GUI Implementation of the Game of Life |
|
|
135 | (5) |
|
|
138 | (1) |
|
|
138 | (2) |
|
|
140 | (1) |
|
|
141 | (46) |
|
|
141 | (1) |
|
5.2 Slice Implementation of Generic Stack |
|
|
142 | (7) |
|
|
145 | (1) |
|
Why T Is Declared As Ordered |
|
|
145 | (4) |
|
5.3 Node Implementation of a Generic Stack |
|
|
149 | (4) |
|
5.4 Compare the Efficiency of Node and Slice Stacks |
|
|
153 | (3) |
|
5.5 Stack Application: Function Evaluation |
|
|
156 | (8) |
|
|
157 | (3) |
|
We Walk Through Algorithm |
|
|
160 | (2) |
|
Evaluating Postfix Expression |
|
|
162 | (2) |
|
5.6 Converting Decimal Number to Binary |
|
|
164 | (2) |
|
|
166 | (19) |
|
Efficient Strategy for Maze Path Using a Stack |
|
|
166 | (1) |
|
Building Infrastructure for Maze Application |
|
|
167 | (9) |
|
|
176 | (9) |
|
|
185 | (2) |
|
Chapter 6 Queues and Lists |
|
|
187 | (50) |
|
|
188 | (1) |
|
6.2 Implementation of Slice Queue |
|
|
188 | (3) |
|
|
190 | (1) |
|
6.3 Implementation of Node Queue |
|
|
191 | (3) |
|
6.4 Comparing the Performance of Slice and Node Queue |
|
|
194 | (1) |
|
|
195 | (3) |
|
|
198 | (5) |
|
|
203 | (4) |
|
6.8 Queue Application: Discrete Event Simulation of Waiting Line |
|
|
207 | (8) |
|
|
207 | (1) |
|
|
208 | (1) |
|
|
209 | (6) |
|
6.9 Queue Application: Shuffling Cards |
|
|
215 | (4) |
|
|
216 | (3) |
|
|
219 | (1) |
|
|
220 | (8) |
|
|
228 | (8) |
|
Benefit of Double Linking |
|
|
235 | (1) |
|
|
236 | (1) |
|
|
237 | (28) |
|
|
237 | (3) |
|
|
239 | (1) |
|
|
240 | (4) |
|
7.3 Building a Hash Table |
|
|
244 | (6) |
|
Create an Empty Hash Table |
|
|
245 | (1) |
|
Insertion into Hash Table |
|
|
245 | (1) |
|
Collisions and Collison Resolution |
|
|
246 | (1) |
|
|
246 | (1) |
|
Determining Whether a Key Is Present |
|
|
246 | (1) |
|
Comparing the Performance of Hash Table with Standard Map |
|
|
247 | (3) |
|
7.4 Hash Application: String Search |
|
|
250 | (6) |
|
|
251 | (1) |
|
|
252 | (4) |
|
|
256 | (7) |
|
|
263 | (2) |
|
|
265 | (22) |
|
|
265 | (1) |
|
|
266 | (1) |
|
|
266 | (1) |
|
|
267 | (1) |
|
|
267 | (1) |
|
|
267 | (19) |
|
|
269 | (1) |
|
Infrastructure Used to Display Binary Tree |
|
|
269 | (2) |
|
|
271 | (2) |
|
Implementation of ShowTreeGraph |
|
|
273 | (10) |
|
Creating go.mod Files in Subdirectories binarytree and main |
|
|
283 | (3) |
|
|
286 | (1) |
|
Chapter 9 Binary Search Tree |
|
|
287 | (28) |
|
|
287 | (4) |
|
|
288 | (1) |
|
|
289 | (1) |
|
|
289 | (1) |
|
|
290 | (1) |
|
9.2 Generic Binary Search Tree |
|
|
291 | (23) |
|
|
291 | (1) |
|
Generic Types Needed for Binary Search Tree |
|
|
291 | (2) |
|
Methods for Binary Search Tree |
|
|
293 | (1) |
|
Discussion of Insert, Delete, and Inorder Traversal |
|
|
294 | (1) |
|
|
295 | (2) |
|
Implementation of Tree Graphics |
|
|
297 | (16) |
|
Discussion of binarysearchtree Package and Main Driver |
|
|
313 | (1) |
|
|
314 | (1) |
|
|
315 | (34) |
|
10.1 Overview: Adelson Velsky and Landis |
|
|
315 | (5) |
|
|
316 | (1) |
|
|
317 | (1) |
|
|
318 | (1) |
|
|
319 | (1) |
|
10.2 Implementation of a Generic AVL Tree |
|
|
320 | (19) |
|
Explanation of avl Package |
|
|
332 | (6) |
|
Discussion of Main Driver Results |
|
|
338 | (1) |
|
10.3 Set Using Map, AVL, and Concurrent AVL |
|
|
339 | (8) |
|
Implementation of Set Using Map, AVL Tree, and Concurrent AVL Tree |
|
|
341 | (2) |
|
Explanation of Concurrent AVL Set |
|
|
343 | (1) |
|
Comparing the Three Set Implementations |
|
|
343 | (3) |
|
|
346 | (1) |
|
|
347 | (2) |
|
|
349 | (14) |
|
11.1 Heap Tree Construction |
|
|
349 | (2) |
|
11.2 Deletion from a Heap Tree |
|
|
351 | (1) |
|
11.3 Implementation of a Heap Tree |
|
|
352 | (6) |
|
Logic for Building a Heap Tree |
|
|
352 | (1) |
|
|
353 | (3) |
|
Explanation of Package heap |
|
|
356 | (2) |
|
|
358 | (2) |
|
Discussion of heapsort Results |
|
|
360 | (1) |
|
11.5 Heap Application: Priority Queue |
|
|
360 | (2) |
|
|
362 | (1) |
|
Chapter 12 Red-Black Trees |
|
|
363 | (24) |
|
|
363 | (1) |
|
Definition of Red-Black Tree |
|
|
363 | (1) |
|
Example of Red-Black Tree |
|
|
364 | (1) |
|
|
364 | (9) |
|
Detailed Walk-Through of Many Insertions |
|
|
367 | (6) |
|
12.3 Implementation of Red-Black Tree |
|
|
373 | (12) |
|
Comparing the Performance of Red-Black Tree to AVL Tree |
|
|
384 | (1) |
|
|
384 | (1) |
|
|
385 | (2) |
|
Chapter 13 Expression Trees |
|
|
387 | (14) |
|
|
387 | (2) |
|
13.2 Construction of an Expression Tree |
|
|
389 | (7) |
|
Building a New Expression Tree |
|
|
389 | (1) |
|
Explanation of Function NewTree |
|
|
390 | (1) |
|
Function Evaluation Using Expression Tree |
|
|
391 | (1) |
|
Explanation of Method Evaluate |
|
|
391 | (5) |
|
13.3 Implementation of ShowTreeGraph |
|
|
396 | (3) |
|
|
399 | (2) |
|
Chapter 14 Ecological Simulation with Concurrency |
|
|
401 | (26) |
|
|
401 | (1) |
|
|
402 | (4) |
|
|
402 | (1) |
|
|
403 | (1) |
|
|
403 | (1) |
|
|
404 | (2) |
|
|
406 | (1) |
|
|
406 | (19) |
|
Data Model for Each Species |
|
|
406 | (1) |
|
|
407 | (1) |
|
|
408 | (1) |
|
|
409 | (1) |
|
Required Methods for Mackerel to Be of Type MarineLife |
|
|
409 | (2) |
|
|
411 | (1) |
|
|
412 | (1) |
|
|
413 | (1) |
|
|
414 | (2) |
|
Output Function for the Graphical Display of Critters |
|
|
416 | (2) |
|
|
418 | (1) |
|
Full Implementation of Simulation |
|
|
418 | (7) |
|
|
425 | (2) |
|
Chapter 15 Dynamic Programming |
|
|
427 | (14) |
|
15.1 Example of Dynamic Programming: nth Fibonacci Number |
|
|
427 | (5) |
|
Top-Down Dynamic Programming |
|
|
428 | (1) |
|
Bottom-Up Dynamic Programming |
|
|
428 | (1) |
|
|
429 | (2) |
|
|
431 | (1) |
|
15.2 Another Application: 0/1 Knapsack Problem |
|
|
432 | (5) |
|
|
432 | (1) |
|
|
433 | (1) |
|
Dynamic Programming Solution |
|
|
433 | (1) |
|
|
434 | (2) |
|
|
436 | (1) |
|
|
437 | (3) |
|
|
440 | (1) |
|
|
440 | (1) |
|
Chapter 16 Graph Structures |
|
|
441 | (24) |
|
|
441 | (1) |
|
|
442 | (1) |
|
16.3 Depth- and Breadth-First Search |
|
|
442 | (9) |
|
|
444 | (1) |
|
|
445 | (6) |
|
16.4 Single-Source Shortest Path in Graph |
|
|
451 | (6) |
|
|
452 | (3) |
|
|
455 | (2) |
|
16.5 Minimum Spanning Tree |
|
|
457 | (1) |
|
|
457 | (1) |
|
16.6 Implementation of Kruskal Algorithm |
|
|
458 | (6) |
|
Explanation of Kruskal Implementation |
|
|
464 | (1) |
|
|
464 | (1) |
|
Chapter 17 Travelling Salesperson Problem |
|
|
465 | (12) |
|
17.1 Travelling Salesperson Problem and Its History |
|
|
465 | (1) |
|
17.2 An Exact Brute-Force Solution |
|
|
466 | (7) |
|
|
467 | (2) |
|
Brute-Force Computation for TSP |
|
|
469 | (3) |
|
|
472 | (1) |
|
|
473 | (1) |
|
17.3 Displaying a TSP Tour |
|
|
473 | (3) |
|
|
475 | (1) |
|
|
476 | (1) |
|
Chapter 18 Branch-and-Bound Solution to TSP |
|
|
477 | (16) |
|
18.1 Branch and Bound for TSP |
|
|
477 | (4) |
|
|
478 | (1) |
|
Computation of Lower Bound |
|
|
478 | (1) |
|
Branch-and-Bound Algorithm |
|
|
479 | (1) |
|
|
480 | (1) |
|
A Walk-Through Part of the Five-City Example Presented Earlier |
|
|
480 | (1) |
|
18.2 Branch-and-Bound Implementation |
|
|
481 | (10) |
|
Implementation of Priority Queue |
|
|
483 | (2) |
|
Generating Branch-and-Bound Solution |
|
|
485 | (5) |
|
|
490 | (1) |
|
|
490 | (1) |
|
|
491 | (2) |
|
Chapter 19 Simulated Annealing Heuristic Solution to TSP |
|
|
493 | (30) |
|
19.1 Combinatorial Optimization |
|
|
493 | (2) |
|
|
494 | (1) |
|
|
495 | (2) |
|
Simulated Annealing Steps |
|
|
495 | (1) |
|
Problem of Convergence to Local Minimum Rather Than Global Minimum |
|
|
496 | (1) |
|
19.3 Implementation of Simulated Annealing |
|
|
497 | (24) |
|
|
516 | (1) |
|
|
516 | (1) |
|
|
516 | (1) |
|
|
517 | (4) |
|
|
521 | (2) |
|
Chapter 20 Genetic Algorithm for TSP |
|
|
523 | (26) |
|
|
523 | (2) |
|
High-Level Description of Genetic Algorithm |
|
|
523 | (1) |
|
More Detailed Description of Genetic Algorithm |
|
|
524 | (1) |
|
20.2 Implementation of Genetic Algorithm |
|
|
525 | (22) |
|
Step 1 Form an Initial Population of Random Tours |
|
|
525 | (1) |
|
Step 2 Form an Elite Group of Best Tours |
|
|
526 | (1) |
|
Step 3 Tournament Selection |
|
|
527 | (1) |
|
|
527 | (4) |
|
|
531 | (3) |
|
Putting the Pieces Together |
|
|
534 | (13) |
|
|
547 | (2) |
|
Chapter 21 Neural Networks and Machine Learning |
|
|
549 | (24) |
|
21.1 Overview of Neural Networks and Machine Learning |
|
|
549 | (4) |
|
|
550 | (1) |
|
|
550 | (1) |
|
|
551 | (1) |
|
Schematics of Neural Networks |
|
|
552 | (1) |
|
|
553 | (1) |
|
|
553 | (1) |
|
21.3 Constructing a Neural Network |
|
|
554 | (1) |
|
Matrices That Represent Network |
|
|
554 | (1) |
|
21.4 Neural Network Implementation |
|
|
555 | (13) |
|
Estimating the Partial Derivatives of Cost with Respect to Each Weight |
|
|
560 | (8) |
|
21.5 Output from Neural Network |
|
|
568 | (4) |
|
|
572 | (1) |
Index |
|
573 | |