Guest User

Table Sum Pseudocode

a guest
Jan 3rd, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. **TABLE SUM PSEUDOCODE**
  2.  
  3. let N = number of elements
  4. let A = array of elements
  5.  
  6. R0 = array that will hold A + (1 to N) in the 0th rotation
  7. for i in (0 to N-1)
  8. R0[i] = A[i] + (i+1)
  9.  
  10. pre = prefix max array of length N
  11. pre[0] = R0[0]
  12. for i in (1 to N-1)
  13. pre[i] = max(pre[i-1], R0[i])
  14.  
  15. suf = suffix max array of length N
  16. suf[N-1] = R0[N-1]
  17. for i in (N-2 to 0)
  18. suf[i] = max(suf[i+1], R0[i])
  19.  
  20. print suf[0] as output for 0th rotation
  21. for r in (1 to N-1)
  22. maxbeforesplit = r + pre[N-r-1]
  23. maxaftersplit = r-N + suf[N-r]
  24. maxoverall = max(maxbeforesplit, maxaftersplit)
  25. print maxoverall as output for rth rotation
Add Comment
Please, Sign In to add comment