News for hackers. Stuff that matters.
Re:Lampsort: Leslie Lamport's Non-recursive Quicksort by Cushman on Sunday December 07, 2014 @02:03PM (#8713160)
Watching the source lecture[0], it's not about how the code is written so much as how the function is specified. It's easier to describe quicksort as a few set equations without invoking the concept of recursion, but since we don't write code like that people can't get to it easily.

The nuts-and-bolts difference is in fact that it's a set and not a stack, but the underlying question is, why do we all treat the set implementation as the derived version?

[0] http://channel9.msdn.com/Events/Build/2014/3-642 ~35m

Re:Lampsort: Leslie Lamport's Non-recursive Quicksort by TheLoneWolfling on Sunday December 07, 2014 @04:36PM (#8713662)
> since we don't write code like that people can't get to it easily.

I've lately been trying to write code with no recursion - as in able to be implemented with each function having a variable indicating where to return to, no implicit stack in sight. (Statically-determinable stack size, to put it another way.)

It took me a bit to get the hang of, but I'd argue that it ends up being easier in the long run. Far easier to change the priority operator on your queue than trying to reason what behavior different orders of recursion get you, for example.

Ditto with graph search algorithms. It's enlightening to teach graph search algorithms as a single algorithm with a queue, where changing the priority gives you Dijkstra's algorithm (least cost first), DFS (LIFO), BFS (FIFO), A* (current cost + underestimating huristic of cost left), or whatever. Also easy to show that A* degenerates into Dijkstra's algorithm when you use a null heuristic (i.e. a heuristic that returns a constant) if you teach them as variants of the same algorithm.

Re:Lampsort: Leslie Lamport's Non-recursive Quicksort by badubu on Sunday December 07, 2014 @03:04PM (#8713368)
> but since we don't write code like that people can't get to it easily

which likely sums up what Lamport is trying to get across - express your work equationally, determine properties and generally understand what you're dealing with and then later, you can 'compile your equations' down to a particular implementation. from my own practice, i've found that it is much easier to reason about equations and reflect it down into code than to try and reason about the code