Java Collections Cheatsheet – v2

Hello,

I have just updated the Java Collections Cheatsheet with a small modification : in the first table, I have mentioned the utility class “Collections” (thank you Evernat for your feedback).

Java Collections Cheatsheet - v2

Java Collections Cheatsheet - v2

If you are not familiar with the O-Notation (in our case, n is the number of elements managed by the collection):

O(1): Constant –> the time to execute the method is constant whatever the size

O(log n): Logarithmic –> if N is doubled, the running time is increased by a constant amount

O(n): Linear –> if N is doubled, the running time is doubled too

I want to thank “commentators” of my previous post: Casper Bang, Lutz Hankewitz, Davide Angelocola, Dragan Sahpaski, Maurice Naftalin (one of the authors of the “Java Generics and Collections” book :-) ) and Evernat.

PS: I’ve added a link to this post from my Friendly Cheatsheets page.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • Yahoo! Buzz

Comments 5

  1. Cornelius Perkins wrote:

    Small correction: O(log n) probably shouldn’t be described as the running time increasing by a constant amount. It’s actually by the square root of 2, but that means the growth is nonlinear: it has a curve, steeper than linear… but of course, much shallower than n**2.

    However, the cheat sheet itself looks fantastic. I’ve just printed it to study it in detail. Thanks for the great work.

    Posted 04 Sep 2009 at 5:36 am
  2. Neverwinterx wrote:

    There’s an error in the cheat sheet. The remove(O) operation of LinkedList works in O(n), not O(1). You can check it for yourself in the source code.
    This seems to be a common misconception, i’ve made a post about it here: http://forums.sun.com/thread.jspa?threadID=5406078

    Posted 06 Sep 2009 at 2:50 pm
  3. Maurice Naftalin wrote:

    Contrary to the comment from Neverwinterx, the cheatsheet is correct if slightly ambiguous. It gives the complexity of remove(0) – the first element of the list.

    There is no remove(O) method on List. There is, however, a method remove(Object) and, yes, that has linear complexity. But the book and the cheatsheet don’t discuss that.

    Posted 10 Sep 2009 at 11:27 am
  4. Maurice Naftalin wrote:

    The other comment is also wrong:

    log 2n = log 2 + log n

    (see, for example, http://en.wikipedia.org/wiki/Logarithm), so the statement (in both book and cheatsheet) that “if N is doubled, the running time is increased by a constant amount” is correct.

    Posted 10 Sep 2009 at 3:35 pm
  5. coder-friendly wrote:

    Hello,

    Since the answer of Maurice Naftalin(author of the book) is relevant, I’ve removed my previous answer because it would upset other future readers.

    Thank you Maurice for your answers.

    Coderfriendly

    Posted 11 Sep 2009 at 4:34 pm

Trackbacks & Pingbacks 1

  1. From Site de Cheat Sheets | Serviço Técnico de Informática on 01 Jul 2010 at 12:03 am

    [...] de uma grande parte das linguagens de programação e aplicações. Por exemplo, referências das Collections do JDK ou as referências standard de [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

Additional comments powered by BackType