Exam Review 3 Chapters 10 – 13, 15 CSC212 Section FG CS Dept, CCNY.

Slides:



Advertisements
Similar presentations
Chapter 7. Binary Search Trees
Advertisements

CS16: Introduction to Data Structures & Algorithms
Chapter 12 Binary Search Trees
Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
Comp 122, Spring 2004 Binary Search Trees. btrees - 2 Comp 122, Spring 2004 Binary Trees  Recursive definition 1.An empty tree is a binary tree 2.A node.
Transform and Conquer Chapter 6. Transform and Conquer Solve problem by transforming into: a more convenient instance of the same problem (instance simplification)
S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
Tree Data Structures &Binary Search Tree 1. Trees Data Structures Tree  Nodes  Each node can have 0 or more children  A node can have at most one parent.
CS 206 Introduction to Computer Science II 03 / 23 / 2009 Instructor: Michael Eckmann.
1 HeapSort CS 3358 Data Structures. 2 Heapsort: Basic Idea Problem: Arrange an array of items into sorted order. 1) Transform the array of items into.
@ Zhigang Zhu, CSC212 Data Structure - Section FG Lecture 22 Recursive Sorting, Heapsort & STL Quicksort Instructor: Zhigang Zhu Department.
Exam Review 3 Chapters 10 – 13, 15 CSC212 Section FG CS Dept, CCNY.
Main Index Contents 11 Main Index Contents Tree StructuresTree Structures (3 slides) Tree Structures Tree Node Level and Path Len. Tree Node Level and.
CS 206 Introduction to Computer Science II 11 / 04 / 2009 Instructor: Michael Eckmann.
Version TCSS 342, Winter 2006 Lecture Notes Priority Queues Heaps.
BST Data Structure A BST node contains: A BST contains
Graphs & Exam Review 3 Chapter 10 – 13 CS211 CS Dept, MHC.
Chapter 6: Priority Queues Priority Queues Binary Heaps Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
1 abstract containers hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1) set.
Trees Main and Savitch Chapter 10. Binary Trees A binary tree has nodes, similar to nodes in a linked list structure. Data of one sort or another may.
B-trees (Balanced Trees) A B-tree is a special kind of tree, similar to a binary tree. However, It is not a binary search tree. It is not a binary tree.
Compiled by: Dr. Mohammad Alhawarat BST, Priority Queue, Heaps - Heapsort CHAPTER 07.
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CS Data Structures Chapter 15 Trees Mehmet H Gunes
ADT Table and Heap Ellen Walker CPSC 201 Data Structures Hiram College.
Information and Computer Sciences University of Hawaii, Manoa
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
1 Trees A tree is a data structure used to represent different kinds of data and help solve a number of algorithmic problems Game trees (i.e., chess ),
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Chapter 21 Binary Heap.
Review for Final Andy Wang Data Structures, Algorithms, and Generic Programming.
P p Chapter 10 has several programming projects, including a project that uses heaps. p p This presentation shows you what a heap is, and demonstrates.
CSC 213 – Large Scale Programming Lecture 15: Heap-based Priority Queue.
Trees CS 105. L9: Trees Slide 2 Definition The Tree Data Structure stores objects (nodes) hierarchically nodes have parent-child relationships operations.
Chapter 2: Basic Data Structures. Spring 2003CS 3152 Basic Data Structures Stacks Queues Vectors, Linked Lists Trees (Including Balanced Trees) Priority.
CSC211 Data Structures Lecture 18 Heaps and Priority Queues Instructor: Prof. Xiaoyan Li Department of Computer Science Mount Holyoke College.
1 CSC212 Data Structure - Section AB Lecture 22 Recursive Sorting, Heapsort & STL Quicksort Instructor: Edgardo Molina Department of Computer Science City.
Data Structures Using C++1 Chapter 10 Sorting Algorithms.
CSC212 Data Structure Lecture 16 Heaps and Priority Queues Instructor: George Wolberg Department of Computer Science City College of New York.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R3. Priority Queues.
CISC220 Fall 2009 James Atlas Dec 07: Final Exam Review.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
@ Zhigang Zhu, CSC212 Data Structure - Section FG Lecture 17 B-Trees and the Set Class Instructor: Zhigang Zhu Department of Computer Science.
Final Exam Review COP4530.
CSCE 210 Data Structures and Algorithms
Trees Chapter 15.
CSC212 Data Structure - Section AB
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Sorting Chapter 13 presents several common algorithms for sorting an array of integers. Two slow but simple algorithms are Selectionsort and Insertionsort.
Bohyung Han CSE, POSTECH
Priority Queues Sections 6.1 to 6.5.
Chapter 22 : Binary Trees, AVL Trees, and Priority Queues
Review for Midterm Neil Tang 03/04/2010
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.
original list {67, 33,49, 21, 25, 94} pass { } {67 94}
i206: Lecture 14: Heaps, Graphs intro.
CSC212 Data Structure - Section RS
Balanced-Trees This presentation shows you the potential problem of unbalanced tree and show two way to fix it This lecture introduces heaps, which are.
Final Exam Review COP4530.
ITEC 2620M Introduction to Data Structures
B-Trees This presentation shows you the potential problem of unbalanced tree and show one way to fix it This lecture introduces heaps, which are used.
Heaps Chapter 11 has several programming projects, including a project that uses heaps. This presentation shows you what a heap is, and demonstrates.
Balanced-Trees This presentation shows you the potential problem of unbalanced tree and show two way to fix it This lecture introduces heaps, which are.
Chapter 10 1 – Binary Trees Tree Structures (3 slides)
Sorting Chapter 13 presents several common algorithms for sorting an array of integers. Two slow but simple algorithms are Selectionsort and Insertionsort.
Final Review Dr. Yingwu Zhu.
CSC 143 Binary Search Trees.
B-Trees This presentation shows you the potential problem of unbalanced tree and show one way to fix it This lecture introduces heaps, which are used.
Presentation transcript:

Exam Review 3 Chapters 10 – 13, 15 CSC212 Section FG CS Dept, CCNY

Trees and Traversals Tree, Binary Tree, Complete Binary Tree –child, parent, sibling, root, leaf, ancestor,... Array Representation for Complete Binary Tree –Difficult if not complete binary tree A Class of binary_tree_node –each node with two link fields Tree Traversals –recursive thinking makes things much easier A general Tree Traversal –A Function as a parameter of another function

Binary Search Trees (BSTs) Binary search trees are a good implementation of data types such as sets, bags, and dictionaries. Searching for an item is generally quick since you move from the root to the item, without looking at many other items. Adding and deleting items is also quick. But as you'll see later, it is possible for the quickness to fail in some cases -- can you see why? ( unbalanced )

Heaps Heap Definition –A complete binary tree with a nice property Heap Applications –priority queues (chapter 8), sorting (chapter 13) Two Heap Operations – add, remove –reheapification upward and downward –why is a heap good for implementing a priority queue? Heap Implementation –using binary_tree_node class –using fixed size or dynamic arrays

B-Trees A B-tree is a tree for sorting entries following the six rules B-Tree is balanced - every leaf in a B-tree has the same depth Adding, erasing and searching an item in a B-tree have worst-case time O(log n), where n is the number of entries However the implementation of adding and erasing an item in a B-tree is not a trivial task.

Trees - Time Analysis Big-O Notation : –Order of an algorithm versus input size (n) Worse Case Times for Tree Operations –O(d), d = depth of the tree Time Analysis for BSTs –worst case: O(n) Time Analysis for Heaps –worst case O(log n) Time Analysis for B-Trees –worst case O(log n) Logarithms and Logarithmic Algorithms –doubling the input only makes time increase a fixed number

Searching Applications –Database, Internet, AI... Most Common Methods –Serial Search – O(n) –Binary Search – O(log n) –Search by Hashing - O(k) Run-Time Analysis –Average-time analysis –Time analysis of recursive algorithms

Quadratic Sorting Both Selectionsort and Insertionsort have a worst- case time of O(n 2 ), making them impractical for large arrays. But they are easy to program, easy to debug. Insertionsort also has good performance when the array is nearly sorted to begin with. But more sophisticated sorting algorithms are needed when good performance is needed in all cases for large arrays.

O(NlogN) Sorting Recursive Sorting Algorithms –Divide and Conquer technique An O(NlogN) Heap Sorting Algorithm –making use of the heap properties STL Sorting Functions –C++ sort function –Original C version of qsort

Graphs Examples/Applications Terminologies Representations Graph Traversal

void merge(int data[ ], size_t n1, size_t n2) // Precondition: The first n1 elements of data are sorted, and the // next n2 elements of data are sorted (from smallest to largest). // Postcondition: The n1+n2 elements of data are now completely // sorted.

Quiz Using the binary_tree_node from page 481, write a recursive function to meet the following specification. Check as much of the precondition as possible. template void flip(binary_tree_node * root_ptr) // Precondition: root_ptr is the root pointer of a non-empty binary tree. // Postcondition: The tree is now the mirror image of its original value. // Example original tree: Example new tree: // 1 1 // / \ / \ // // / \ / \ // //retrievals data left right //set set_data set_left set_right //boolean is_leaf