ta7_8_solution

# ta7_8_solution - COMP 271H Design and Analysis of...

This preview shows pages 1–2. Sign up to view the full content.

COMP 271H Design and Analysis of Algorithms 2006 Fall Semester Tutorial 8 1. Consider the problem of examining a string x = x 1 x 2 . . . x n of characters from an alphabet on k symbols, and a multiplication table over this alphabet, and deciding whether or not it is possible to parenthesize x in such a way that the value of the resulting expression is σ , where σ belongs to the alphabet. The multiplication table is neither commutative nor associative, so the order of multiplication matters. For example, consider the following multiplication table the string bbbba . Parenthesizing it ( b ( bb ))( ba ) gives a , but (((( bb ) b ) b ) a ) gives c . a b c a a c c b a a b c c c c Give an algorithm, with running time polynomial in n and k , to decide whether such a parenthe- sization exists for a given string, multiplication table, and goal element. Analyze the running time of your algorithm. Possible solution: Let P [ i, j, σ ] be a boolean variable deﬁned as follow: P [ i, j, σ ] = true if there exists a way to parenthesize a sub-string of x = x i x 2 ...x j , resulting an expression equals to σ , where σ belogns to the alphabet on

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

ta7_8_solution - COMP 271H Design and Analysis of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online