1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Serga [27]
3 years ago
13

A palindrome is a string of characters that is the same when reversed (e.g., ‘affa’). Single characters are palindromes. Suppose

you are given a string S of N characters and wish to produce an N-by-N matrix P, where P = 1 if i ≤ j and S[i,...,j] is a palindrome, and Pij = 0 otherwise.
(A) Matrix P can be computed using brute force by separately examining each substring of S and determining whether it is a palindrome. Describe this algorithm. What is the algorithm’s running time?
(B) It is possible to compute matrix P more efficiently using dynamic programming. Give a dynamic programming algorithm to compute P, and analyze its running time. (Hint: Begin by filling in the values along the diagonal of the matrix.)
Computers and Technology
1 answer:
Nina [5.8K]3 years ago
5 0

Answer:

Check the explanation

Explanation:

a) This done can be executed through the use of brute force by the given algorithm: Consider any two indices i and j then we can check if string from s[i....j] is palindrome or not in O(L) where L is length of string.

Algorithm to check if string is palindrome :

Takes String s as argument and the two indices i,j between which the string is to be considered

bool palindromeCheck(s,i,j) :

        y = j

        for x in range(i,j) :

             if(s[x]==s[y]) :

                      y--

                      continue

            else :

                      return false

       return true

Now taking a look at the  part a) we will be calling the function to confirm and execute palindrome for all i<=j that is a total of points of the order of O(n^2) and the string checking will take O(n) in the worst case making it O(n^3).

b) To advance over we became aware of the fact that repeated calculation is being done i.e when we confirmed the string s[i...j] we also tested in between strings like s[i+1,j-1] etc in the same time. Consequently we used memorization to store the outcome that we calculate and reuse them we need them later.

We know that P[i][i] will always be one since a single character string will always be a palindrome.

Using this as our base case to check for P[i][j] we need to check if the ith and the jth character are equal and also if P[i+1][j-1] is true i.e is a palindrome.

We come up with the following recurrence

P[i][j] = 1 if i=j

P[i][j] = P[i+1][j-1] ; if i>=j and s[i]==s[j]

            0; otherwise

There are order of O(n^2) states and each one of the state necessitates only constant and regular time character checking for its evaluation and then assigning the value of 1, P[i+1][j-1],0 as a result of that which is again a constant time operation. Therefore all the P[][] matrix values can be found in O(n^2) time.

Pseudo code :

Let n be the length of the string

for x in range(1,n) :

        P[x][x]=1

for sz in range(2,n) : # Since we have already computed answer for string of size 1

        for x in range (1,n-sz+1):

                   y=x+sz - 1

                   if x == y :

                            if sz==2 :

                                      P[x][y] = 1

                            else :

                                      P[x][y] = P[x+1][y-1]

                  else :

                            P[x][y] = 0

From the implementation also it is clear that the running time of the algorithm is O(n^2).

You might be interested in
DSSS uses a chipping code to encode redundant data into the modulated signal. Which two of the following are examples of chippin
Schach [20]

Answer:

Option A and Option D

Explanation:

5 0
4 years ago
100 POINTS + BRAINLYEST FOR FIRST PERSON THAT GETS IT RIGHT!!!! While writing a formula, what are some ways to insert a cell ref
nexus9112 [7]

Answer:

Line second and third i.e, "typing the cell name, like "B4"  and clicking the cell to reference " the correct answer.

Explanation:

It relates to some kind of set of cells on the worksheet, which could be used to calculates the formula. It also helps to locate the information, which you want to analyze in the calculation. It can also provide the cell reference in  more than one formula in the same worksheet, that relates to Information on many other workbooks, and wrong choices can be described as follows:

  • Hovering provides the basic details, in which we hover, that's why it is wrong .
  • Zooming is used in projection, it can't be used in the cell reference, that's why it is wrong.
7 0
4 years ago
Read 2 more answers
When configuring an adsl installation where should you to install the dsl filters?
xxTIMURxx [149]

<span>Filter installation in ADSL setup, the DSL filters should on connections leading to an analog phone. The DSL modem and phone were share on the same jack. ADSL is a type of digital subscriber line machinery, a data communication that enables faster data transfer over copper telephone lines.</span>

5 0
3 years ago
CREIDT INAOCT Unscramble thr word<br>please solve it fast its urgent ​
ivanzaharov [21]

Answer:

Credit Action .......I believe

6 0
3 years ago
It is important to analyze the sources and uses of cash because:___.
sergey [27]

It is important to analyze the sources and uses of cash because creditors use this information to assist them in deciding whether to loan funds to them. Investors use this information to decide if they will purchase their stock.

Managing your revenue is an important step to starting or investing in something.

Creditors always check and properly analyze the sources of cash before providing a loan to a lender. They do not invest in companies or people who are least likely to source and make cash in the coming time. Hence, your sources and uses shall be properly analyzed when presenting to creditors.

Investors, whenever investing in something will look at the benefits of the source they want to invest into. If a source is not likely to produce beneficiary revenue in the upcoming time, then investors will never invest in such a kind of source.

To learn more about investors, click here:

brainly.com/question/25311149

#SPJ4

5 0
2 years ago
Other questions:
  • The list below shows the number of text messages that five students sent from
    9·1 answer
  • Function Integer cube(Integer num) Return num * num * num End Function Write a main module that contains a statement that passes
    11·1 answer
  • 22. A user receives an error message when logging into Salesforce. What is the first check performed by an administrator?
    8·1 answer
  • Out of a list of the values 2, 45, 18, 22, 8, and 37, what result would the MAX function return?
    14·2 answers
  • What does the internet engineering task force (IEFT) do?
    5·1 answer
  • If two egg cells are fertilized what will happen?
    10·1 answer
  • You are in the windows power shell window and decide to encrypt folder which of the following command do you use
    7·1 answer
  • You can add additional design elements to a picture by adding a color background, which is accomplished by using what Paint feat
    12·1 answer
  • Write a python program that should determine from the range you choose to enter :
    9·1 answer
  • You have a host device with an assigned IP address of 192.168.15.100 and a subnet mask of 255.255.255.192. To what network does
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!