Question: [20 points) Problem 8 Write a non-recursive method of the_gen_perms method by creating a call stack and simulating the creation and deletion of activation records

[20 points) Problem 8 Write a non-recursive method of the_gen_perms method by creating a call stack and simulating the creation and deletion of activation records [] def get_perms(nums): all_perms = [] _gen_perms (pending_nums-nums, curr_perm=[], all_permsall_perms) return all_perms def gen_perms (pending_nums, curr_perm, all_perms): # check if list pending_nums is empty; curr_permutation is complete if not pending_nums: all_perms.append(curr_perm) else: # iterate over all possible options to continue the generation of curr_perm for i in range(len (pending_nums)): # add pending_nums[i] to the permutation we are currently generating extended_perm curr_perm.copy) extended_perm.append(pending_nums[i]) # remove pending_nums[i] before making a recursive call since that item # is already included in the permutation being generated itr_pending_nums = pending_nums[:i] + pending_nums [i+1:] _gen_perms (pending_nums-itr_pending_nums, curr_perm=extended_perm, all_perms=all_perms) def gen_perms_non_recursive (pending_nums, curr_perm, all_perms): # YOUR CODE GOES HERE return
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
