You are currently browsing the tag archive for the ‘permutation with repetition’ tag.

This applet program is much different from the previously posted applet programs.This applet program takes a string and gives the possible permutations with repetition of words and total number of permutations with repetition of words.

There are many ways to get permutation of a string with repetition of words, i have implemented it using the following algorithm :


 //This is Countdown Quick-Perm Algorithm:

   let a[] represent an arbitrary list of objects to permute
   let N equal the length of a[]
   create an integer array p[] of size N+1 to control the iteration     
   initialize p[0] to 0, p[1] to 1, p[2] to 2, ..., p[N] to N
   initialize index variable i to 1
   while (i < N) do {
      decrement p[i] by 1
      if i is odd, then let j = p[i] otherwise let j = 0
      swap(a[j], a[i])
      let i = 1
      while (p[i] is equal to 0) do {
         let p[i] = i
         increment i by 1
      } // end while (p[i] is equal to 0)
   } // end while (i < N)

If you are not clear with the above description try it yourself, the program is below:

Read the rest of this entry »

Blog Stats

  • 9,744 hits

My tweets

Follow me on twitter
Follow

Get every new post delivered to your Inbox.