Monday, March 5, 2007

TreeMap vs PriorityQueue

Comparison

Category
TreeMap
PriorityQueue
Implementation
Uses Red-Black tree
Uses Min (max) tree
Remove Time Complexity
O(log(n))
O(log(n))
Insert Time Complexity
O(log(n))
O(log(n))
Duplicates
No
Yes
Search Time Complexity
O(log(n))
O(n)

When to use PriorityQueue?

As the above comparison shows, when you need duplicates and when you don't care about finding a particular elements by key, you should use this.

When to use TreeMap?

Again, as the comparison shows, when you need duplicates and when you need to find an element based on a particular key, use this. There are ways to put duplicates into TreeMap using a custom Comparator, but try to avoid that as it breaks the general understanding of the TreeMap for users.

Tuesday, July 25, 2006

Very handy Unix Commands

If you are like me, an awesome application developer :), only spends time on Unix for the usual process or disk monitoring, not like a system programmer, these commands can be very handy...

List all directories with sizes
du -sh *
h -- displays the information in human readable format, using G (Gigabyte), M (Megabyte) etc.

List of all directories sorted by size
du -sm * | sort -nr

Size of a file system (drives in lay man terms)

--Current File system
   df .

--Current file system in human readable form
   df -h .

Size of all file systems
df -h

Find processes sorted by the maximum amount of RAM / CPU usage
top
Once inside, press Shft+Q
Now, Press the letter next to the option 'RES' (to sort by Resident Memory usage)
Press the letter next to the option 'CPU' (to sort by CPU usage)