cs6515Exam1Prep Knapsackwithoutrepetition-ANSWER-k(0)=0
forw=1toW:
ifw_j>w:k(w,j)=k(w,j-1)
else:K(w,j)=max{K(w,j-1),K(w-w_j,j-1)+v_i}
knapsackwithrepetition-ANSWER-knapsackrepeat(w_i....w_n,w_i...w_n,B) k(0)=0 fori=1ton ifw_i<=b&k(b)
fori=0ton:L(i,0)=0
forj=0ton:L(0,j)=0
fori=1ton forj=1ton
ifX_i==Y_j:
L(i,j)=L(i-1,j-1)+1
else:
L(i,j)=max(L(i-1,j),L(i,j-1) return(L(i,j) 1 / 2
longestcommonsubstring-ANSWER- whatisBigohofLCS?-ANSWER-O(n**2) whatisbigOhoflongestcommonsubstring?-ANSWER-O(mn) whatisimportanttorememberwhencalculatinglongestcommonsubsequence asopposedtosubstring?-ANSWER-substringisverydiagonalandplus1 subsequenceyouhavetouseamaxfunction
Performlongestcommonsubstringandsubsequenceon:
"abcdaf" "3bcdf" Whataretherecurrences?writedownthealgorithmandresults-ANSWER- ifyouarepresentedwithacoins(1,5,6,8)andyourknapsackisk=11,whatis theminimumnumberofcoins,whatwouldbethecomputationaltime,andwhat
istherecurrence?-ANSWER-https://www.youtube.com/watch?v=Y0ZqKpToTic
howtocalculatelongestincreasingsubstring.Tryitusingthefollowing:
541208563-ANSWER-Itshouldonlyrequiretwoseparateloops:
onetolooptogothroughtocalculatethevalues -thenaseparatelooptofigureoutwhatthemaxis...andthenreturnthemax whatdoyouneedtorememberwhenitcomestolIsubsequence?-ANSWER-- youareworkwithonearray -youfilleverythingoutwith1sfirstbasedonanarrayofsamesize -thevalueiscomparedaswellastheindexiscomparedthatiswhy(a_ whattakesmoretime,longestincreasingsubsequenceorlongestcommon subsequence?-ANSWER-increasingforsure!!!O(n**2)
explainminimumdistancealgorithm:performitusing
"abcdef" and
- / 2