641 Abstract Data Structures, 335, 336, 393 Abstractions, 158, 367 Access Attributes, 356, 429 Add Two Function, 216, 217 Algori
Total Page:16
File Type:pdf, Size:1020Kb
Index A input data, 96 input size, 95 Abstract data structures, 335, 336, 393 measurement uncertainty, 94, 95 Abstractions, 158, 367 plotting, 93, 95 Access attributes, 356, 429 range, 95 add_two function, 216, 217 sleep() function, 94, 95 Algorithmic efficiency theoretical, 94, 95 amortized complexity validation, 93 add elements, 77 variable-size data, 93 analysis, 78, 80 worst-case scenario, 96 append operation, 78 sequence of numbers, 73 banker’s method, 78, 79 types cheap operation, 78 average-case complexity, 75 data structures, 76 best-case complexity, 75 expensive operation, 77, 79 worst-case complexity, 75 individual operation, 79 Algorithms, 41 memory layout, 78 abstraction level, 7 operations, 79 checking, 42 potential method, 78–80 combining, 6 Python’s lists, 77 comparing, 66 rule, 77 comparison-based, 98, 103 space, 77 complexity, 44 statistical properties, 76 computational problem, 42, 43 analysis, 74 cryptographic protocols, 43 guessing game, 76 designing, 7, 43 if statement, 74 abstractions, 45 operations, 74 assertions, 51 running time bits, 56 best-case scenario, 96 cities, 45 data size, 96 computational problem, 44 empirical, 93, 94 computations, 54 641 © Thomas Mailund 2021 T. Mailund, Introduction to Computational Thinking, https://doi.org/10.1007/978-1-4842-7077-6 INDEX Algorithms (cont.) problems complexity, 43 data, 45 programmer time, 65 distances, 45 properties, 42 for loops, 54 sequential, 57–59 implementation, 45 stable/unstable, 102 index, 46 tasks, 7 invariants, 52, 53 techniques, 42 lists, 46 terminates, 41 loop condition, 56 Timsort, 105 map, 44, 46 undecidable, 43 model of system, 44 append() method, 394, 396, 397, 552 operators, 54 apply() function, 159, 188, 382 output, 46 Arithmetic operations, 336, 563, 571 pairwise distance, 51 Assertions, 51 post-conditions, 51, 52 Asymptotic running time, see Big-Oh preconditions, 51, 52 notation progress, 54 Attributes, 320, 344, 348, 358 reductionist approach (see Reductionist approach) roads, 45 B termination function, 54, 55 Bayesian statistics, 301 while loops, 54 Big-Oh notation efficiency, 43 add numbers, 82 halting problem, 42 arithmetic implementation, 6, 65 addition rule, 87 intractable, 43 binary search, 88 lists complexity, 89 changing numerical base, 60, 61 functions, 86 longest subsequence, 63 inner loop, 88 longest substring, 63 insertion sort, 88 merging, 64 interval, 89 powerset, 63 low/high range, 88 Sieve of Eratosthenes, 62 multiplication, 86, 87 measuring, 66 nonzero constant, 87 operations, 80 outer loop, 88 optimal, 44 quadratic time, 88 P vs. NP problem, 43 running time, 86, 88 primitive operations, 66 summation, 87 642 INDEX transitivity rules, 86 binary numbers, 596, 601 asymptotic behavior, 81 binomial trees, 595, 596, 598 big-Theta, 82 build tree, 597 binary search, 92 carry tree, 602 classes, 82, 83 constant time, 597 complexity classes constant-time operations, 605, 606 algorithm, 91 create nodes, 597 constant time, 89 data structure, 595 cubic time, 90 deletion, 602 exponential time, 90 delete_min(), 606 growth, 90, 91 designing, 599 linear time, 90 ephemeral, 535, 605 logarithmic time, 89 get_min(), 604 long-linear time, 90 heap class, 598 properties, 83, 84 implementation, 605 quadratic time, 90 insertions/deletions, 599, 604 function growth, 91 insert_tree(), 599 functions, 81 vs. leftist heap, 604 insertion sort, 92 linking, 597 longest substring, 93 merge(), 600–602 merging, 93 operations, 533, 603, 604 operations, 81 Python lists, 596 order class, 80 ranking, 596 reasoning, 84, 85 running time, 601 Sieve of Eratosthenes, 92 sibling/children attributes, 596 symmetric, 81 sorting, 605 upper bound, 81 value, 600 Binary heaps, 607, 610–612, 615, 622, 630 Breadth-first tree traversal Binary search algorithm, 98, 99, 247 definition, 581 bind1st()function, 342 implementation, 582 Binning, 475, 478 in-order and breadth-first, 582 Binomial coefficient, 302, 595 Built-in mutable data structures, 476 Binomial distribution, 303 Binomial heaps, 595, 629 add numbers, 601 C add tree, 597 __call__() magic method, 364 amortization analysis, 604 __call__() method, 338, 365 binary addition, 597 Call by reference, 148 643 INDEX Call by value, 148 implementation, 107 Classes, 173, 318, 319, 326 iteration, 106, 107 Class hierarchies, 369 not stable, 108 Class variables, 339, 341, 343 running time, 108 compare() function, 182, 184 strategy, 105 Comparison sorts swapping, 106 bubble sort Complexity theory, 43 asymptotic complexity, 114 Computational thinking, 2, 4, 8 cocktail shaker algorithm, 115 feed data, 10 comparisons, 114, 115, 117 language choice, 10 for loop, 112 natural sciences, 8 forms, 115, 116 problem solving, 9 inner loop, 113, 114 Computer vs. insertion sort, 111, 114 Caches, 67 invariants, 112, 113 computations, 66 positions, 115 core, 66 swapping, 111, 113, 115, 118 memory hierarchy, 67 termination, 113 registers, 67 variables, 112 running time, 67 variants, 115 Concrete data structures, 335 while loop, 112 Conditional independence, 295, 296, 306 worst-case complexity, 115 Conditional probabilities, 294, 296–298 insertion sort Constant-time operations, 402, 452, 474, asymptotic complexity, 114 481, 550 best-case, 110 Constructor, 320, 604 contiguous regions, 109 contains() function, 447, 450, 463 for loop, 109 counter() function, 186, 196 implementation, 110 inner loop, 109 invariant guarantees, 108, 109 D iteration, 108 Data objects, 98, 360 reverse order, 116 Data structures, 637 running time, 110 Decoding problem, 313 swapping, 109, 110 Deep learning neural networks, 639 worst-case, 110 def function, 202 selection sort Default methods, 360 for loop, 107 Default parameters, 162, 164, 165 guarantees, 106 Designing algorithms, 5, 11, 43, 44, 47, 53 644 INDEX Distribution sorting algorithms, 119 first element, 412–414, 419 Divide and conquer last element, 414, 415, 419 definition, 247 __repr__(), 410 floating-point numbers, 284–287 set_at_index(), 411, 412, 421 merge sort, 248 special case, 413, 414 quick sort, 249 Dynamic programming recursive, 247 edit distance Domain-specific languages (DSLs), 493 backtracking, 279, 280 Double underscore methods, 336 implementation, 278 Doubly linked lists memoization, 276, 277 adding dummy recursion, 275, 276 create list, 416 fibonacci number, 271, 272 dummy link, 417 linear algorithm, 268, 269 first/last, 416 memoization, 273, 274 get_at_index(), 417 partitioning new link, 418 definition, 281, 282 __repr__() method, 416, 417 memoization, 283, 284 set_at_index(), 417 recursion, 282, 283 add reference, 410 recursion, 268 append(), 410, 418 Dynamic programming algorithm, 273, circular, 424 274, 307, 313 constant-time operation, 422 create dummy, 410 dummy points, 410 E dummy.next.next, 412 Emission probabilities, 306 elegant solutions, 420 enqueue() operations, 551 extend(), 415, 416, 420 Ephemeral data structure, 461 general case, 412 Error handling, 171, 175 get_at_index(), 411, 419, 421 exception, 176 insert_after(), 418, 420 low-level, 176 insert_sequence_at(), 422 evaluate(), 373, 375 list implementation, 422–424 Exception() expression, 173 ListSequence class, 421 Exceptions, 170, 172, 173, 326 new link, 411 *expressions argument, 562 prepend(), 422 Expression stacks and stack machines previous pointer, 415, 416 call operator, 568 Python lists, 421 CPython, 561 removal EmptyStack exception, 563 645 INDEX Expression stacks and stack issue, 424 machines (cont.) objects, 426 inner-inner function, 567 open() function, 425 LOAD_CONST operation, 569 previous attribute, 428 operator module, 565 property class, 428 operator, 561 Python, 425, 427 Python features, 568 references RAM model, 560 adding, 426 registers, 560 circular, 427 reverse Polish notation, 562, 564 count, 426, 429 extend method, 230, 402 previous/next, 427 weak, 427 resources, 424, 425 F triggering, 427 fib() function, 233, 239 with syntax, 425 First-class objects, 158 Garbage collector, 425 First-in first-out (FIFO), 551 Generators Floating-point numbers, 293 animals(), 438 Floyd-Warshall’s algorithm, 50, 51, 53 bugs, 441 format() method, 378 counter, 439 Forward algorithm, 307–310 definition, 438 rescale, 310 for loop, 441, 442 scaling factor, 311 infinite sequences, 440 Forward recursion, 311 instance, 438 Functional programming, 2, 195, 231 __iter__(), 442 Function vs. function instance, 160–162 iterator, 438 Function instances, 160, 161, 166 linked list, 442 Function parameters vs. local variables, 146 lists, 441 modification, 440 modifiers, 441 G output, 438 Garbage collection square_counts, 441 context manager, 425 syntax, 440 __del__() method, 427 take(), 441 doubly linked lists, 426 testing, 438 Garbage collectors, 426, 429 yield, 438, 439 gc module, 426 yield from command, 439 gc.collect(), 427 __getattribute__() method, 350, 352, 353 646 INDEX get_node() function, 466 implementation, 588, 589 Global scope, 143, 146, 147, 178 insertion, 586 Global variable, 145, 147–149, 340 is_empty(), 586 merge(), 586, 587 node’s value, 586 H Hidden Markov models (HMMs), 304 Halting problem, 42, 43 dependency graph, 305 __hash__() method, 477 emission probabilities, 306 Hash dictionary, 485 observable states, 305 Hash function, 474, 475, 478 probabilities, 289–292 Hash table data structure, 474 Hierarchies analysis, 481 class, 375 collision, 479, 480 conceptual, 372, 374, 375 hash function, 475, 478 design, 371 resize, 481, 482, 484 expression, 375 Heaps Higher-level abstractions, 8 binary heaps Higher-order functions, 156–158 addition, 609, 610 High-level languages, 9 balancing, 607 Huffman encoding delete_max() operation,