Choosing structures and finding bugs

How to match a problem to a structure by the operations it needs, and how to find the memory and index bugs that data structure code attracts.

About 4 hours of study

Learning objectives

Lessons

  1. 1

    Choosing a data structure

    The cost of each operation on every structure in this course, side by side, and how to pick one for a problem.

  2. 2

    Data structure bugs

    Popping an empty stack, reading a node after freeing it, and a queue that runs off its array: three bugs StepVioz stops for you.

Module practice

Module quiz

1. A program must always remove its smallest item next. Which structure fits best?
2. What should pop do when the stack is empty?
3. Order does not matter, and records are looked up by key very often. Which structure is fastest on average?
4. A program must find keys quickly and also print them in sorted order. Which structure fits best?
5. What is wrong with the two statements free(p); p = p->next; ?
6. A linked queue holds one item, and it is dequeued. What must happen to its pointers?
7. Why can a plain array beat a hash table when there are only 20 items?

‹ Hash tables and graphsAdvanced structures ›