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
10
votes
2 answers

Data structure to find integers within a query range efficiently

There is an arbitrary amount of distinct unsigned integer values within a known range. The number of integer values is << the number of integers within the range. I want to build a data structure which allows the following runtime…
Etan
  • 17,014
  • 17
  • 89
  • 148
10
votes
7 answers

What does it mean to instantiate an object using curly braces in C++?

Let's say I have a struct defined as: typedef struct number{ int areaCode; int prefix; int suffix; } PhoneNumber; When I create an instance of this struct, if I use the following syntax: PhoneNumber homePhone = {858, 555,…
DJ Tanner
10
votes
1 answer

Best data structure for an immutable persistent 3D grid

I'm experimenting with writing a game in a functional programming style, which implies representing the game state with a purely functional, immutable data structures. One of the most important data structures would be a 3D grid representing the…
mikera
  • 105,238
  • 25
  • 256
  • 415
10
votes
5 answers

Optimal data structure for a special dictionary

Which data structure is best in terms of computational complexity to implement a dictionary of (key,val) items, which must support only following commands: Insert(key) - appends an item (key,val) with val=1 Increment(key) - increments val of…
psihodelia
  • 29,566
  • 35
  • 108
  • 157
10
votes
3 answers

How should I specify the type of JSON-like unstructured data in Scala?

I'm considering porting a very simple text-templating library to scala, mostly as an exercise in learning the language. The library is currently implemented in both Python and Javascript, and its basic operation more or less boils down to this (in…
Tim Gilbert
  • 5,721
  • 5
  • 33
  • 28
10
votes
2 answers

Can functional/immutable data structures still be useful for concurrency in a non-garbage collected context?

One of the selling points of immutable data structures is that they are automatically parallelizable. If no mutation is going on, then references to a functional data structure can be passed around between threads without any locking. I got to…
10
votes
14 answers

given a node how can I find previous node in a singly linked list

Given the current node, how can I find its previous node in a Singly Linked List. Thanks. Logic will do , code is appreciated. We all know given a root node one can do a sequential traverse , I want to know if there is a smarter way that avoids…
David Prun
  • 8,203
  • 16
  • 60
  • 86
10
votes
2 answers

Implementing a balanced binary search tree?

I have implemented a binary search tree and I want to add more functionality in its insertion function to make it a self-balancing tree. I am coding in C#. Can anybody please suggest me good tutorials or links on this? I did some searches and…
Lost
  • 12,007
  • 32
  • 121
  • 193
10
votes
2 answers

__eq__() called multiple times instead of once in nested data structure

Once or twice a year, I run into the following issue: I have some type on which comparison operations might be expensive (e.g. the values are to big to keep in memory and need to be loaded form disk or equality is hard to compute because a single…
Feuermurmel
  • 9,490
  • 10
  • 60
  • 90
10
votes
3 answers

Minimum add to make parentheses string consisting of '{', '}', '[', ']', '(', ')' valid

This problem is an addition to the familiar stack question(https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/) where we have to return the minimum number of additions to make the parentheses string valid. But that question consists…
10
votes
3 answers

How to represent a strange graph in some data structure

A simple way to represent a graph is with a data structure of the form: {1:[2,3], 2:[1,3], 3:[1,2]} Where the keys in this dictionary are nodes, and the edges are represented by a list of other nodes they are connected to. This data structure…
Wilduck
  • 13,822
  • 10
  • 58
  • 90
10
votes
6 answers

Best way to store hierarchical tags

I have a list, where each list entry is tagged with multiple tags. Each tag can also have child tags. Every entry in the list can have more than one tags. For example, a list entry that talks about cars can have tags called "cars", "vehicles",…
ashwnacharya
  • 14,601
  • 23
  • 89
  • 112
10
votes
5 answers

Are Tries still a good idea on modern architectures?

One of my favourite data structures in college was the Trie. It's a great data structure for holding a large set of strings if the prefixes are shared. Lookups are also nice, since they are done at O(|length|) of the string regardless of how many…
Uri
  • 88,451
  • 51
  • 221
  • 321
10
votes
3 answers

Why is avl tree faster for searching than red black tree?

I have read it in a couple of places that avl tree search faster, but not able to understand. As I understand : max height of red-black tree = 2*log(N+1) height of AVL tree = 1.44*logo(N+1) Is it because AVL is shorter?
paseena
  • 4,207
  • 6
  • 32
  • 51
10
votes
6 answers

Efficient Cab scheduling

I came across this technical question while preparation. There are K cabs. ith cab takes ki minutes to complete any trip. What is the minimum time it will take to complete N trips with these K cabs. We can assume there is no waiting time in between…
Sandeep
  • 663
  • 2
  • 8
  • 18