Questions tagged [data-structures]

A data structure is a way of organizing data in a fashion that allows particular properties of that data to be queried and/or updated efficiently.

Data structures are ubiquitous in software. Hash tables, balanced trees, and dynamic arrays are essential building blocks for large, complicated systems and almost all programmers have encountered them at some point. More complicated structures like binary heaps can speed up complicated systems, while simpler concepts like stacks and queues make it possible to more elegantly and concisely encode algorithms.

Of course, this is just the tip of the iceberg when it comes to data structures. Theoreticians have been developing progressively better and better data structures over the past years, many of which are used extensively in modern software, and many are only useful from a theoretical perspective.

Data structures are closely related to algorithms. Often, a good choice of data structure can lead to a marked improvement in an algorithm's runtime. For example, Dijkstra's algorithm with a naive implementation of a priority queue runs in quadratic time, but with a fast Fibonacci heap can be shown to run in O(m + n lg n).

Below is a (not at all comprehensive) list of some of the more popular data structures and their variants:

  • Dynamic arrays
    • Dynamic table
    • Tiered vector
    • Hashed array tree
    • Extendible array
  • Linked lists
    • Singly-linked lists
    • Doubly-linked lists
    • XOR-linked lists
    • Skip lists
  • Hash tables
    • Chained hash tables
    • Linear probing hash tables
    • Quadratic probing hash tables
    • Double hash tables
    • Cuckoo hash tables
    • Perfect hash tables
    • Dynamic perfect hash tables
  • Binary trees
    • Red/black trees
    • Interval trees
    • Binary search trees
    • Segment trees
    • AVL trees
    • AA trees
    • Splay trees
    • Scapegoat trees
    • Treap
  • Priority queues
    • Binary heap
    • Binomial heap
    • Fibonacci heap
    • van Emde Boas tree
    • Skew binomial heap
    • Brodal queue
  • Radix trees
    • Trie
    • Patricia tree
    • Ternary search tree
  • Multiway trees
    • B tree
    • B+ tree
    • B* tree
  • Geometric trees
    • Quadtree
    • Octree
    • kd-Tree
    • BSP-tree
    • R-tree
  • Geometric structures
    • Winged-edge
    • Quadedge
  • Network connectivity structures
    • Disjoint-set forest
    • Link/cut tree
    • Top tree
  • Graphs
    • DAG
    • Directed graph
    • Undirected graph
    • Hypergraph

Links:

33477 questions
303
votes
4 answers

golang why don't we have a set datastructure

I'm trying to solve "The go programming lanaguage" exercise #1.4 which requires me to have a set. I can create a set type but why doesn't the language come with one ? go, having come from google, where guava also originated, why didn't the language…
anjanb
  • 12,999
  • 18
  • 77
  • 106
292
votes
11 answers

Does VBA have Dictionary Structure?

Does VBA have dictionary structure? Like key<>value array?
fessGUID
291
votes
20 answers

Tree data structure in C#

I was looking for a tree or graph data structure in C#, but I guess there isn't one provided. An Extensive Examination of Data Structures Using C# 2.0 a bit about why. Is there a convenient library which is commonly used to provide this…
stimms
  • 42,945
  • 30
  • 96
  • 149
288
votes
20 answers

How to convert List to Map?

Recently I have conversation with a colleague about what would be the optimal way to convert List to Map in Java and if there any specific benefits of doing so. I want to know optimal conversion approach and would really appreciate if any one can…
Rachel
  • 100,387
  • 116
  • 269
  • 365
264
votes
7 answers

Skip List vs. Binary Search Tree

I recently came across the data structure known as a skip list. It seems to have very similar behavior to a binary search tree. Why would you ever want to use a skip list over a binary search tree?
Claudiu
  • 224,032
  • 165
  • 485
  • 680
263
votes
12 answers

What is the difference between a map and a dictionary?

I know a map is a data structure that maps keys to values. Isn't a dictionary the same? What is the difference between a map and a dictionary1? 1. I am not asking for how they are defined in language X or Y (which seems to be what generally people…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
256
votes
11 answers

Python Sets vs Lists

In Python, which data structure is more efficient/speedy? Assuming that order is not important to me and I would be checking for duplicates anyway, is a Python set slower than a Python list?
Mantas Vidutis
  • 16,376
  • 20
  • 76
  • 92
247
votes
19 answers

Why doesn't java.util.Set have get(int index)?

I'm sure there's a good reason, but could someone please explain why the java.util.Set interface lacks get(int Index), or any similar get() method? It seems that sets are great for putting things into, but I can't find an elegant way of retrieving a…
Marty Pitt
  • 28,822
  • 36
  • 122
  • 195
244
votes
8 answers

Why should I use Deque over Stack?

I need a Stack data structure for my use case. I should be able to push items into the data structure and I only want to retrieve the last item from the Stack. The JavaDoc for Stack says : A more complete and consistent set of LIFO stack operations…
Geek
  • 26,489
  • 43
  • 149
  • 227
242
votes
12 answers

Priority queue in .Net

I am looking for a .NET implementation of a priority queue or heap data structure Priority queues are data structures that provide more flexibility than simple sorting, because they allow new elements to enter a system at arbitrary intervals. It is…
Doug McClean
  • 14,265
  • 6
  • 48
  • 70
228
votes
22 answers

What is the best way to implement nested dictionaries?

I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this: {'new jersey': {'mercer county': {'plumbers': 3, 'programmers': 81}, 'middlesex county':…
YGA
  • 9,546
  • 15
  • 47
  • 50
228
votes
6 answers

How is set() implemented?

I've seen people say that set objects in python have O(1) membership-checking. How are they implemented internally to allow this? What sort of data structure does it use? What other implications does that implementation have? Every answer here was…
Daenyth
  • 35,856
  • 13
  • 85
  • 124
226
votes
6 answers

Why is std::map implemented as a red-black tree?

Why is std::map implemented as a red-black tree? There are several balanced binary search trees (BSTs) out there. What were design trade-offs in choosing a red-black tree?
Denis Gorodetskiy
  • 2,884
  • 3
  • 21
  • 23
223
votes
12 answers

.Net Data structures: ArrayList, List, HashTable, Dictionary, SortedList, SortedDictionary -- Speed, memory, and when to use each?

.NET has a lot of complex data structures. Unfortunately, some of them are quite similar and I'm not always sure when to use one and when to use another. Most of my C# and VB books talk about them to a certain extent, but they never really go into…
Pretzel
  • 8,141
  • 16
  • 59
  • 84
221
votes
15 answers

Get keys from HashMap in Java

I have a Hashmap in Java like this: private Map team1 = new HashMap(); Then I fill it like this: team1.put("United", 5); How can I get the keys? Something like: team1.getKey() to return "United".
masb
  • 2,813
  • 3
  • 20
  • 20