• 117 questions

Data Structures and Algorithms Trivia Questions

Tap a choice for the answer and why, from a first stack to the worst case of quicksort.

What is a matrix called when nearly all its entries are zero?
More options

Answers checked November 30, 2026.

All 117 questions with answers

Checked against: xlinux.nist.gov, Wikipedia.

Arrays and lists

  • A, B and C are put one after another at the head of an empty linked list. How does it read from the head? Answer: C, B, A. NIST dictionary: linked list
  • The array 5, 8, 2, 9 is indexed from 1. Which number is at index 3? Answer: 2. NIST dictionary: array index
  • How does a skip list decide the level of a new item? Answer: At random. NIST dictionary: skip list
  • How must an ordinary linked list, in no order, be searched? Answer: One item at a time. NIST dictionary: linked list
  • In a circular list, what is the tail linked to? Answer: The head. NIST dictionary: circular list
  • In a doubly linked list, what does an item link to besides the next one? Answer: The previous one. NIST dictionary: doubly linked list
Show all 12
  • On which level does a search of a skip list begin? Answer: The highest. NIST dictionary: skip list
  • What do you give an array to get any of its items straight away? Answer: Its index. NIST dictionary: array
  • What does a self-organizing list change to make the average access faster? Answer: The order of its items. NIST dictionary: self-organizing list
  • What is a matrix called when nearly all its entries are zero? Answer: Sparse. NIST dictionary: sparse matrix
  • What is an array called when its size may change over time? Answer: Dynamic. NIST dictionary: dynamic array
  • You are holding one item of a doubly linked list. Why does taking it out cost constant time? Answer: It links to both its neighbors. NIST dictionary: doubly linked list

Stacks and queues

  • 1, 2 and 3 are pushed in that order, with pops whenever you like. In which order can they never come off? Answer: 3, 1, 2. NIST dictionary: stack
  • A printer takes jobs strictly in the order they came. Which structure fits? Answer: A queue. NIST dictionary: queue
  • A queue is empty. Add A, add B, remove, add C, remove. What is left? Answer: C. NIST dictionary: queue
  • A stack is empty. Push 1, push 2, pop, push 3, push 4, pop. What is on top? Answer: 3. NIST dictionary: stack
  • After what is the shunting-yard algorithm, which uses a stack, named? Answer: A railroad yard. Wikipedia: Reverse Polish notation
  • An emergency room always calls the most urgent case next. Which structure fits? Answer: A priority queue. NIST dictionary: priority queue
Show all 14
  • An undo key takes back the latest change first. Which structure fits? Answer: A stack. NIST dictionary: stack
  • How is the word deque pronounced? Answer: Like deck. NIST dictionary: deque
  • In the rules of a stack, what does top(push(v, S)) = v say? Answer: The last thing pushed is on top. NIST dictionary: stack
  • Items join a queue at the tail. Where do they leave it? Answer: At the head. NIST dictionary: queue
  • Using a stack, what is the value of 3 4 + 2 × in reverse Polish notation? Answer: 14. Wikipedia: Reverse Polish notation
  • What are the two basic operations of a stack called? Answer: Push and pop. NIST dictionary: stack
  • What can a deque do that a plain queue cannot? Answer: Add and remove at both ends. NIST dictionary: deque
  • What is a queue called when it holds no more than a fixed number of items? Answer: Bounded. NIST dictionary: bounded queue

Trees and heaps

  • 50, 30, 70 and 40 go into an empty binary search tree in that order. Where does 40 end up? Answer: Right child of 30. NIST dictionary: binary search tree
  • A B-tree is a good choice for a tree that is mostly kept where? Answer: On a disk. NIST dictionary: B-tree
  • A binary heap lies in an array that counts from 1. Where are the children of the node at index 4? Answer: 8 and 9. NIST dictionary: binary heap
  • A root A has a left child B and a right child C. In which order does a postorder traversal take them? Answer: B, C, A. NIST dictionary: postorder traversal
  • A treap is a binary search tree that is kept in the order of what as well? Answer: A heap. NIST dictionary: treap
  • By how much may the heights of a node's two subtrees differ in an AVL tree? Answer: One at most. NIST dictionary: AVL tree
Show all 17
  • How many nodes has a perfect binary tree of height 3, where the root alone has height 0? Answer: 15. NIST dictionary: perfect binary tree
  • In a binary search tree, where do the keys below a node go if they are smaller than its own? Answer: In its left subtree. NIST dictionary: binary search tree
  • In Huffman coding, which characters get the shortest codes? Answer: The most frequent. NIST dictionary: Huffman coding
  • What are two nodes with the same parent called? Answer: Siblings. NIST dictionary: sibling
  • What do the letters AVL in AVL tree come from? Answer: Its inventors' names. NIST dictionary: AVL tree
  • What does a red-black tree store in each node to keep itself nearly balanced? Answer: One extra bit. NIST dictionary: red-black tree
  • What is a tree node with no children called? Answer: A leaf. NIST dictionary: leaf
  • Where is the root of a tree usually drawn in computer science? Answer: At the top. NIST dictionary: tree
  • Which node of a heap holds the largest key, or the smallest if it is that kind of heap? Answer: The root. NIST dictionary: heap property
  • Which traversal takes the left subtree, then the root, then the right subtree? Answer: In-order. NIST dictionary: in-order traversal
  • Which word gave the trie its name? Answer: Retrieval. NIST dictionary: trie

Graphs

  • A graph has few edges for its vertices. Which way of storing it takes less room? Answer: Adjacency lists. NIST dictionary: adjacency-list representation
  • A triangle has edges of weight 4, 5 and 6. What does its minimum spanning tree weigh? Answer: 9. NIST dictionary: minimum spanning tree
  • The edges are A to B, A to C and B to D. Starting at A, in which order does a depth-first search meet the vertices, if it takes B before C? Answer: A, B, D, C. NIST dictionary: depth-first search
  • Every course has courses that must come before it. What puts them all in an order that works? Answer: A topological sort. NIST dictionary: topological sort
  • How many edges has a complete graph of five vertices? Answer: 10. NIST dictionary: complete graph
  • Some edges have negative weights, though no cycle does. Which algorithm still finds the shortest paths from one source? Answer: Bellman-Ford. NIST dictionary: Bellman-Ford algorithm
Show all 15
  • What do the algorithms of Kruskal and of Prim and Jarník both find? Answer: A minimum spanning tree. NIST dictionary: greedy algorithm
  • What does a breadth-first search usually keep its waiting vertices in? Answer: A queue. NIST dictionary: breadth-first search
  • What does a Hamiltonian cycle pass through exactly once? Answer: Every vertex. NIST dictionary: Hamiltonian cycle
  • What does the A in DAG stand for? Answer: Acyclic. NIST dictionary: directed acyclic graph
  • What is a graph called that can be drawn on paper with no edges crossing? Answer: Planar. NIST dictionary: planar graph
  • What is an undirected graph called when it is connected and has no cycle? Answer: A tree. NIST dictionary: tree
  • What is the degree of a vertex? Answer: The number of its edges. NIST dictionary: degree
  • What is the line between two vertices of a graph called? Answer: An edge. NIST dictionary: graph
  • What sort of graph is like a neighborhood of one-way streets? Answer: Directed. NIST dictionary: directed graph

Hashing

  • A hash table has 40 slots and 30 items. What is its load factor? Answer: 0.75. NIST dictionary: load factor
  • How many hash tables does cuckoo hashing use? Answer: Two. NIST dictionary: cuckoo hashing
  • In chaining, what deals with keys that land in the same slot? Answer: A linked list. NIST dictionary: chaining
  • In open addressing, where does a key go when its slot is taken? Answer: Into another slot of the table. NIST dictionary: open addressing
  • In which kind of hash table can the load factor be more than 1? Answer: One with chaining. NIST dictionary: load factor
  • Slots are 0 to 6, the hash is the remainder by 7, and a taken slot means the next empty one. Insert 10, 17, 3. Where is 3? Answer: Slot 5. NIST dictionary: linear probing
Show all 14
  • Slots are numbered 0 to 6 and the hash is the remainder after dividing by 7. Where does 24 go? Answer: Slot 3. NIST dictionary: hash table
  • What does a Bloom filter test quickly? Answer: Whether a key is in a set. NIST dictionary: Bloom filter
  • What happens to look-ups as the load factor rises? Answer: They get slower. NIST dictionary: load factor
  • What is a hash function called when it gives each key a number that no other key gets? Answer: Perfect. NIST dictionary: perfect hashing
  • What is it called when two keys hash to the same place? Answer: A collision. NIST dictionary: collision
  • What is linear probing especially prone to? Answer: Long runs of filled slots. NIST dictionary: primary clustering
  • Which abstract data type is a hash table a way of building? Answer: A dictionary. NIST dictionary: hash table
  • Why is cuckoo hashing named after the bird? Answer: A key can push another one out. NIST dictionary: cuckoo hashing

Sorting

  • 2, 6, 9 and 1, 7 are merged into one sorted list. Which number comes third? Answer: 6. NIST dictionary: merge
  • After whom is Shell sort named? Answer: Donald Shell. NIST dictionary: Shell sort
  • Into how many groups does the Dutch national flag problem part the items? Answer: Three. NIST dictionary: Dutch national flag
  • The list is 4, 2, 5, 1. What is it after one pass of bubble sort from the left? Answer: 2, 4, 1, 5. NIST dictionary: bubble sort
  • The list is 7, 3, 9, 1. Selection sort makes its first swap. What is the list now? Answer: 1, 3, 9, 7. NIST dictionary: selection sort
  • What does bogosort do until the items happen to be in order? Answer: Shuffles them. NIST dictionary: bogosort
Show all 15
  • What does heapsort build before it takes out the largest item again and again? Answer: A heap. NIST dictionary: heapsort
  • What does insertion sort do with the next item? Answer: Puts it in place among those sorted. NIST dictionary: insertion sort
  • What does introsort switch to when quicksort starts to go badly? Answer: Heapsort. NIST dictionary: introspective sort
  • What is a sort called when equal keys keep the order they came in? Answer: Stable. NIST dictionary: stable
  • What is a sort called when the items stay in the same storage? Answer: In-place. NIST dictionary: in-place sort
  • What is the item called that quicksort compares all the others with? Answer: The pivot. NIST dictionary: quicksort
  • When is counting sort a good choice? Answer: When the keys take few values. NIST dictionary: counting sort
  • Which data needs an external sort? Answer: Data too big for main memory. NIST dictionary: external sort
  • Which digit does a radix sort go by first, unless it is a top-down one? Answer: The least significant. NIST dictionary: radix sort

How the work grows

  • A list gets twice as long. How many more looks does a binary search need, in the worst case? Answer: One. NIST dictionary: binary search
  • A method takes a number of steps that goes with n squared. What happens to the steps if n doubles? Answer: Four times as many. NIST dictionary: polynomial
  • How does dynamic programming save work? Answer: It keeps answers to subproblems. NIST dictionary: dynamic programming
  • How does the time of merge sort grow with n items, whatever their order? Answer: n log n. NIST dictionary: merge sort
  • How does the time of quicksort grow in its worst case? Answer: n squared. NIST dictionary: quicksort
  • How does the time of selection sort grow with n items, whatever their order? Answer: n squared. NIST dictionary: selection sort
Show all 16
  • How does the time of the Floyd-Warshall algorithm grow with V vertices? Answer: V cubed. NIST dictionary: Floyd-Warshall algorithm
  • How does the time to look up, insert or delete grow in an AVL tree of n nodes, in the worst case? Answer: log n. NIST dictionary: AVL tree
  • The list is already in order. How does the time of bubble sort, which stops after a pass with no swap, grow? Answer: n. NIST dictionary: bubble sort
  • What does a greedy algorithm take at each step? Answer: The best choice right there. NIST dictionary: greedy algorithm
  • What does an amortized cost spread a price over? Answer: A sequence of operations. NIST dictionary: amortized cost
  • What does Θ say that big O does not? Answer: The growth is no slower, either. NIST dictionary: Θ
  • What is the least number of moves for a Tower of Hanoi of five disks? Answer: 31. NIST dictionary: towers of Hanoi
  • What is true of the answers to an NP-complete problem? Answer: They can be checked quickly. NIST dictionary: NP-complete
  • Which of these grows fastest as n gets large? Answer: 2 to the power n. NIST dictionary: exponential
  • Which of these is n² + 3n + 4, said with big O as tightly as it can be? Answer: O(n²). NIST dictionary: big-O notation

How this list was compiled: Written for this site; nothing was copied from another list. Questions and wrong choices are our own. The fact behind each answer is in the entry named and linked beside the question, and the explanations are our own sentences: 87 entries of the Dictionary of Algorithms and Data Structures of the U.S. National Institute of Standards and Technology (xlinux.nist.gov), and one article of the English Wikipedia (en.wikipedia.org, text under the Creative Commons Attribution-ShareAlike 4.0 license). Every page was fetched on November 30, 2026, and read beside its question. Where a question asks what a trace ends with (a stack, a pass of a sort, a look-up), we worked it out from the rule in the entry, and a second script ran it. Where growth is asked, the question says worst case, average or any order, or the entry gives one figure for all. The subject is structures and algorithms alone; no programming language, company or product is asked. Levels are our estimate: easy is fair for a first course, medium suits a student before a quiz, hard will stop some.

How it works

What is left on the stack, which structure fits, and how does the work grow? These data structures and algorithms trivia questions cover eight topics of a first course, with the reason after each answer.

Read the full guide

Eight rounds

Arrays and lists, Stacks and queues, Trees and heaps, Graphs, Hashing, Sorting, Searching and How the work grows. Choose one with Topic, in More options. Some questions ask which structure fits, some for a name, and some for a trace: what one pass of bubble sort leaves, or where linear probing puts a key.

Twenty questions for a club

Scored round: 20 questions, in More options, gives a score at the end. For paper, finish a set of ten, press Question sheet on the score card, press Add 5 more twice, tick With answer key and print.

  • Read a trace question out with a pencil in hand: draw the stack, the tree or the table before you look at the choices.

Questions and answers

What are some easy data structures questions?

What are the two operations of a stack? What is a tree node with no children called? What is it when two keys hash to the same place? Push and pop, a leaf, and a collision.

Which is better, an array or a linked list?

It depends on the job. An array gives any item by its index. A linked list is reached through its links, so finding an item takes a linear search, but taking one out of a doubly linked list takes constant time.

What is the worst case of quicksort?

It grows with n squared, though typically with n log n. Heapsort and merge sort grow with n log n.

How were the answers checked?

On November 30, 2026, each against the entry linked beside it: 87 in the NIST Dictionary of Algorithms and Data Structures and one Wikipedia article. Traces were worked out from the rule and run by a script.