day7 - COP 3503 Computer Science II CLASS NOTES - DAY #7...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 3503 – Computer Science II CLASS NOTES - DAY #7 General Trees A tree consists of a set of nodes and a set of edges that connect pairs of nodes. A tree is an instance of a more general data structure known as a graph. We will be concerned with rooted trees . A rooted tree has the following characteristics: One node is distinguished as the root node . Every node c (except the root node) is connected by an edge from exactly one other node p . The node p is c’s parent. The node c is one of p’s children. A leaf node has no children. There is a unique path from the root to each node in the tree. The number of edges that must be traversed to go from node a to node b is called the path length from a to b . Siblings are all the child nodes on the same ply or all nodes with the same path length from the root. The tree data structure is a fundamental one in computer science. Many operating systems arrange their file systems using tree structures, thus you have directories with sub-directories and so on. Tree structures are also often used by compilers during their parsing and code generation phases for handling arithmetic expressions and other constructs in the language being compiled. An example of a general tree is shown below followed by an example illustrating its use as an expression tree. Day 7 - 1 leaf nodes ply A B C D E F G H I J K A general tree
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Trees are commonly implemented like a linked list, albeit with more pointers involved. Since traversing the tree requires movement both up and down the tree, pointers in both directions from a given node are typical. A node has the following general format. For the root node: the pointer to the parent is null For a leaf node: the set of pointers to the children are all null For an internal node: the pointers all have values Binary Search Trees (BST) Used for dynamic searching. A tree where each node can have at most two children. Some sort of ordering is imposed on the nodes of the tree. Typically supports three operations: 1. insertion 2. deletion 3. find – (name or rank) – worst case: O(N), average case: O(log 2 N) Day 7 - 2 + * b c a An Expression Tree Expression: a + b * c pointer to parent data value {pointers to children}
Background image of page 2
Hash Tables Provides dynamic searching capabilities based upon name alone. Avoids two problems of the BST. (1) Not O(N) in the worst case, and (2) does not require the repetitive memory maintenance of the BST which requires reorganization of the tree after every insertion and deletion. A hashing function is associated with the table that converts an input value (a key value) into an integer value that represents an address within the table (a location in the hash table). Data collision results any time that the hash function yields an address for a
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/22/2009 for the course COP 3503c taught by Professor Staff during the Spring '08 term at University of Central Florida.

Page1 / 10

day7 - COP 3503 Computer Science II CLASS NOTES - DAY #7...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online