Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 9th, 2008, 05:01 PM
danooo danooo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 2 danooo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 50 m 20 sec
Reputation Power: 0
Text-shrinking algorithm using dynamic programming

Hi,

I am new to this forum and I desperately need an idea of how to solve the following task:

"Write an algorithm which shriks an input string of characters. The shrinking operation consists of replacing a substring "sub" repeated k-times with the following string: k[sub]. The output string has to be the SHORTEST string possible. I should use dynamic programming"

example of an input: "daaaaaaabcaaaaaaabc"
output: "d2[7[a]bc]"

As I said, I am desperated. The biggest hitch is that the resulting string has to be the shortest possible. I tried to think of an idea of how the algorithm should work but i wasn't successful. Most of the ressources I found on the web focus on compression, Huffmal, Ziv-Lempel codes or LCS.

Please help!

Reply With Quote
  #2  
Old April 9th, 2008, 05:42 PM
jwdonahue jwdonahue is offline
Bellevue WA, USA
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2004
Location: Bellevue Washington, USA
Posts: 1,038 jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level)jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level)jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level)jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level)jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level)jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level)jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 6 Days 23 h 14 m 51 sec
Reputation Power: 66
There's a couple of ways to approach this. You could try to find the longest sequences that repeat in the string first and then the next longest (that aren't part of the longer repeating sections). Or you could perform the encoding based on the shortest repeating parts first and then repeatedly run the result back through the algorithm until it stops shrinking. Hmm...

Since you're using brackets [] in the encoding you should consider whether they might also be part of the source string. If so, you will have to "escape" those characters in the encoding.

What about digits? Are those legal source string characters?

First start with the simplifying assumption that all you have to deal with are lower case alpha characters a..z. Then build up from there.
__________________
It's not always a matter of what you can do with a language, but whether you should. [JwD]

Reply With Quote
  #3  
Old April 10th, 2008, 08:15 AM
danooo danooo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 2 danooo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 50 m 20 sec
Reputation Power: 0
"Or you could perform the encoding based on the shortest repeating parts first and then repeatedly run the result back through the algorithm until it stops shrinking"

That`s a good idea, and it looks like dynamic programming as well. I will look into this concept.

The input string consists only of lowercase alpha characters "a"-"z".
I the output string, each character (digits, "[" and "]" brackets and letters) counts, so the two output strings:
15[a]bc10[a]bc
and
5[a]2[10[a]bc]

are both the best solution for the input:
aaaaaaaaaaaaaaabcaaaaaaaaaabc

Reply With Quote
  #4  
Old May 5th, 2008, 05:47 AM
Peter_APIIT Peter_APIIT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 22 Peter_APIIT Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 40 m 10 sec
Reputation Power: 0
This is a run length encoding algorithm and not dynamic programming,

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Text-shrinking algorithm using dynamic programming


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT