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

1412 questions
155
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?
Click Upvote
  • 235,452
  • 251
  • 553
  • 736
54
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
  • 2,900
  • 5
  • 33
  • 50
49
votes
16 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.
  • 8,707
  • 7
  • 39
  • 64
36
votes
8 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
  • 827
  • 3
  • 12
  • 14
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
  • 977
  • 1
  • 8
  • 21
32
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
  • 11,004
  • 22
  • 81
  • 136
32
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
  • 12,865
  • 46
  • 123
  • 204
28
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
  • 9,465
  • 14
  • 65
  • 93
23
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
  • 999
  • 6
  • 20
  • 45
22
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
  • 189,354
  • 112
  • 476
  • 821
22
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
  • 163,579
  • 332
  • 834
  • 1,328
22
votes
2 answers

Create a SortedMap in Java with a custom Comparator

I want to create a TreeMap in Java with a custom sort order. The sorted keys which are string need to be sorted according to the second character. The values are also string. Sample map: Za,FOO Ab,Bar
unj2
  • 47,759
  • 80
  • 235
  • 362
21
votes
4 answers

Treemap visualization in Python

I'm interested in drawing a treemap: What is the easiest way to make one in Python? Is there a library that could produce such a graphic, given the proper input data?
Primoz
  • 249
  • 1
  • 2
  • 4
21
votes
2 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
  • 349
  • 2
  • 4
  • 9
20
votes
8 answers

Find element position in a Java TreeMap

I am working with a TreeMap of Strings TreeMap, and using it to implement a Dictionay of words. I then have a collection of files, and would like to create a representation of each file in the vector space (space of words) defined by…
Matteo
  • 6,694
  • 21
  • 75
  • 123
1
2 3
94 95