Chapter Review

11.5. Chapter Review#

  1. What does LIFO stand for, and which data structure follows this principle? What does FIFO stand for, and which data structure follows this principle?

  2. What is the difference between a generic collection (e.g., Stack<T>) and a non-generic collection (e.g., Stack) in C#? Why are generic collections generally preferred?

  3. Describe the two primary operations of a Stack. What happens if you call Pop() on an empty stack?

  4. Describe the two primary operations of a Queue. Give a real-world scenario where a queue would be the appropriate data structure to use.

  5. A LinkedList<T> stores nodes that each point to the next node. How does this differ from an array in terms of:

    • Memory layout

    • Accessing an element by index

    • Inserting an element in the middle

  6. What is a hash table, and why does it provide near constant-time O(1) lookup on average? What C# collection type is built on a hash table?

  7. You need to store a set of tasks to process in the order they arrive. Which collection type would you choose — Stack<T>, Queue<T>, or List<T>? Explain.

  8. You need to temporarily save and restore a series of states (like an undo feature). Which collection type is most appropriate? Explain.

  9. What is the relationship between the data structures covered in this chapter (arrays, stacks, queues, linked lists, hash tables, trees) and the C# collection classes in System.Collections.Generic? Give two concrete examples.

  10. A tree data structure has a root node, and each node may have child nodes. What distinguishes a tree from a general graph?