3 ms·
Is there an alike book that would provide functional implementations of the algorithms alongside or instead of imperative ones? In Python preferably but I don't
by qwerty456127 8y ago
Is there an alike book that would provide functional implementations of the algorithms alongside or instead of imperative ones? In Python preferably but I don't mind any other language. I would like to learn implementing algorithms and solving problems the functional way.
- Puer 8y agoElements of Programming Interviews in Python is excellent imo. The authors give a crash course in all of the data structures and all of the code is written extremely cleanly. Most of the problems give standard solutions and also idiomatic ones using iter/functools. I've been programming Python for years and felt like I gained a lot from it as a developer even though I bought it to interview prep. Quick example of the "look and say" problem: def look_and_say(n: int) -> str: s = '1' for _ in range(n - 1): s = ''.join( str(len(list(group))) + key for key, group in groupby(s)) return s
- ultrasounder 8y agoI am using this book for interview prep as well. Code is pythonic and a joy to read.
- mixedmath 8y agoI hadn't heard of this before, so I went and checked this out this morning. I haven't read too much, but I've liked what I saw. And I notice that there are java and C++ variants for those interested in those languages. Thank you for your suggestion.
- johntam 8y ago+1 for EPI. Using it now myself. It's great stuff.
- ummonk 8y agoA lot of imperative algorithms don't really have functional analogues. Sometimes you need to mutate in place to achieve optimal algorithmic complexity. That said, I think this might be what you're looking for: https://cs.uwaterloo.ca/~plragde/flaneries/FDS/ https://cs.uwaterloo.ca/~plragde/flaneries/FDS/
- qwerty456127 8y ago> A lot of imperative algorithms don't really have functional analogues. But there are to be the ways functional programmers solve the same task? Thank you for the link.
- disgruntledphd2 8y agoDefinitely. But unless special care is taken, these will use (normally) more space, and potentially more time. I think Chris Osaki did a bunch of work on functional data structures for handling immutability efficiently (still less efficiently) and that some of this was implemented in Clojure.
- ascar 8y agoFunctional programming is not supposed to be a golden hammer. That's the pragmatic solution for this problem ;).
- Puer 8y agoNice resource, thank you for sharing. It's been a why since I've used Ocaml but this will be a good opportunity to review.
- flafla2 8y agoYou can check out [1], which is used to teach 15-210 [2], the parallel data structures / algorithms course at CMU. The most recent version of the book is students-only it seems, on a private site (I took the course last semester), however this version is close and comprehensive. [1] http://www.parallel-algorithms-book.com http://www.parallel-algorithms-book.com [2] http://www.cs.cmu.edu/~15210 http://www.cs.cmu.edu/~15210
- scns 8y agohttps://github.com/liuxinyu95/AlgoXY https://github.com/liuxinyu95/AlgoXY In this book the author shows brute force, improved and functional implementations in python, c and haskell.