U GOTTA Chek tis out!!!

Saturday, December 4, 2010

johnson trotter algorithm to ma rescue:P:)...

I was askin 1 of ma friends whos studyn in 4th year at RVCE as to how his placements were goin on...he tol tat yahoo,microsoft etc had already visited tem...wen i quizzed him abt the questions tey had ased in the interviews...he was left clueless;)..well prety ovz situation considerin hes not too gud at computers:P

howeva he recalled 1 of the questions ...which was pretty simple(considerin the fact tat i had teh MAGIC algorithm wit me:P) acc to me..
the ques was...  :  TO permutate 'n' values or 'n' user inputs...in 'n' diff ways...

acc to me the best way to solve the problem is usin the johnson trotter algo..
johnson trotter algorithm gives a non recursive approach to generate permutations. The algorithm goes something like this..

while there exists a mobile integer k do
-->find the largest mobile integer k;
-->swap k and the adjacent integer, its arrow points to;
-->reverse the direction of all integers that are larger than k
for eg:if the user inputs the n value as 3..
the followin will b the programs compilation ..
<1  <2  <3
<1  <3  <2
<3  <1  <2
 3> <2  <1
<2   3> <1
<2  <1  3>


I'm using a character flag to maintain the direction of the mobile integers.. the code is simple:)..
try it:)..
il post the code in a few days..until ten keep tryin:)

3 comments:

  1. wow man..
    thnks a tonne fo postin such useful info..
    way to go..
    ure sure to get in2 MS o GOOGLE!keep it up..amazin bro..

    ReplyDelete
  2. nice logic man just saw it rit now it was really interesting i will try it soon . well now im off t paty :D thanks for giving me n insite man appreciate it :)

    ReplyDelete
  3. Thank u man:)..

    do try it..il b more tan happy:)

    ReplyDelete