Optimization options: 1. Don't double the string length. You can use the mod operator (might or might not be an optimization - profile and see). 2. Work only with indices. There is no need to create a reference to a slice of the string during each loop pass that checks the "if" condition. That statement might be creating a copy of the string (I don't know if psyco does copy on write for substrings). Besides, you only need the index of the string. 3. There's a reference to the string slice created inside the loop too. You really don't need the reference if you're storing the index value.
You could also look at simple optimizations like checking if the next character is smaller than the current one, so skipping the testing of the substring as the next one is guaranteed to be a better candidate. Hope this helps. -- DK http://twitter.com/divyekapoor http://www.divye.in -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/simQ8C9YCocJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
