Question: Write a Racket program to define the following functions x : list value: list of lists description generate all permutations of the original list value
Write a Racket program to define the following functions


x : list value: list of lists description generate all permutations of the original list value is the list of lists of all permutations Examples Skeleton (define (permute x ) (cond ((empty? x) null) ((empty? (cdr x)) (list x)) ((empty? (cddr x)) (list x( reverse x))) (else (ph-2 x(( length x ) 1))) 1 ) For the else case, see discussion below on defining helper functions ph-1 and ph- (ph1n) find th element of x find x minus nth element cons-to-all nth element to value of permute x minus nth element note that ph-1 calls permute, but it doesn't call itself (ph-1 is not directly recursive) (ph2n) evaluate ph-1 for all positions in the list 0 through length 1 append all resulting lists into final list The general case for the permute function is then to call ph-2 - permute calls ph-2 - ph-2 calls ph-1 - ph-1 calls permute (on a smaller version of the original list)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
