1 / 10

ITEC 2620M Introduction to Data Structures

ITEC 2620M Introduction to Data Structures. Instructor: Prof. Z. Yang Course Website: http://people.math.yorku.ca/~zyang/itec2620m.htm Office: TEL 3049. Double Linked List and Binary Trees. Key Points of this Lecture. Multiple pointers Doubly linked lists Binary trees Binary search trees.

rune
Download Presentation

ITEC 2620M Introduction to Data Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ITEC 2620MIntroduction to Data Structures Instructor: Prof. Z. Yang Course Website: http://people.math.yorku.ca/~zyang/itec2620m.htm Office: TEL 3049

  2. Double Linked Listand Binary Trees

  3. Key Points of this Lecture • Multiple pointers • Doubly linked lists • Binary trees • Binary search trees

  4. Doubly Linked List • Designed to allow convenient access from a list node to the next node and also to the preceding node on the list. • Storing two pointers • One to the node following it • A second pointer to the node preceding it • Code

  5. Binary Trees • A binary tree is a structure that is either empty or which consists of one node connected to two disjoint (binary) subtrees • disjoint – no common nodes • Each node of a binary tree has a value, a pointer to a left child node, and a pointer to a right child node (pointers may be NULL) • A node is the parent of its child nodes • Example

  6. More Definitions • Length, path, ancestor, descendant, height, leaf, internal nodes • A minimum-level binary tree has all levels full except the last level • A complete binary tree is a minimum-level binary tree with nodes filled in from the left on the last level • A full binary tree is a binary tree where each node has either 0 or 2 children (also called 2-tree )

  7. Binary Search Trees • BST property: • For each node (with a key value of K) in the binary tree, all nodes in the left sub-tree will have key values less than K, and all nodes in the right sub-tree will have key values greater than K

  8. Searching BSTs • If node has same key value, return it • If node has larger key value, search the left sub-tree • If node has smaller key value, search the right sub-tree • if BST is “balanced”, we get binary search • a full binary search tree has “ideal” balancing • ~ 50% on each side of each node

  9. Complexity • Code • What is the complexity for find? • Best • root node • O(1) • Worst • end node • O(n) • Average • depends on shape of tree! • on average (i.e. reasonably balanced trees), O(logn)

  10. Benefits of BST • Balanced BSTs have O(logn) worst and average case find – like binary search on an array • BSTs have O(1) insert – like linked lists

More Related