Questions tagged [amortized-analysis]

An amortized analysis is an analysis of the total runtime of a set of operations rather than the individual runtime of any one operation.

Typically, in computer science theory, asymptotic worst case algorithm performance is used as the most important metric. However, this ignores that in reality we want the overall computation time to be low.

Sometimes this desire for overall computation time to be low requires algorithms that may have high worst case complexity for a single instance, but that will have good time complexity on average.

A well-known example of this is how it is best to grow the memory in an std::vector<> after a push_back that exceeds the currently allocated memory, i.e. by reallocating an array that is M times bigger, where M could be around 1.5. The amortized run-time of this is constant (O(1)) as long as M>1. Naively reallocating a fixed amount of memory each such push_back is average time O(N), where N is the number of push_backs.

Here is the MIT Open Courseware lecture where they touch upon amortized analysis.

122 questions
0
votes
1 answer

Updating maximum sum subinteral in an array in sublinear time when an adjacent transposition is applied

I asked this question for general transpositions and it seemed too hard, I only got one answer which didn't seem to give a guaranteed asymptotic speed-up. So suppose we apply a sequence of adjacent transpositions to a numeric array (an adjacent…
user2566092
  • 4,473
  • 12
  • 19
0
votes
2 answers

Finding amortized time complexity

So I wrote a function push_back for a vector class, and I'm now trying to figure out the amortized time complexity. I'm pretty new to the theoretical side of programming, so if someone could walk me through it that would be amazing. This is my…
Connor Black
  • 6,177
  • 12
  • 35
  • 67
0
votes
0 answers

is the amortized cost for increment and decrement binary counter the same?

is the amortized cost for increment and decrement binary counter the same? i.e O(n) for n increments or decrements? Also can somebody explain how to calculate the amortised cost of a binary decrement counter using the potential method.
happs
  • 397
  • 5
  • 15
0
votes
4 answers

StringBuffer and amortization

In ArrayList the add operation is amortized operation. So while reading StringBuffer it came to my mind why the StringBuffer is not amortized. Suppose I use append operation on a string buffer object then it should be able to add those many no…
Anil Sharma
  • 568
  • 5
  • 18
0
votes
1 answer

Binary Counter Amortized Analysis

I guess you already know that if all the entries in the Array starts at 0 and at each step we increment the counter by 1 (by flipping 0's and 1's) then the amortized cost for k increments is O(k). But, what happens if the Array starts with n ? I…
Robert777
  • 761
  • 2
  • 8
  • 22
0
votes
0 answers

n-bit counter amortized analysis

Suppose we have a binary counter that supports two operations: incrementing and resetting all bits to zero. If the modification or examination of a single bit takes Theta(1) time, how can a counter be implemented as an array of bits so that any…
norman
  • 4,280
  • 10
  • 38
  • 72
0
votes
2 answers

Big-O: Getting all of the keys in a Java HashMap

Anyone know what the amortized analysis is of keySet in Java HashMap? O(1)? Is iterating through them O(n)?
Dean J
  • 35,669
  • 13
  • 61
  • 92
0
votes
1 answer

Connection between amortized complexity and worst case time complexity

I have a set of n consecutive operations which each one runs in O(1) amortized complexity. Can I say that the whole set runs in O(n) worst case time complexity? How do I prove it ?
orizis
  • 134
  • 1
  • 14
-1
votes
1 answer

Amortized Analysis: Find the Rate of Travel

A biker can travel at 24kms per hour with the flow of the wind, but only 12kms per hour against the wind. Assuming the biker starts and finishes at the same point. What is the rider's amortized rate of travel? I do not understand how the answer is…
ron8
  • 243
  • 2
  • 4
  • 13
-1
votes
1 answer

Amortized analysis on power 3 counter

I was reading the algorithms textbook Cormen, Liserson, Rivest and Stein more often than not. One of the interesting chapter in there is Amortized analysis. Binary counter is a difficult example when it comes to selecting Potential functions. I was…
user527248
  • 35
  • 6
-1
votes
1 answer

Amortized analysis on Heap

When I ran to this topic. I read in this book on the bottom of page 5-1 that Binomial Queues, Fibonacci Heap and Skew Heap have O(1) amortized cost for insert operations and O(log n) amortized cost of delete operations. Next the authors write that…
user4249446
-1
votes
1 answer

Randomized Algorithm

I'm having trouble with a randomized problem. :) A, a randomized algorithm, determines whether an input x is a prime number. This algorithm works the following way: 1- If x is prime, then A outputs YES 2- If x is not prime, then A outputs NO with…
user3670084
-1
votes
1 answer

Doubling and incremental strategy while implementing stack using linked list and arrays?

What is difference between amortized and average complexity? Also what is doubling and incremental strategy while implementing stack using linked list and arrays?
-2
votes
1 answer

Using the potential and the accounting methods in amortized analysis

I have read about the accounting and the potential methods but I still having trouble solving such questions:
-2
votes
1 answer

Amortized analysis accounting method

I'm trying to find the amortized cost per operation in a sequence of n operations on a data structure in which the ith operation costs i if i is an exact power of 3, and 1 otherwise can anyone explain me how to solve the problem I found O(6), i dont…
1 2 3
8
9