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
1 answer

Time complexity: deleting element of deque

What is the time complexity of deleting an element of collections.deque? E.g.: deq = collections.deque([1, 2, 3]) del deq[1]
10
votes
9 answers

First Name Variations in a Database

I am trying to determine what the best way is to find variations of a first name in a database. For example, I search for Bill Smith. I would like it return "Bill Smith", obviously, but I would also like it to return "William Smith", or "Billy…
Joseph Ferris
  • 12,576
  • 3
  • 46
  • 72
10
votes
3 answers

Using std::set container for range items

I'd like to store a bunch of range items in std::set container. This data structure should provide fast decision whether a specific input range contained by one of the ranges that the set currently holds, by overloading the comparison of std::set…
Irad K
  • 867
  • 6
  • 20
10
votes
2 answers

Issues with understanding Dining table optimal seating algorithm

I was reading through a problem and was trying to solve this problem. You've invited N people over for dinner. Let's say 4. You have a circular dinner table and you wish to seat everyone around it. Unfortunately, not all of your friends are…
SFer
  • 109
  • 4
10
votes
1 answer

Data-structural bootstrapping examples?

I recently read Okasaki and Brodal's paper "Optimal Purely Functional Priority Queues," which describes a fast priority queue based on data-structural bootstrapping, in which a simple and inefficient data structure is used to construct a robust and…
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
10
votes
4 answers

Datastructure and algorithm to detect collisions of irregular shaped moving objects

I came across this interview question Many irregularly shaped objects are moving in random directions. Provide a data structure and algorithm to detect collisions. Remember that the number of objects is in the millions. I am assuming that every…
garima
  • 5,154
  • 11
  • 46
  • 77
10
votes
3 answers

Delete a node in singly linked list in Rust

I am new to Rust and want to write linked list in Rust to have fun. I am confused about how to delete a node in the linked list. Here is my simple code. #[derive(Debug)] struct Node{ v: usize, next: Option>, } struct LinkedList…
YjyJeff
  • 833
  • 1
  • 6
  • 14
10
votes
6 answers

Why does HashMap resize() again, when specifying a precise capacity?

Code speaks more than words, so: final int size = 100; Map m = new HashMap<>(size); for (int i = 0; i < size; i++) m.put(i, String.valueOf(i)); Why is the HashMap internally calling resize() 21 2 times! (Credit to Andreas for…
James Wierzba
  • 16,176
  • 14
  • 79
  • 120
10
votes
3 answers

Find all (english word) substrings of a given string

This is an interview question: Find all (english word) substrings of a given string. (every = every, ever, very). Obviously, we can loop over all substrings and check each one against an English dictionary, organized as a set. I believe the…
Michael
  • 41,026
  • 70
  • 193
  • 341
10
votes
1 answer

How can I store multiple elements in a Rust HashMap for the same key?

I have a HashMap. Sender is a open connection object and the key is a user id. Each user can connect from multiple devices. I need to store all possible open connections for the same user id. After this I can iterate and send messages…
Dennis
  • 1,805
  • 3
  • 22
  • 41
10
votes
2 answers

Sorting a queue using same queue

I have been asked this question and I think it's doable, However I am having a hard time coming up with an algorithm to do this. The restrictions is that you can not use any other data structure nor create another queue. Also you only can use…
3ashmawy
  • 469
  • 1
  • 7
  • 16
10
votes
2 answers

Find minimum number of operation of specific function

I got this question from an company's interview but I could not find the minimum (according to me minimum operations are highest number or lowest number) but I'm not sure. Please can someone help me? Thanks The question is :- Given an array and…
Abc
  • 109
  • 1
  • 3
10
votes
2 answers

Is there a drop-in replacement for Java Stack that is not synchronized?

I have a large codebase (written by me) that uses the Stack data structure. This was used for convenience and I am using it as Stack sometimes or Vector/List some other times. After a performance review however it was decided that we do not want to…
kazanaki
  • 7,988
  • 8
  • 52
  • 79
10
votes
2 answers

How does one implement graph algorithms that require efficient contraction and expansion of connected components?

There are some algorithms, like Edmond's Algorithm, or Boruvka's Algorithm which require the programmer to create a graph which is obtained by contraction of some nodes into a single node, and later expanding it back. A formal description of…
10
votes
2 answers

Vue.js and Immutable.js

I'm working on a Vue.js application where I have to deal with deeply nested data structures (trees and forests). After reading about using simple data structures, pure functions and reducing (non-local) mutation, I belief that embracing those ideas…
Willem-Aart
  • 2,200
  • 2
  • 19
  • 27