This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: COMP 250 Winter 2010 17 - trees Feb 15, 2010 (Rooted) Tree ADT Thus far we have been working with linear collections, namely lists . For each element, it made sense to talk about the previous element (if it exists) and the next element (if it exists). We saw two data structures for representing lists, namely linked lists and arrays. Both have limitations, though, in that certain common operations are O ( n ). For linked lists, finding the i th element is O ( n ). For arrays, add an element at the i th position is O ( n ), as is removing the element at the i th position if we require that the array doesnt have any holes. To get around these limitations, one often organizes a collection of items in a non-linear way. In the next several lectures, we will look at some examples. Today we begin with (rooted) trees . Like a list, a (rooted) tree is composed of nodes that reference one another. With a tree, each node can have one parent and multiple children. You can think of the parent as the prev node and the children as next nodes. What is new here is that a node can have multiple children, whereas in a linked list a node has (at most) one next node. You are familiar with the concept of (rooted) trees already. Here are a few examples. Many organizations have a hierarchical structures that are trees. For example, as a McGill professor in the School of Computer Science, I report to my department Chair, who reports to the Dean of Science, who reports to the McGill Provost, who reports to the Principal. A professor in the Department of Electrical and Computer Engineering reports to the Chair of ECE, who reports to the Dean of Engineering, who like the Dean of Science reports to the Provost, who reports to the Principal. (The B reports to A relationship in an organization hierarchy defines a B is a child of A relation in a tree see below)....
View Full Document
- Spring '08
- Computer Science