2ndweekassignment 1
2ndweekassignment 1
0.1 Question 1:
i) Write a program on the Fibonacci series in Python using the native approach.
1
print(fibonacci_recursive(i))
2
2. These smaller subproblems are solved repeatedly in a recursive approach, leading to expo-
nential time complexity.
3. DP addresses this issue by solving each subproblem once and storing its result for future use
1 Question 2
• Write a Python program to print all permutations of a given string
[7]: def permute_string(input_string, current_permutation):
if len(input_string) == 0:
print(current_permutation, end=" ")
return
for i in range(len(input_string)):
character = input_string[i]
left_substr = input_string[:i]
right_substr = input_string[i + 1:]
remaining = left_substr + right_substr
permute_string(remaining, current_permutation + character)
2 Question 3
• Write a Python program to check prime number
[8]: def check_prime(n):
if n <= 1:
return False
is_prime = True
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
is_prime = False
break
return is_prime
[11]: check_prime(11)
3
[11]: True