Data Structures: Stacks, Queues, and Trees
Practice core operations and use cases for common data structures
Practice core operations and use cases for common data structures
CS - Grade 9-12
- 1
A stack starts empty. The operations are push(4), push(9), push(2), pop(), push(7), pop(). What values are removed by the two pop operations, in order, and what remains in the stack from bottom to top?
- 2
A queue starts empty. The operations are enqueue(A), enqueue(B), enqueue(C), dequeue(), enqueue(D), dequeue(). What values are removed by the two dequeue operations, in order, and what remains in the queue from front to back?
- 3
Explain the difference between LIFO and FIFO. Name one data structure that uses each rule.
- 4
A program checks whether parentheses are balanced in the expression (a + b) * (c + d). Which data structure is best for tracking the opening parentheses, and why?
- 5
A printer receives jobs in the order Job1, Job2, Job3, and Job4. If the printer processes jobs in the order they arrive, which data structure should manage the jobs? What job is processed first?
- 6
Draw or describe the binary tree with root 10, left child 5, right child 15, left child of 5 equal to 2, and right child of 5 equal to 7. Then list the leaf nodes.
- 7
For the binary tree with root A, left child B, right child C, left child of B equal to D, and right child of B equal to E, write the preorder traversal.
- 8
For the binary tree with root A, left child B, right child C, left child of B equal to D, and right child of B equal to E, write the inorder traversal.
- 9
For the binary search tree containing the values 8, 3, 10, 1, 6, 14, 4, 7, and 13, list the values in sorted order using an inorder traversal.
- 10
A binary search tree is empty. Insert the values 12, 5, 18, 2, 9, and 15 in that order. What are the left and right children of 12?
- 11
Choose the best data structure for an undo feature in a text editor: stack, queue, or tree. Explain your choice.
- 12
A customer service system must help customers in the same order they joined the waiting list. Choose the best data structure and explain what operation adds a customer and what operation serves a customer.
Related Cheat Sheets
More CS Worksheets
CS: Algorithms and Flowcharts
Grade 6-8 · 12 problems
CS: Arrays and Lists
Grade 9-12 · 12 problems
CS: Big-O Notation and Algorithm Efficiency
Grade 9-12 · 12 problems
CS: Binary Numbers and Number Systems
Grade 6-8 · 12 problems
More Grade 9-12 Worksheets
Linear Equations
Math · 8 problems
Cell Biology
Biology · 8 problems
Reading Comprehension
Language Arts · 8 problems
Historical Thinking & Evidence
Social Studies · 8 problems