#TodaysNondeterministicAlgorithm
#TodaysNondeterministicAlgorithm solves the subset sum problem: is there a subset of S having sum k? This one shows a standard “design pattern” for nondeterministic algorithms: for each element of the set S, you just guess if you’re taking it or not, then check if you were right.
November 26, 2024 at 10:07 AM
I’ve released version 3.1.1 of the nondeterminism Python library (as a reminder, you can now “pip install nondeterminism” and much better documentation is available). See #TodaysNondeterministicAlgorithm for a few examples (watch out for the API updates). github.com/aeporreca/no...
GitHub - aeporreca/nondeterminism: A Python library for nondeterministic algorithms
A Python library for nondeterministic algorithms. Contribute to aeporreca/nondeterminism development by creating an account on GitHub.
github.com
December 16, 2024 at 5:07 PM
Oooh yesss thank you! That’s really interesting and particularly relevant to this #TodaysNondeterministicAlgorithm thing (I’m looking for short, cool algorithms to present later this year at a seminar for master’s student interns, PhD students and colleagues). I see a few interesting examples there!
December 2, 2024 at 8:16 AM
#TodaysNondeterministicAlgorithm is Lucky Search! Tired of waiting O(n) time for a linear search? Don’t even have O(log n) time for a binary search? Well, why don’t you just guess where the element is in your array straight on your first try?
November 20, 2024 at 7:39 PM
Shortest paths in graphs are so easy. 😴 OTOH, longest simple paths are NP-hard! #TodaysNondeterministicAlgorithm finds them by using “maximising guesses” (freshly added to the nondeterminism library). You can solve all your OptP problems (complexityzoo.net/Complexity_Z...) this way!
December 3, 2024 at 2:40 PM
#TodaysNondeterministicAlgorithm is actually 5! The same code (guess & eval a logic formula) can be executed in deterministic (take the first answer), nondeterministic (a *positive* answer), conondeterministic (a negative answer), counting (the positive answers) or majority mode.
November 28, 2024 at 6:40 AM
#TodaysNondeterministicAlgorithm solves the longest common subsequence problem (en.wikipedia.org/wiki/Longest...) which is of interest in bioinformatics (and computational linguistics? and more). This is easy for two (or any fixed no. of) sequences, but NP-hard if the number is variable.
December 6, 2024 at 8:39 AM
#TodaysNondeterministicAlgorithm checks if a… nondeterministic finite automaton N (this definition en.wikipedia.org/wiki/Nondete..., without ε moves for simplicity) accepts a string x. Then, by using Python generators, you can lazily construct the whole (possibly infinite) language of N.
November 30, 2024 at 8:01 AM
#TodaysNondeterministicAlgorithm shows that you don’t need binary trees to be “search” if you have nondeterminism. Just guess correctly if you need to go left or right! (You still need them balanced though, if you want that sweet O(log n) runtime.)
November 25, 2024 at 6:42 AM
#TodaysNondeterministicAlgorithm computes spanning trees! Just guess a subgraph and check if it’s a tree! (The is_connected algorithm is chosen for its coolness, not because it’s the most efficient.)
November 27, 2024 at 7:59 AM
#TodaysNondeterministicAlgorithm checks if a string is an anagram another! Just guess a permutation of one of them, compare the result with the other, and in at least one possible universe you will get True if and only if it’s indeed an anagram!
November 22, 2024 at 8:45 AM
Shorter version of #TodaysNondeterministicAlgorithm using set comprehensions!
November 26, 2024 at 12:40 PM
#TodaysNondeterministicAlgorithm I’ve already published, but it’s Saturday so it’s OK. It’s a SAT solver in 5 lines of Python! The trick is to use a defaultdict (docs.python.org/3/library/co...) for the assignment: the first time you access a variable, its value is guessed automatically.
November 23, 2024 at 8:17 AM
#TodaysNondeterministicAlgorithm is reachability in directed graphs! This one is better than any known deterministic algorithm in terms of auxiliary space complexity, only O(log n) rather than linear (en.wikipedia.org/wiki/St-conn...)! As a bonus, a version that actually outputs the path.
November 29, 2024 at 9:07 AM
Nondeterminism allows you to write a comparison-based sorting algorithm that only makes n − 1 comparisons, like #TodaysNondeterministicAlgorithm! This is mathematically impossible for a deterministic algorithm, which need Ω(n log n) comparisons (en.wikipedia.org/wiki/Compari...).
December 5, 2024 at 6:36 AM
The paper “Which Problems Have Strongly Exponential Complexity?” by Impagliazzo, Paturi and Zane seems to contain all the details I need in order to discuss the number of nondeterministic bits in #TodaysNondeterministicAlgorithm for some NP-complete problems (notably 3SAT vs CLIQUE). 📌
December 4, 2024 at 8:24 AM
#TodaysNondeterministicAlgorithm is one of the examples for the nondeterminism library, but hey, it’s Sunday (and it’s slightly nicer this way). A natural number is composite if it has a proper divisor (≤ √n, if we want to optimise) and a prime is just a non-composite n > 1.
November 24, 2024 at 8:13 AM
#TodaysNondeterministicAlgorithm checks if two graphs are isomorphic, which is hard (but possibly not NP-complete, en.wikipedia.org/wiki/Graph_i...). Two graphs G, H given as adjacency matrices are isomorphic iff there exists a permutation matrix P (which we can guess) such that PG = HP.
December 2, 2024 at 7:57 AM
#TodaysNondeterministicAlgorithm is more powerful than usual (under standard complexity theory assumptions) 💪! We use alternation (en.wikipedia.org/wiki/Alterna...) here, with the standard guess(mode=Or) and conjunctive guess(mode=And) in order to evaluate quantified Boolean formulae!
December 1, 2024 at 6:26 PM
#TodaysNondeterministicAlgorithm is for k-colouring graphs! You just guess a colour for each vertex and then check if connected ones have different colours; if not… you just give up! 🤷‍♂️ Who cares? Another computation will guess the right colouring! (That is, if it exists!)
November 21, 2024 at 2:00 PM
This week I’ve inaugurated a #TodaysNondeterministicAlgorithm “column” with Python code on Twitter (x.com/search?q=%23...) and Bluesky (bsky.app/hashtag/Toda...), both for fun and because I need examples for a future seminar talk. There are already 5 entries, with more coming!
November 24, 2024 at 10:49 AM
#TodaysNondeterministicAlgorithm checks if G has a clique (complete subgraph) with size vertices. This is NP-complete but, unlike other NPC problems like 3SAT, you only need √n nondet bits (n = |V²|), which is o(n), while 3SAT needs Ω(n) assuming ETH (en.wikipedia.org/wiki/Exponen...).
December 4, 2024 at 11:16 AM