{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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

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

View Full Document
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}
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 new input value that is already occupied by an existing data value. Without resolving the collision – the new input value is simply lost!

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern