How are You all?
I guess everyone’s mind is stressed now for a bloody long vacation.However I gotta post here
just to share one thrilling code with you.Infact I couldn’t but inform it all of you.Everyone knows
that we were given a assignment by Rasel Sir on typical Permutation algorithm such as to remove repetition
,to sort lexicographically etc.Might be some of us solved it,but with different algo for all specific task.
I also solved it but had used different algo for different task.I even surfed through net to find out such a code
,maybe for my inexperience how to search diligently,I failed to manage it.However I managed it myself few days
ago in this damn vacation(Im confused!!was it really damn vacation??:P)Though we know STL’s “next_permutation”
do this job perfectly,I find two flaw there.
1)It takes much time even than of mine!! 2)It’s a relative flaw of STL(Plz Recall that I said Relative)is that
somehow its odd to use STL without knowing How it works.
Well..I don’t want to stretch my introduction more..Here directly code goes:
int cmp(const void *a,const void *b)
void check(long how)
char pr=’-’; //This for switching off the repetition
And short analysis on this code goes here:
First of all,I wanna say my ability of analysing algo is poor even if it’s my own algo!!
As Far my ability,What I got is that Max depth of Recursion of above code is “Length of String”.
Let, Max depth=N and in each depth loop runs N time each making it a exponential algorithm
of like N^N.
For The string of length 11:”abcdefghijk” it takes almost 7.81 sec in Intel Dual core 2.20GHz Pc
whereas for same string STL takes 9.37 sec in same PC.(Time measured without printing results)
…Hope friends you might find it useful for ACM solving and you will notify me my errors and suggest
how to develop it..
Sayem Mohammad Imtiaz
CUET CSE 08