Devon
Devon

Reputation: 7

Coding algorithm to solve quasi palindromes based on specific swap parameters

For my computer science degree, I have a project where I must recognise strings that can be turned into palindromes (the word backwords is the same as the word forward such as "racecar". While this is easy, we have specific parameters. We have a minimum number of char swaps allowed as well as a max nr. We have a min jump length(how far a char can jump) as well as a max jump length. What sort of algorithm method would you suggest I use to solve it. I can definitely see how I could sort of hard code the solution using a huge amount of if statements but I want to learn more advanced techniques. One of my friends is using a tree where it checks all the possibilities and that you can do and then again, all the possibilities that that would allow etc. but we get marked for optimisation where everyones code gets compared to determine how fast your code is (there are 500 students). Also note a few smaller rules such as that if you have 2 available swaps you need to swap the one furthest left first so the swap order matters. Is there any theoretical way to do this where I can learn something new that will help me out in the future, where its not some random external lib that I will likely never use again. Thank you.

Upvotes: -1

Views: 74

Answers (0)

Related Questions