what is amortised cost using aggregate method is
amortized cost = total cost of n operation / n
so we have to just find the cost of all the operations and then add them and divide them by n
so total cost = 1+ 2+ 1 + 4 + 1 + 1 + 1+ 8 ...
n + it will approx to 3n
which is equivalent to O(n)
so amortized cost = O(n) / n = O( 1)
2.) accounting method tells that we store some cost for the cheaper actions and then use that extra cost for the heavy actions.
suppose we make a cost of 3 for every operation so what happen now look at following table
operation | available cost | remaining cost |
---|---|---|
1 | 3 | 3 -1 =2 |
2 | 2 + 3= 5 | 5 -2 =3 |
3 | 3+3= 6 | 6-1 =5 |
4 | 5+3 =8 | 8-4 =4 |
5 | 4+3 =7 | 7-1=6 |
6 | 6+3 =9 | 9-1 =8 |
7 | 8+3 =11 | 11-1 =10 |
8 | 10+3 =13 | 13-8=5 |
as we can see that the cost 3 is sufficient to complete the operations and it will satisfy all the requirements.
so for the n operations total cost will be 3*n
so for one operation cost is 3 which is equivalent to O(1)
I hope this will help you so please give positive ratings :)))
3. Suppose we are doing a sequence of operations (numbered 1, 2, 3, ...) such that the ith operation: - costs 1 if i is not a power of 2 - costs i if i is a power of 2. For example, the following...
Suppose we have 20 singleton sets, numbered 0 through 19, and we call the operation union(find(i),find(i + 5)), for i = 0, 1, 2, . . . , 14. Draw a picture of a tree-based representation of the sets that result, assuming we don’t implement the union-by-size and path compression heuristics.
The example shows that the actual cost of action number k is the largest integer i so that 2i goes up. For example, if k is 12, then i = 2, because 22 = 4 goes up 12 and a higher square of 2 does not. 1. Suppose we are maintaining a data structure under a series of n operations. Let f (k) denote the actual running time of the kth operation. For each of the following functions f, determine...
Suppose we execute the following stack operations on a stack of ints. push(1); pop(); // #1 push(10); pop(); // #2 push(7); push(4); push(3); pop(); // #3 push(5); pop(); //#4 Write the final state of the stack, and for each pop() operation, write the value that will be popped off the stack (pops are numbered so you can refer to them).
do (b) please 2. (15 marks) Consider the abstract datatype SEQ whose objects are sequences of elements and which supports two operations . PREPEND(x, S), which inserts element r at the beginning of the sequence S and . ACCESS(S, i), which returns the ith element in the sequence Suppose that we represent S by a singly linked list. Then PREPEND(, S) takes 1 step and ACCESS(S, i) takes i steps, provided S has at least i elements Suppose that S...
2. Table 1 shows the daily quantities of work units moving between five (5) work stations. Draw a network diagram for the information shown and state which operations are: i. Repeated operation, ii. In-sequence moves, ii. By-pass moves and iv. Backflow moves. [10mks Table J Daily Quantitses of work nits moved between five (3) Work Stations To operation j 10 30 17 10 30 From operation 3 10 20 25 50 15 2. Table 1 shows the daily quantities of...
2. You must support the following two operations on a set of numbers: (1) insertion, and (2) "large-delete" which is to delete the largest half of the values in the set. In other words if there are k elements you delete the elements with the rk/2] largest values. For example, large-delete15, 3,7,9,1,8) 3,1,5) Both operations should take constant time, amortized. Assume that you start with an empty data structure. You can use whatever data structure you like for the set....
Consider an infinite sequence of positions 1, 2, 3, . . . and suppose we have a stone at position 1 and another stone at position 2. In each step, we choose one of the stones and move it according to the following rule: Say we decide to move the stone at position i; if the other stone is not at any of the positions i + 1, i + 2, . . . , 2i, then it goes to...
Example Suppose that the economy of the city of Everett depends on three industries Logging-timber operation, electricity and aircraft-manufacturing plant. Monitoring the operations of these three industries over a period of one year, we were able to come up with the following observations: 1. To produce 1 unit worth of timber, the Logging-timber industry must consume 0.3 units of its own production, 0.3 units of electricisy and 0.3 units of aircraft to run its operations 2. To produce 1 unit...
2. Suppose we want to multiply two N-by-N matrices, C-A B, by following the componentwise formula に1 (a) What are the operation counts? (b) In floating-point arithmetic, for which of these operations does the order matter? (c) Write a Matlab program that implements this formula. 2. Suppose we want to multiply two N-by-N matrices, C-A B, by following the componentwise formula に1 (a) What are the operation counts? (b) In floating-point arithmetic, for which of these operations does the order...
Consider an infinite sequence of positions 1,2,3,... and suppose we have a stone at position 1 and another stone at position 2. In each step, we choose one of the stones and move it according to the following rule: Say we decide to move the stone at position i; if the other stone is not at any of the positions i 1,i + 2, ..., 2i, then it goes to 2i, otherwise it goes to 2i +1 For example, in...