Java code: data structures, algorithms, and OOP.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
Charles Reid 5e5d9a152d adding wisdom learned from linked list scaling. il y a 4 ans
.. add rotate to linked list test. il y a 4 ans reorganizing doubly-linked list class DLinkedList and expanding tests. il y a 4 ans Clearing up the print method of the generic and non-generic linked lists. il y a 4 ans
Makefile Update makefile to make timing test il y a 4 ans adding wisdom learned from linked list scaling. il y a 4 ans moving linked list materials to new directory. il y a 4 ans singly linked list. il y a 4 ans Adding Tim the Timer. il y a 4 ans Fixing up timing, prints out 1e3 to 1e6 scaled linked list performance. il y a 4 ans


Abstract List Type

The list abstract data type (ADT) implements the following methods:

  • size
  • isEmpty
  • first
  • last
  • addFirst
  • addLast
  • removeFirst

Other convenience methods:

  • remove
  • removeFirst
  • removeLast
  • removeElement

Mistakes Learnings Tricks

Use the Integer class when processing integers!

When you have a String and you want an integer:

  • Integer.parse(“525”)

When you have an integer and you want a String:

  • Integer.toString(str)

In general, you can also use the String class to turn the object into a String:

  • String.valueOf(o)

Linked List specific details:

  • Need to handle cases where you are adding to an empty list, or removing last item from list
  • Especially when using tail pointer, be aware of what it is pointing to and when it needs to be updated.

Linked list methods should automatically become a list of bookkeeping things to do.

  • Add method: consider adding to an empty list, non-empty list
  • Add at index i:
    • What are all possible cases?
    • i is too big, i is too small
    • the list is empty
    • i is a special case
    • how can we fold any of these cases into other cases (list empty -> i too small)

Size of linked list:;

  • Number of bytes:
  • Size estimation:
    • 1000-integer linked list should theoretically use up:
    • 1000 nodes x ( 4 bytes per integer + 8 bytes per ref + 16 bytes object overhead )
    • 28,0000 bytes ~ 28 kB
    • What’s the power of 2 that would correspond to that?
    • 1000 integers ~ 1024 integers ~ 2^10 integers
    • Round it up to 8 bytes per integer, 8 bytes per ref, 16 bytes per object overhead)
    • 2^5 = 32 bytes per integer
    • 32 x 8 = 2^5 * 2^3 = 2^8 = 256 bits = 256 zeroes and ones
    • 10 GB / 10 kB/obj = 10x10^6 / 10 = 10^6


class Empty extends Exception{};

Circular linked list:

  • Take care with the details of pointers.

Doubly linked list:

  • It makes algorithms easier, but

Nice link explaining sizes of Strings in memory:

sizeof(string) =
8 + // object header used by the VM
8 + // 64-bit reference to char array (value)
8 + string.length() * 2 + // character array itself (object header + 16-bit chars)
4 + // offset integer
4 + // count integer
4 + // cached hash code


  • Don’t do logarithmic size.........
  • Need to fix that actually.
  • Cover a single order of magnitude, then maybe try for two.