Factorial
Last updated
What is Factorial?
Factorial complexity algorithms have a runtime of O(n!). This is the worst case scenario for an algorithm. Factorial complexity algorithms are very inefficient and should be avoided.
def generate_permutations(s):
# Base case: If the string length is 1, return a list containing the string
if len(s) == 1:
return [s]
# Initialize the result list
permutations = []
# Recursively generate all permutations
for i in range(len(s)):
# Current character
current_char = s[i]
# Remaining characters
remaining_chars = s[:i] + s[i + 1 :]
# Generate all permutations of the remaining characters
for perm in generate_permutations(remaining_chars):
# Add the current character to the front of each generated permutation
permutations.append(current_char + perm)
return permutations
Free resources to learn Factorial
More in stage 3: Asymptotic Notation
Factorial: common questions
Can I learn Factorial in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Factorial in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this Factorial tutorial for beginners?
It is lesson 33 of 188 in the free Computer Science roadmap, in stage 3, Asymptotic Notation. If you are new to Computer Science, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.