Question: implement this recursive algorithm to build a truth table in python input = number of variables output = a list of lists containing all possible
implement this recursive algorithm to build a truth table in python
input = number of variables
output = a list of lists containing all possible combinations
Base case: For a single variable, the list of all combinations is [ [True], [False] ]
Recursive case: each element in the list (which is itself a list), is replaced with two lists, one with True appended to it, and one with False appended to it.
example output for 3 variables : [[True, True, True], [True, True, False], [True, False, True], [True, False, False], [False, True, True], [False, True, False], [False, False, True], [False, False, False]]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
