I'll be moving my blog to riyadhrazzaq/text. Main reason I'm doing this is because of Jekyll's markdown feature.
Considering input series: { 4 , -10 , 3 , 100 , -20 , 1 } Query(x,y) = Max { a[i]+a[i+1]+...+a[j] ; x ≤ i ≤ j ≤ y } A node contains- [ START & END is a node's segment limit ] Prefix is the maximum sum starting at START, end can be anywhere. There are two possibilities of the maximum. One, node's leftChild's prefix or two, adding leftChild's sum + rightChild's prefix. (which will make the prefix contiguous) Suffix is the maximum sum ending at END, start can be anywhere. There's two possibility of the maximum. One, node's rightChild's already calculated suffix or two, add rightChild's sum + leftChild's suffix (which will make the suffix contiguous). Sum : leftChild's sum + rightChild's sum. MAX Maximum of - prefix (result is in the node, starts from START but doesn't end in END ) suffix (result is in the node, doesn't start from START but surely ends in END ) leftChild's max ( result is in left ...
Comments
Post a Comment