Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Arda is an artist that loves to draw random patterns with ASCII characters in Notepad. One day, he noticed that his drawings have too many

Arda is an artist that loves to draw random patterns with ASCII characters in Notepad. One day, he noticed that his drawings have too many repeated characters, such that his hard drive cannot fit his portfolio. He decided to write a serialization algorithm to compress the file size. He found that each line of his drawings happens to be repeating some sub-patterns in certain order. Thus, he serializes the drawings to a list of all sub-patterns that occurred and the counts of consecutive occurrences in each line.

Example:

Suppose the line is OOOOAAABBOBBBBB, and patterns list is [AAA, B, O], the serialization algorithm will first look for the first pattern in patterns list (AAA), count until it meets a different pattern, and start look for the second pattern (B), etc. When the patterns list is exhausted, the algorithm wraps back to the first pattern. Thus, the count list for this line is generated like follows:

OOOOAAABBOBBBBB

-> [(AAA, 0), (B, 0), (O, 4), (AAA, 1), (B, 2), (O, 1), (AAA, 0), (B, 5)]

-> [0, 0, 4, 1, 2, 1, 0, 5]

def deserialize(outpath, patterns, *serialized_lines):

"""

>>> deserialize("outfiles/out1.txt", ["**", "Marina"],

... [1,1,1], [0,5], [3,3,0,3,3])

>>> with open("outfiles/out1.txt", "r") as outfile1:

... print(outfile1.read().strip())

**Marina**

MarinaMarinaMarinaMarinaMarina

******MarinaMarinaMarinaMarinaMarinaMarina******

"""

# YOUR CODE GOES HERE #

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

What are some of the more common applications of sprayed coatings?

Answered: 1 week ago

Question

1. Is it a topic you are interested in and know something about?

Answered: 1 week ago