Are there any worse sorting algorithms than Bogosort (a.k.a Monkey Sort)? [closed]

From David Morgan-Mar’s Esoteric Algorithms page: Intelligent Design Sort Introduction Intelligent design sort is a sorting algorithm based on the theory of intelligent design. Algorithm Description The probability of the original input list being in the exact order it’s in is 1/(n!). There is such a small likelihood of this that it’s clearly absurd to … Read more

How does finding a cycle start node in a cycle linked list work?

Let me try to clarify the cycle detection algorithm that is provided at Wikipedia – Tortoise_and_hare in my own words. How it works Let’s have a tortoise and a hare (name of the pointers) pointing to the beginning of the list with a cycle, as in the diagram above. Let’s hypothesize that if we move … Read more

Performing Breadth First Search recursively

(I’m assuming that this is just some kind of thought exercise, or even a trick homework/interview question, but I suppose I could imagine some bizarre scenario where you’re not allowed any heap space for some reason [some really bad custom memory manager? some bizarre runtime/OS issues?] while you still have access to the stack…) Breadth-first … Read more

What are the mathematical/computational principles behind this game?

Finite Projective Geometries The axioms of projective (plane) geometry are slightly different than the Euclidean geometry: Every two points have exactly one line that passes through them (this is the same). Every two lines meet in exactly one point (this is a bit different from Euclid). Now, add “finite” into the soup and you have … Read more

Non-recursive depth first search algorithm [closed]

DFS: list nodes_to_visit = {root}; while( nodes_to_visit isn’t empty ) { currentnode = nodes_to_visit.take_first(); nodes_to_visit.prepend( currentnode.children ); //do something } BFS: list nodes_to_visit = {root}; while( nodes_to_visit isn’t empty ) { currentnode = nodes_to_visit.take_first(); nodes_to_visit.append( currentnode.children ); //do something } The symmetry of the two is quite cool. Update: As pointed out, take_first() removes and … Read more

Difference between Divide and Conquer Algo and Dynamic Programming

Divide and Conquer Divide and Conquer works by dividing the problem into sub-problems, conquer each sub-problem recursively and combine these solutions. Dynamic Programming Dynamic Programming is a technique for solving problems with overlapping subproblems. Each sub-problem is solved only once and the result of each sub-problem is stored in a table ( generally implemented as … Read more