ta7_8_question - { d 1 , d 2 , . . . , d k } units. They...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
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. 2. Consider a country whose coins are minted with denominations of
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { d 1 , d 2 , . . . , d k } units. They seek an algorithm that will enable them to make change of n units using the minimum number of coins. You may assume that d 1 = 1, so it is always possible to make change for any n . (a) The greedy algorithm for making change repeatedly uses the biggest coin smaller than the amount to be changed until it is zero. Show that the greedy algorithm does not always give the minimum number of coins in a country whose denominations are { 1 , 6 , 10 } . (b) Give an O ( nk ) time algorithm that correctly determines the minimum number of coins needed to make change of n units using denominations { d 1 , d 2 , . . . , d k } . Justify the correctness and running time of your algorithm. c ± 2006 Chung Kai Lun Peter. Comments are welcomed. Email: cspeter@cse.ust.hk 1...
View Full Document

Ask a homework question - tutors are online