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
23
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
  • 52,135
  • 87
  • 247
  • 375
22
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
  • 7,924
  • 24
  • 84
  • 129
22
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
  • 259
  • 1
  • 2
  • 4
22
votes
2 answers

TreeMap - Search Time Complexity

What is the time complexity of a get() and put() in a TreeMap? Is the implementation same as a Red-Black Tree?
java_geek
  • 17,585
  • 30
  • 91
  • 113
21
votes
1 answer

Why does the same Map.Entry change when calling iterator.remove() in Java TreeMap?

When I use Iterator to iterate some TreeMap, I found the same Map.Entry's content will change. For example: import java.util.Map.Entry; import java.util.TreeMap; public class Solution { public static void main(String[] args) { …
maplemaple
  • 1,297
  • 6
  • 24
21
votes
3 answers

How to collect a stream into a TreeMap

I know this is a noob a question, but I couldn't find a simpe answer anywhere else. Question is: I need to write a method that returns a SortedMap, so a tree map should work just fine. I have a HashMap< String, Skill>, the Skill class has both the…
francesco foschi
  • 323
  • 1
  • 2
  • 9
21
votes
6 answers

How to get key and value of a TreeMap at particular index

I have a TreeMap with a set of 'Key and Value' pairs. How can I get both Key and Value at a particular Index of the TreeMap? EDIT : @TO-ALL : Thanks. But I know how to implement it by using an extra ArrayList. I just thought is there any way to…
Dileep Perla
  • 1,865
  • 7
  • 33
  • 54
19
votes
4 answers

Migrating Java TreeMap code to Scala?

I am migrating my Java code base to pure Scala and I am stuck on this one piece of code. I have an implementation of an IntervalMap i.e. a data structures that let's you efficiently map ranges [from,to] to values where the set, delete and get…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
19
votes
4 answers

TreeMap how does it sort

How does the TreeMap sort? say for example you have the following map: TreeMap treemap = new TreeMap<>(); treemap.put("lol", 1); treemap.put("Marc", 2); treemap.put("Jesper", 3); Iterator ittwo = treemap.entrySet().iterator(); …
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364
18
votes
3 answers

Using java.util.Map in h:dataTable

I need to display Map using . My backing bean has a Map property as below: public class Bean { private Map map; // +getter @PostConstruct public void init() { map = new TreeMap(); …
JPS
  • 2,730
  • 5
  • 32
  • 54
16
votes
7 answers

How would I print all values in a TreeMap?

I have a project that I'm working on for my Java class (obviously) and I must have missed the lecture on how to interact with TreeMaps. I have no idea what I'm doing with this part and I'm not finding a lot of help from Google. For the first case…
Lish
  • 307
  • 2
  • 3
  • 10
16
votes
3 answers

Java putting Hashmap into Treemap

I am currently reading 2 million lines from a textfile as asked in the previous question Java Fastest way to read through text file with 2 million lines Now I store these information into HashMap and I want to sort it via TreeMap because I want to…
BeyondProgrammer
  • 893
  • 2
  • 15
  • 32
16
votes
4 answers

d3.nest() key and values conversion to name and children

I am working on creating a Treemap from a csv file. The data in the csv file is hierarchical, as a result I used d3.nest(). However, the resulting JSON is in the form of {key:"United States", values:[...]}. The zoom-able treemap requires hierarchy…
user2457956
  • 203
  • 2
  • 6
16
votes
9 answers

How to sort a treemap based on its values?

How can I sort a treemap using its values rather than the key?
Ali
  • 261,656
  • 265
  • 575
  • 769
16
votes
2 answers

Time complexity of TreeMap operations- subMap, headMap, tailMap

Does anyone know the time complexity of the operations of TreeMap like - subMap, headMap. tailMap. The time complexity of operations like get, put is O(logn). But the javadoc doesnt say much about the complexity for the above operations. The worst…
agaase
  • 1,562
  • 1
  • 15
  • 24