Which data structure is used to implement a trie? [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Which data structures should I use to implement a trie in Java?
Do I use a linked list, array, map?

The way I implemented a Trie was to use a custom class for the node and store outgoing links as either a HashMap or ArrayList (depending on the number of child nodes).
The reason to split the two cases was that many of the nodes would have just a few child nodes and using a Map would actually slow things down. If I recall correctly I put the limit at about 4 child nodes.

Related

Why are elements in a HashSet unordered? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
What advantage is there in keeping the Set unordered?
Is it more efficient in space/time?
In what way is a random order easier to manage than insertion order?
Elements in a HashSet are ordered (dispersed in the Javadoc) by the Object.hashCode(). You can use a LinkedHashSet if you need a Set that preserves insertion order.

*ignore* How to check if an Array<String> contains an item that starts with a value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
The app fetches data from a server. The data is returned in an Array. I need to check if one of the Array items starts with a value specified in the app. If it's possible without iterating because that slows down the app significantly.
If you have just an array data structure, there is no way to check what it contains without actually looking into it.
However if you use a different data structure such as a HashMap (which is built on to of an array) you can check/lookup a key like "101" in O(1) time typically. You can check map.isEmpty() in O(1) time.
In short, if it's taking too long to perform a simple operation, chances are you need to be using a different data structure (or possibly more than one)

huffman without using node [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm thinking on possibility of making a Huffman code without "node".
It's based on the nodes then my question seems a bit ambiguous.
I know,maybe we have to use string's abilites ...
Is it possible ? and if "YES" how Is it possible in java?
Thanks.
You can use indices instead of nodes but you need somewhere nodes and/or vertices.

Which Map to use in case of million records in Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have many records in to fetch and it could be in millions, I want to use hashmap, but I am not sure if that is ok or what would be the memory implications.
Please suggest
Thanks
VIvek
Welcome to StackExchange. A good place to start would be taking a look at this question:
Difference between HashMap, LinkedHashMap, and SortedMap in Java
HashMap is generally discouraged if you need to grab items in a specific order.
If you need to store 1,000,000+ records, you may want to look into an external database to store the information, as it will be memory consuming to hold all of the records.

Java best data structure for sorting? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I want to store a list of (Object, int) in a data structure such that the int field can be easily sorted (ascending or descending).
I'm looking at Hashtables and TreeMaps but i'm unsure which, if either, of these are good for this purpose.
The priority is the sort speed. Any suggestions?
Given what you've told us, it's hard to say what'd be best.
If you're concerned with sorting performance alone, a HashTable or TreeMap (actually a red-black binary tree) have great sorting performance, but they're slower than some other data structures when adding (and in TreeMap's case, deleting) items.
You should probably provide more details regarding what you're doing with the data.

Categories

Resources