PA of Algorithms Q97

  • Option : C
  • Explanation :
    a1, a2 .....................an
    b1, b2 .....................bn
    In order to find out the largest span, check the sums of
    ai +............aj and bi +..............bj at each step.
    If a1 + a2 = b1 + b2 go on, check a1 + a2 + a3 and b1 + b2 + b3.
    If not, then check a2 + a3 and b2 + b3
    Similarly a check is done at each of the n places during traversal. A separate variable has to be kept that contains the maximum span observed hitherto
    Hence fastest algorithm computes with (~) (n) time and space.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *