Questions tagged [treemap]

An implementation of a mapping (dictionary) using a tree. This tag is also used for treemapping, an information visualization method for displaying hierarchical data with nested rectangles.

A map implemented as a tree

A map (also called dictionary or associative array) can be represented as a tree, typically a binary search tree. This tag can be used for such implementations, especially the TreeMap class in Java.

Treemapping visualisation technique

A treemap is a method for displaying tree-structured data in two dimensions. Each element is represented as a rectangle, with the children of a tree displayed as sub-rectangles inside their parent's rectangle.

Treemap example http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Tree_Map.png/305px-Tree_Map.png

1568 questions
175
votes
4 answers

How to iterate over a TreeMap?

Possible Duplicate: How do I iterate over each Entry in a Map? I want to iterate over a TreeMap, and for all keys which have a particular value, I want them to be added to a new TreeMap. How can I do this?
Ali
  • 261,656
  • 265
  • 575
  • 769
85
votes
7 answers

How to use SortedMap interface or TreeMap in Java?

I have a Map What is the best way to keep the map sorted according to the float? Is SortedMap or TreeMap the best answer? How do I use it? I only create the map once and replace the MyObject frequently using myMap.put() and…
Bick
  • 17,833
  • 52
  • 146
  • 251
64
votes
17 answers

Java List Sorting: Is there a way to keep a list permantly sorted automatically like TreeMap?

In Java you can build up an ArrayList with items and then call: Collections.sort(list, comparator); Is there anyway to pass in the Comparator at the time of list, creation like you can do with TreeMap? The goal is to be able add an element to the…
Dave L.
  • 9,595
  • 7
  • 43
  • 69
56
votes
14 answers

Which data structure would you use: TreeMap or HashMap? (Java)

Description | A Java program to read a text file and print each of the unique words in alphabetical order together with the number of times the word occurs in the text. The program should declare a variable of type Map to store the…
JohnZaj
  • 3,080
  • 5
  • 37
  • 51
53
votes
11 answers

When should I use a TreeMap over a PriorityQueue and vice versa?

Seems they both let you retrieve the minimum, which is what I need for Prim's algorithm, and force me to remove and reinsert a key to update its value. Is there any advantage of using one over the other, not just for this example, but generally…
iceburn
  • 987
  • 3
  • 13
  • 16
46
votes
2 answers

Why is there not a concurrent TreeMap?

I have a few question related to java.util.concurrent package: Why in the java API there is the non-concurrent TreeMap on one side and the concurrent ConcurrentSkipListMap on one other? Why did not they call it ConcurrentTreeMap? Is it safe to say…
Rollerball
  • 12,618
  • 23
  • 92
  • 161
43
votes
3 answers

Different font sizes in the same annotation of matplotlib

I need to annotate a pylab rectangle with few data lines - which are of different length. Searching through the matplotlib documentation, and Googling, I could not find a way to give different parts of an annotation different sizes. The following…
user1850727
  • 569
  • 2
  • 6
  • 9
37
votes
3 answers

Java TreeMap Comparator

I need a comparator for a TreeMap. Should I write this anonymously in the constructor for my TreeMap? How else could I write my comparator. Currently, Java does not like my code (can I do this anonymously?): SortedMap myMap = …
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
33
votes
8 answers

Selecting random key and value sets from a Map in Java

I want to get random keys and their respective values from a Map. The idea is that a random generator would pick a key and display that value. The tricky part is that both key and value will be strings, for example myMap.put("Geddy", "Lee").
Roberto
  • 987
  • 1
  • 9
  • 21
31
votes
1 answer

Explanation of Red-Black tree based implementation of TreeMap in JAVA

I was going through the source code of TreeMap in JAVA. As per JAVA doc: A Red-Black tree based NavigableMap implementation. The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time,…
Zeeshan
  • 11,851
  • 21
  • 73
  • 98
31
votes
4 answers

Why and when to use TreeMap

Could someone tell me when and why to use TREEMAP.I went through This link but didn't find my answer. As Per my thinking we use treemap to get the data sort according to your key and the same we can achieve by other ways also.
Java_Alert
  • 1,159
  • 6
  • 24
  • 50
27
votes
4 answers

Python 2.6 TreeMap/SortedDictionary?

Is there a built-in sorted dictionary implementation in Python 2.6, or are hashtables the only kind? Clarifications: I'm asking about sorted dictionarys, not ordered dictionaries!
user541686
  • 205,094
  • 128
  • 528
  • 886
25
votes
4 answers

Java TreeMap equivalent in C#?

Most places I've consulted say to use SortedList, but the problem is that the program I'm porting actually uses duplicate keys (differentiated by order), which is permissible with TreeMap, but not SortedList. Any advice?
user58817
23
votes
5 answers

How to Print treemap in reverse order

In my assignment we are read from a file the text: To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer then count the times each has occured. I've been able to print this map unsorted, then I was able to make a…
IC2D
  • 471
  • 4
  • 11
  • 22
23
votes
7 answers

From C# serverside, Is there anyway to generate a treemap and save as an image?

I have been using this javascript library to create treemap on webpages and it works great. The issue now is that I need to include this in a powerpoint presentation that I am generating on the server side (I am generating the powerpoint using…
leora
  • 188,729
  • 360
  • 878
  • 1,366
1
2 3
99 100