Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm.

Slides:



Advertisements
Similar presentations
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
Advertisements

AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
AVL Trees COL 106 Amit Kumar Shweta Agrawal Slide Courtesy : Douglas Wilhelm Harder, MMath, UWaterloo
AVL Trees CS II – Fall /8/2010. Announcements HW#2 is posted – Uses AVL Trees, so you have to implement an AVL Tree class. Most of the code is provided.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
CS202 - Fundamental Structures of Computer Science II
Binary Trees, Binary Search Trees COMP171 Fall 2006.
CS 171: Introduction to Computer Science II
CSE332: Data Abstractions Lecture 7: AVL Trees Dan Grossman Spring 2010.
CSE332: Data Abstractions Lecture 7: AVL Trees Tyler Robison Summer
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
BST Data Structure A BST node contains: A BST contains
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
Cpt S 223 – Advanced Data Structures Course Review Midterm Exam # 2
Data Structures Using C++ 2E Chapter 11 Binary Trees and B-Trees.
Data Structures Using C++1 Chapter 11 Binary Trees.
Version TCSS 342, Winter 2006 Lecture Notes Trees Binary Trees Binary Search Trees.
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees Nicki Dell Spring 2014 CSE373: Data Structures & Algorithms1.
Advanced Data Structures and Algorithms COSC-600 Lecture presentation-6.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Trees.
Chapter 19 - basic definitions - order statistics ( findkth( ) ) - balanced binary search trees - Java implementations Binary Search Trees 1CSCI 3333 Data.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templatized Tree.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm.
BINARY SEARCH TREE. Binary Trees A binary tree is a tree in which no node can have more than two children. In this case we can keep direct links to the.
1 Binary Trees Informal defn: each node has 0, 1, or 2 children Informal defn: each node has 0, 1, or 2 children Formal defn: a binary tree is a structure.
Review for Final Andy Wang Data Structures, Algorithms, and Generic Programming.
1 Trees 4: AVL Trees Section 4.4. Motivation When building a binary search tree, what type of trees would we like? Example: 3, 5, 8, 20, 18, 13, 22 2.
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Grammars and Parsing  Recursive Definitions of Properties.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Final.
CSE373: Data Structures & Algorithms Lecture 6: Binary Search Trees continued Aaron Bauer Winter 2014 CSE373: Data Structures & Algorithms1.
Review for Exam 1 Topics covered: –Asymptotic analysis –Lists and list implementations Stacks and queues –General trees, binary trees –BST For each of.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Rooted Tree a b d ef i j g h c k root parent node (self) child descendent leaf (no children) e, i, k, g, h are leaves internal node (not a leaf) sibling.
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees Linda Shapiro Winter 2015.
Lecture 10COMPSCI.220.FS.T Binary Search Tree BST converts a static binary search into a dynamic binary search allowing to efficiently insert and.
Data Structures Using C++ 2E Chapter 11 Binary Trees.
Trees CSIT 402 Data Structures II 1. 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical.
Final Exam Review COP4530.
CSE332: Data Abstractions Lecture 7: AVL Trees
CSE 373 Data Structures Lecture 7
Chapter 12 – Data Structures
CC 215 Data Structures Trees
UNIT III TREES.
CS202 - Fundamental Structures of Computer Science II
CS202 - Fundamental Structures of Computer Science II
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees
CSE 373 Data Structures Lecture 7
Cse 373 April 26th – Exam Review.
November 1st – Exam Review
Binary Trees, Binary Search Trees
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
CSE 326: Data Structures: Midterm Review
AVL Trees CENG 213 Data Structures.
CS202 - Fundamental Structures of Computer Science II
Trees CSE 373 Data Structures.
Final Exam Review COP4530.
CSE373: Data Structures & Algorithms Lecture 5: AVL Trees
CS223 Advanced Data Structures and Algorithms
CSE 332: Data Abstractions AVL Trees
Binary Trees, Binary Search Trees
CS223 Advanced Data Structures and Algorithms
CS202 - Fundamental Structures of Computer Science II
Final Review Dr. Yingwu Zhu.
Trees CSE 373 Data Structures.
1 Lecture 13 CS2013.
Trees CSE 373 Data Structures.
Binary Trees, Binary Search Trees
CS202 - Fundamental Structures of Computer Science II
CS202 - Fundamental Structures of Computer Science II
Presentation transcript:

Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm Exam # 1

Midterm Exam 1 When: Wednesday (02/27) 12:10 -1pm Where: In Class Closed book, Closed notes Comprehensive Material for preparation:  Lecture Slides  Homeworks and Programming assignments  Weiss book

Course Overview Math and C++ Review (Chapter 1) Algorithm development and analysis (Chapter 2)  Running time Abstract Data Types (Chapter 3)  Linked Lists, Stacks and Queues  Insert, delete, search, sort Trees (Chapter 4)  Tree Traversals  Binary Trees  Binary Search Trees  AVL Trees

Math Review (Chapter 1) Floors, ceilings, exponents and logarithms  Definitions and manipulations Series: Arithmetic and Geometric series  Definitions and manipulations

Math Review (Chapter 1) Proof Techniques: Read the definition, components, and how to use the following  Proof by induction Example: Prove (is a perfect square)  Proof by counterexample  Proof by contradiction Recursion  Read the definition and rules  Analyze running time of recursive algorithm

C++ Review (Chapter 1) Classes and Objects and Methods  Default Parameters, Initializer List, explicit Constructor, Destructor, Constant Member Function  Copy constructor, operator overloading, operator= Call by value, Call by reference, Call by constant reference Templates  Function templates and Class templates STL for different data structures

Algorithm Analysis (Chapter 2) Asymptotic analysis of an algorithm Best-case, worst-case and average-case analysis Rate of growth: Definitions and Notation (O, Ω, Θ, o)  Proofs for specific examples

Asymptotic Notations O() – upper bound  () – lower bound  () – tight bound o() – strict upper bound

Asymptotic Analysis (Chapter 2) O-notation gives an upper bound for a function to within a constant factor  - notation gives an lower bound for a function to within a constant factor  -notation bounds a function to within a constant factor  The value of f(n) always lies between c 1 g(n) and c 2 g(n) inclusive

Maximum Subsequence Sum Problem (Chapter 2) Maximum subsequence sum problem  Given (possibly negative) integers A 1, A 2, …, A N, find the maximum value (≥ 0) of:  E.g.  Solution # 1:  Solution # 2:  Solution # 3: Recursive, “divide and conquer”  Solution # 4 : Online Algorithm The maximum sum is 16 T(N) = O(N 3 ) T(N) = O(N 2 ) T(N) = O(N logN) T(N) = O(N)

Abstract Data Types (Chapter 3) Lists  Operations: Insert, Delete, Search  Implementations: vectors, singly-linked lists, double- linked lists  Analysis of operations for each implementation  Time complexity Stacks (LIFO)  Operations: Push, Pop, Top  Implementations: linked-list, vector (tradeoffs)  Analysis of operations for each implementation  Time complexity

Abstract Data Types (Chapter 3) Queues (FIFO)  Operations: Enqueue, dequeue  Implementations: linked-list, vector (tradeoffs)  Analysis of operations for each implementation Standard Template Library (STL)  Use of vector, list, stack and queue template classes  Use of iterators Understand all the tradeoffs (in time and space) between all these data structures Given the class information and few methods write the pseudo code of the remaining methods

Trees (Chapter 4): Binary Tree Binary Tree Traversals  Pre-order traversal: root, left, right The work at a node is performed before (pre) its children are processed  In-order traversal: left, root, right  Post-order traversal: left, right, root The work at a node is performed after (post) its children are evaluated Constructing a Binary Tree form pre-order, in-order and post-order traversals

Tree Traversal Problem Construct a Binary Tree from given in-order and pre- order tree traversals output:  The inOrder traversal of the tree is: left, root, right  The preOrder traversal of the tree is: root, left, right

Binary Search Tree (BST)  Binary search tree (BST) is a tree where: For any node n, items in left subtree of n  item in node n  items in right subtree of n  Average depth of a BST is O(logN)  Operations: Insert, Delete, Search, FindMin, FindMax, traversals  Worst-case and Average-case analysis

Insert operation on a BST insert(T, x)  Inserts x into the BST T  E.g. insert 5

Remove operation on a BST (Case 1) remove(T, x)  Removes x from the BST T  Case 1: Node to remove has 0 or 1 child If a node is a leaf, just delete it If the node has one child, the node can be deleted after its parent adjust a link to bypass the node E.g. remove 4

Remove operation on a BST (Case 2) remove(T, x)  Removes x from the BST T  Case 2: Node to remove has 2 children Replace the data of this node with the smallest data of the right subtree and recursively delete that node (which is now empty)  Smallest node in the right subtree cannot have a left child, the second remove is an easy one First Replace node element with successor Remove successor (Case 1) E.g. remove 2 Construct a BST from a sequence of values using insert and remove operation

AVL Trees Balanced BST (AVL trees)  The height of the left and right subtrees at every node in the BST differ by at most 1  Maintained via rotations operations  Depth always O(log 2 N)  Operations: Insert, Search, FindMin, FindMax  AVL Insert (Remember 4 Cases)  Work out how to perform these on an AVL tree and show the resulting AVL tree from a given sequence

AVL Trees Which of the following is an AVL tree? AVL tree?

AVL Insert Insert can violate the AVL balance condition Can be fixed by a rotation Inserting 6 violates AVL balance condition Rotating 7-8 restores balance

AVL Insert (4 Cases) Assume node k needs to be rebalanced Four cases leading to violation Case 1: An insertion into the left subtree of the left child of k Case 2: An insertion into the left subtree of the right child of k Case 3: An insertion into the right subtree of the left child of k Case 4: An insertion into the right subtree of the right child of k  Cases 1 and 4 are handled by single rotation  Cases 2 and 3 are handled by double rotation

Identifying Cases for AVL Insert k Let this be the node with the violation (i.e, imbalance) (nearest to the last insertion site) Insert CASE 1 Insert CASE 2 Insert CASE 3 Insert CASE 4 right child left child left subtree right subtree

Exercise AVL Insert Case 3 + Case 4 + Case 1 + Case 2: Example Start with an empty AVL tree and insert the items 3, 2, 1 and then 4 through 7 in sequential order  Insert 10 through 16 in reverse order, followed by 8 and then 9 CASE 3: Right-left double rotation CASE 1: Single right rotation CASE 2: Left-right double rotation

Tentative Midterm Exam#1 Structure Part I (45 pts): Coding Questions  Given the class information and few methods write the pseudo code of the remaining methods  Provide the runtime complexity of different methods Part II (55 pts): Conceptual & Enumerative Questions  Mathematical Proof  Binary Search Tree/Binary Tree Traversal  AVL Tree

Good Luck !