• Post Reply Bookmark Topic Watch Topic
  • New Topic

PriorityQueue  RSS feed

 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PriorityQueue Implementation note: this implementation provides O(log(n)) time for the insertion methods

What is the meaning of O(log(n)) ?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Wikipedia - Big O Notation and An informal introduction to O(N) notation, the latter of which says...
O(N) notation is used to express the worst-case order of growth of an algorithm. That is, how the algorithm's worst-case performance changes as the size of the data set it operates on increases.

...and specifically...
O(log N) and O(N log N) ... generally mean that the algorithm deals with a data set that is iteratively partitioned, like a balanced binary tree... Generally, but not always, log N implies log2N, which means, roughly, the number of times you can partition a set in half, then partition the halves, and so on, while still having non-empty sets.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case, it means inserting items into a PriorityQueue that contains n items (where n is large - these scalings are only really relevant for big numbers) scales with log(n). Let's say that you've got a queue with 10,000 entries, and it's taking four seconds to insert items (in the worst case). Then you'd expect a queue with 100,000 entries to take five second to insert items [because log(10000) = 4 and log(100000) = 5].
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!