Tessellate S.T.E.M.S - Computer Science - School - Set 1 - Subjective Problem

You are given a string comprised of symbols a and b. You have to perform certain operations on it.

In each operation, you must select an occurrence of the substring ab in the string and replace it with bba. You must keep doing such operations until there is no occurrence of the string ab.

The task for this problem is to: Give an algorithm, whose input is such a string, and which computes the minimum number of operations until the string is free of occurrences of ab.


This problem is a part of Tessellate S.T.E.M.S.

Note by Agnishom Chattopadhyay
10 months ago

No vote yet
1 vote

  Easy Math Editor

MarkdownAppears as
*italics* or _italics_ italics
**bold** or __bold__ bold

- bulleted
- list

  • bulleted
  • list

1. numbered
2. list

  1. numbered
  2. list
Note: you must add a full line of space before and after lists for them to show up correctly
paragraph 1

paragraph 2

paragraph 1

paragraph 2

[example link](https://brilliant.org)example link
> This is a quote
This is a quote
    # I indented these lines
    # 4 spaces, and now they show
    # up as a code block.

    print "hello world"
# I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
MathAppears as
Remember to wrap math in \( ... \) or \[ ... \] to ensure proper formatting.
2 \times 3 \( 2 \times 3 \)
2^{34} \( 2^{34} \)
a_{i-1} \( a_{i-1} \)
\frac{2}{3} \( \frac{2}{3} \)
\sqrt{2} \( \sqrt{2} \)
\sum_{i=1}^3 \( \sum_{i=1}^3 \)
\sin \theta \( \sin \theta \)
\boxed{123} \( \boxed{123} \)

Comments

Sort by:

Top Newest

What is the answer

Niranjan Sarode - 9 months, 1 week ago

Log in to reply

Algorithim !!!!

Dipankar Dutta - 9 months, 1 week ago

Log in to reply

can the algorithm be a computer code of c++ format like with for loops and while loops and array along with basic string functions

Binit Kumar Mondal - 9 months, 1 week ago

Log in to reply

– You are expected to describe the algorithm, possibly in the form of a pseudo-code, and describe why it is correct. Also, analyze the performance of the algorithm.

Agnishom Chattopadhyay

Vatsal Sharma - 9 months, 1 week ago

Log in to reply

1: str= stored string 2: str1="" 3: i=0 4: f=0 5: while (i< length of str) 6: c= character of str at i th position 7: if (c='a') f=f+1 8: elseif (c='b' and f>0) str1=str1+"bb" 9: elseif (c not equal to 'b' and f>0) str1=str1+'a', f=0 10: if (c not = 'a' or c not = 'b') str1=str1+c 11: i=i+1 12: end of while loop 13: return str1

Debayan Ganguly - 9 months, 1 week ago

Log in to reply

What should be the time complexity of the solution?

Vatsal Sharma - 10 months ago

Log in to reply

Try coming up with the best solution that you can :)

Agnishom Chattopadhyay Staff - 10 months ago

Log in to reply

How do we need to answer above question? Write theory explaining the stuff or the pseudocode?

Vatsal Sharma - 10 months ago

Log in to reply

@Vatsal Sharma You are expected to describe the algorithm, possibly in the form of a pseudo-code, and describe why it is correct. Also, analyze the performance of the algorithm.

Agnishom Chattopadhyay Staff - 10 months ago

Log in to reply

@Agnishom Chattopadhyay So will you allot non-binary scores on subjective task according to the answer's quality? Proving the algorithm(sometimes greedy) is sometimes hard.

Vatsal Sharma - 10 months ago

Log in to reply

@Vatsal Sharma

So will you allot non-binary scores on subjective task according to the answer's quality?

Yes. I will check with the organizers and clarify this point.

Proving the algorithm(sometimes greedy) is sometimes hard.

I agree. However, if an algorithm designer does not prove his algorithm, how does one know that what he has proposed really does what we want it to? That said, a next best thing to a proof would be some kind of heuristic justification of why you'd think that the algorithm is correct.

Agnishom Chattopadhyay Staff - 10 months ago

Log in to reply

@Agnishom Chattopadhyay "Hard problems make people think, and once in a while, it's not a horrible thing to think" - Vikraman Balaji

We stand by Balaji's words and believe that it is only through hard problems that one can assess understanding. Please give your best to the response. There will be points for the approach and the solution, and not just the answer.

Thank you On behalf of S.T.E.M.S Aalok

Aalok Thakkar - 10 months ago

Log in to reply

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
1: str= stored string
2: str1=""
3: i=0
4: f=0
5: while (i< length of str)
6: c= character of str at i th position 
7: if (c='a') f=f+1
8: elseif (c='b' and f>0) str1=str1+"bb" 
9: elseif (c not equal to 'b' and f>0) 
                 str1=str1+'a',    f=0
10: if (c not = 'a' or c not = 'b') 
               str1=str1+c
11: i=i+1
12: end of while loop
13: return str1 

Debayan Ganguly - 9 months, 1 week ago

Log in to reply

if any flaw please reply

Debayan Ganguly - 9 months, 1 week ago

Log in to reply

The logic is that check the number of b's after a and then replace 2x number of b's before a removing those b's

Debayan Ganguly - 9 months, 1 week ago

Log in to reply

×

Problem Loading...

Note Loading...

Set Loading...