Dec 28, 2008

n-1 roads between n toll stations, each road has associated cost of travel, design a data structure that required O(n) space O(1) time to compute the

n-1 roads between n toll stations, each road has associated cost of travel, design a data structure that required O(n) space O(1) time to compute the cost from one station to the other station

suppose the index of station is from 0 to n, the index of road is from 1 to n
a[0]=0;//a[] is prefix sum cost array
For[1…n]
a[i]=a[i-1]+c[i]
Cost of ith road = a[i+1]-a[i]

No comments:

Post a Comment