GithubHelp home page GithubHelp logo

masak / taocp Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 0.0 452 KB

Solving exercises in The Art of Computer Programming

TypeScript 79.12% JavaScript 1.35% Scheme 3.80% Haskell 4.65% TeX 9.33% Perl 1.75%

taocp's Introduction

Reading The Art of Programming is a serious enough undertaking in itself (I have only read about a third of it so far myself), but anyone who succeeds in doing all the exercises will have earned themselves several doctorates. — Danny Yee

TAoCP Exercises Build Status

Chapter 1 — Basic Concepts

1.1 Algorithms

ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9

1.2 Mathematical Preliminaries

1.2.1 Mathematical Induction

ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12 ex13 ex14 ex15

1.2.4 Integer Functions and Elementary Number Theory

ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12 ex13 ex14 ex15 ex16 ex17 ex18 ex19 ex20 ex21 ex22 ex23 ex24 ex25 ex26 ex27 ex28 ex29 ex30 ex31 ex32 ex33 ex34 ex35 ex36 ex37 ex38 ex39 ex40 ex41 ex42 ex43 ex44 ex45 ex46 ex47 ex48 ex49

Chapter 2 — Information Structures

2.2 Linear Lists

2.2.1 Stacks, Queues, and Deques

ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12 ex13 ex14

2.2.3 Linked Allocation

Algorithm T

ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12 ex13 ex14 ex15 ex16 ex17 ex18 ex19 ex20 ex21 ex22 ex23 ex24 ex25 ex26 ex27 ex28 ex29 ex30

2.2.4 Circular Lists

ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12 ex13 ex14 ex15 ex16 ex17 ex18

2.3 Trees

ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12 ex13 ex14 ex15 ex16 ex17 ex18 ex19 ex20 ex21 ex22

2.3.1 Traversing Binary Trees

Algorithm T

ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12 ex13 ex14 ex15 ex16 ex17 ex18 ex19 ex20 ex21 ex22 ex23 ex24 ex25 ex26 ex27 ex28 ex29 ex30 ex31 ex32 ex33 ex34 ex35 ex36 ex37

Chapter 7 — Combinatorial searching

ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12 ex13 ex14 ex15 ex16 ex17 ex18 ex19 ex20 ex21 ex22 ex23 ex24 ex25 ex26 ex27 ex28 ex29 ex30 ex31 ex32 ex33 ex34 ex35 ex36 ex37 ex38 ex39 ex40 ex41 ex42 ex43 ex44 ex45 ex46 ex47 ex48 ex49 ex50 ex51 ex52 ex53 ex54 ex55 ex56 ex57 ex58 ex59 ex60 ex61 ex62 ex63 ex64 ex65 ex66 ex67 ex68 ex69 ex70 ex71 ex72 ex73 ex74 ex75 ex76 ex77 ex78 ex79 ex80 ex81 ex82 ex83 ex84 ex85 ex86 ex87 ex88 ex89 ex90 ex91 ex92 ex93 ex94 ex95 ex96 ex97 ex98 ex99 ex100 ex101 ex102 ex103 ex104 ex105 ex106 ex107 ex108 ex109 ex110 ex111 ex112 ex113 ex114 ex115 ex116 ex117 ex118 ex119 ex120 ex121 ex122 ex123 ex124 ex125 ex126 ex127 ex128 ex129 ex130 ex131 ex132 ex133 ex134 ex135 ex136 ex137 ex138 ex139 ex140 ex141 ex142 ex143 ex144 ex145

taocp's People

Contributors

masak avatar dependabot[bot] avatar

Stargazers

 avatar DeletedName avatar Sonic Ning avatar

Watchers

 avatar James Cloos avatar  avatar

taocp's Issues

Get rid of ProtoListNode in src/ch2.2.4/ex5/circular-list.ts

The internal type ProtoListNode exists because, while building the circular list, it briefly ends with a null link which is then "fixed up" to point back to the beginning of the list.

But there's a better way, which doesn't involve this internal type:

  • As a base case, return the null link on empty input
  • Otherwise, create a ListNode for the last element pointing to itself
  • reduceRight on all the elements except the last, using the cyclic ListNode as the base case
  • Fix up the cyclic ListNode by pointing it to (the start of) the resulting list

Close the wiki

The wiki keeps being not updated. Solution: close it, after:

  1. Putting navigation links in the README.md
  2. Testing that the directory structure is reflected by the README.md

Chapter 2.2.3, exercise 7: stack overflow on very long linked lists

I wrote this test:

test('reversing a very long list does not cause a stack overflow', (t): void => {
    const LENGTH = 10_000;
    let longAscendingArray = Array.from({ length: LENGTH }, (x, i) => i);
    let input = makeLinkedList(...longAscendingArray);
    let longDescendingArray = Array.from({ length: LENGTH }, (x, i) => LENGTH - i - 1);
    let expectedOutput = makeLinkedList(...longDescendingArray);
    t.deepEqual(reverseLinkedList(input), expectedOutput);
});

Node fails with Maximum call stack size exceeded.

Iterative solutions are often equivalent to their recursive solutions, but this is one case where they're not. Ten thousand elements is a lot for a linked list, but it's not too much. A solution with just a loop wouldn't have this problem.

There's more about recursion limits in browsers here; the exact numbers don't matter so much — what matters is that there are linked lists that are longer than those numbers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.