Skip to main content

Section C.10 A1: Lists and Trees

Synopsis.

  • Start with the example from last time (reading in person records).

  • Show that reading into a local array is not nice because we are limited in the amount of records to read. Alternatives may be reading file twice or starting file with number of records. We don't want that.

  • Need list of records that grows while reading: array list using realloc. Discuss amortized complexity of appending.

  • Alternative linked list. Discuss and show implementation.

  • Summarize pros and cons of array lists vs linked lists.

  • Discuss trees. Hierarchical data structure. Mostly used to implement sets or maps.

  • Basic property: Set of nodes where each node is linked to multiple children but each node has at most one parent.

  • Discuss basic notions: labels/keys, parent, child, root, graph of a tree, size, height, depth and present height computation as a simple recursive algorithm.

  • Discuss search trees and search tree property. Show searching and insertion. Discuss complexity of search in balanced trees. Of course, insertion may violate balancedness.

  • Introduce tries as maps where keys are sequences of things.

  • Present searching and inserting in tries.

Sections Covered.

Section 5.1, Section 5.2