Algorithms (CSCI 3104, Spring 2015)

Algorithmics Challenge

Challenge Problems

These are fun problems that are posted every 10 days or so to help people work on fun and challenging problems relating to algorithms.

  • The problems are generally harder than the regular class problems.

  • Solutions including partial solutions can be sent directly to Sriram.

  • These problems do not carry any credit. They are purely for fun, if you find them so.

  • The first priority is doing the course work for your grade: attempt these problems only after you have solved the regular class problems.

  • Course staff will generally not provide help with these problems since the actual coursework and students who need help with them takes priority.

  • Each week a small reward will be given to the first student(s) who solve this problem successfully.

Week # 1: Palindrome Splitting Challenge (Prof. John Black)

Deadline for Solutions Friday Jan. 30, 2015.

Palindrome

A palindrome is a string that reads the same forwards as well as backwards.

  • “abcccba”, “abba”, “aaaaaaabbcbbaaaaaaaa”, and “ablewasiereisawelba”.

  • A single letter string is trivially considered a palindrone.

Input

We are input a string eg., “abbaadaarbra”

Output

Split the string into the smallest number of palindromes possible:

  • No part of the string should be left out, duplicated or reordered.

  • Report the number of palindromes in your split, and the split, as well.

Examples

Eg., “abbaadaarbra” = “abba” + “ ada” + “arbra” splits into 3 palindromes.

Another example:

“ababbab” can be split as “aba” +“b” + “bab” into 3 palindromes.

However, it can also be split as “a” + “babbab” into 2 palindromes.

However, the latter split involves a smaller number of palindromes than the former and is therefore the correct answer.

Instructions

Write a simple recursive implementation.

Report on the results for the following input strings:

  1. abbababaaabaababababababaaababbbb

  2. abbacccdabaeabadcccabddfddbacccdab

  3. ggaccttggaccccggcaaagcggagagaccggtaataat

  4. cggtaataatggaccttggaccccggcaaagcggagagac

  5. abaabaaaabaaaaabaaaaaaabaaaaaabbbbbabbbbaaaaaabbbbbaababancababaabababbacabbbbababcbaabcbbac

  6. ACAAGATGCCATTGTCCCCCGGCCTCCTGCTGCTGCTGCTCTCCGGGGCCACGGCCACCGCTGCCCTGCCCCTGGAGGGTGGCCCCACCGGCCGAGACAGCGAGCATATGCAGGAAGCGGCAGGAATAAGGAAAAGCAGCCTCCTGACTTTCCTCGCTTGGTGGTTTGAGTGGACCTCCCAGGCCAGTGCCGGGCCCCTCATAGGAGAGGAAGCTCGGGAGGTGGCCAGGCGGCAGGAAGGCGCACCCCCCCAGCAATCCGCGCGCCGGGACAGAATGCCCTGCAGGAACTTCTTCTGGAAGACCTTCTCCTCCTGCAAATAAAACCTCACCCATGAATGCTCACGCAAGTTTAATTACAGACCTGAA

  7. TTGATTACCTTATTTGATCATTACACATTGTACGCTTGTGTCAAAATATCACATGTGCCTTATAAATGTGTACAACTATTAGTTATCCATAAAAATTAAAAATTAAAAAATCCGTAAAATGGTTTAAGCATTCAGCAGTGCTGATCTTTCTTAAATTATTTTTCTAATTTTGGAAAGAAAGCACAAAATCTTTGAATTCACAATTGCTTAAAGACTGAGGTTAACTTGCCAGTGGCAGGCTTGAGAGATGAGAGAACTAACGTCAGAGGATAGATGGTTTCTTGTACAAATAACACCCCCTTATGTATTGTTCTCCACCACCCCCGCCCAAAAAGCTACTCGACCTATGAAACAAATCACACTATGAGCACAGATAACCCCAGGCTTCAGGTCTGTAATCTGACTGTGGCCATCGGCAACCAGAAATGAGTTTCTTTCTAATCAGTCTTGCATCAGTCTCCAGTCATTCATATAAAGGAGCCCGGGGATGGGAGGATTCGCATTGCTCTTCAGCACCAGGGTTCTGGACAGCGCCCCAAGCAGGCAGCTGATCGCACGCCCCTTCCTCTCAATCTCCGCCAGCGCTGCTACTGCCCCTCTAGTACCCCCTGCTGCAGAGAAAGAATATTACACCGGGATCCATGCAGCCAGCAATGATGATGTTTTCCAGTAAATACTGGGCACGGAGAGGGTTTTCCCTGGATTCAGCAGTGCCCGAAGAGCATCAGCTACTTGGCAGCTCA

If possible, can you tell me what is the worst case running time of your solution?

Status

No solutions yet.