Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

String compression algorithms

Featured Replies

Posted

String compression algorithms:

1. First simple algorithm:

Input string "Acccc";

We store first 2 chars "Ac" +

a char:

- first bit should be set whit 1 for marking that we have a compression here

- rest of bits will filled whit numbers of duplicates - under this case 3

"Acccc" -> Ac[3]

2. Second algorithm:

Input string "the Udrea, the Basescu";

* We store "the Udrea, " +

First char:

- first bit should be set whit 1 for marking that we have a compression here

- rest of bits will filled whit the lenght of duplicate string - under this case

Second char:

- all bits should contain the position from where to take the string - under this case 11

"the Udrea, the Basescu" -> "the Udrea, [11,3] Basescu"

Edited by CodeRipper

I think most of us already though of the first algo. You can even make it shorter by removing the second bracket.

Ac$3 for instance where $ is the indicator.

I ran some tests with it and you barely save any space (unless whitespace).

what about huffman :^

If you just use one separator you cant have strings like Accccc123 because that makes Ac$5123

A + 5123 times c

Not really what you intended

And yeah, none of these really beat Huffman unless you have something like 5000 of the same character

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.