Implementing a HashMap in C

Well if you know the basics behind them, it shouldn’t be too hard. Generally you create an array called “buckets” that contain the key and value, with an optional pointer to create a linked list. When you access the hash table with a key, you process the key with a custom hash function which will … Read more

Difference between a HashMap and a dictionary ADT

In terms of Java, both the class HashMap and the class Dictionary are implementations of the “Map” abstract data type. Abstract data types are not specific to any one programming language, and the Map ADT can also be known as a Hash, or a Dictionary, or an Associative Array (others at http://en.wikipedia.org/wiki/Associative_array). (Notice we’re making a distinction between the Dictionary class and the Dictionary … Read more

Linked List vs Vector

Vector is another name for dynamic arrays. It is the name used for the dynamic array data structure in C++. If you have experience in Java you may know them with the name ArrayList. (Java also has an old collection class called Vector that is not used nowadays because of problems in how it was … Read more

How do I instantiate a Queue object in java?

A Queue is an interface, which means you cannot construct a Queue directly. The best option is to construct off a class that already implements the Queue interface, like one of the following: AbstractQueue, ArrayBlockingQueue, ArrayDeque, ConcurrentLinkedQueue, DelayQueue, LinkedBlockingQueue, LinkedList, PriorityBlockingQueue, PriorityQueue, or SynchronousQueue. An alternative is to write your own class which implements the necessary Queue interface. It is not needed except in those rare cases where you wish to … Read more

What is the difference between a map and a dictionary?

Two terms for the same thing: “Map” is used by Java, C++ “Dictionary” is used by .Net, Python “Associative array” is used by PHP “Map” is the correct mathematical term, but it is avoided because it has a separate meaning in functional programming. Some languages use still other terms (“Object” in Javascript, “Hash” in Ruby, “Table” in Lua), but those all … Read more

Tree data structure in C#

My best advice would be that there is no standard tree data structure because there are so many ways you could implement it that it would be impossible to cover all bases with one solution. The more specific a solution, the less likely it is applicable to any given problem. I even get annoyed with … Read more