Playground Design Karl Lieberherr. Playground A collection of algorithms to define – what is wanted from a solve algorithm S in a particular domain (inputs/outputs)

Slides:



Advertisements
Similar presentations
1 Functional Programming Lecture 8 - Binary Search Trees.
Advertisements

Binary Trees Chapter 6. Linked Lists Suck By now you realize that the title to this slide is true… By now you realize that the title to this slide is.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 10 Ming Li Department of.
CS 261 – Winter 2010 Binary Search Trees. Can we do something useful? How can we make a collection using the idea of a binary tree? How about starting.
1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in.
10. Binary Trees A. Introduction: Searching a linked list.
1 BST Trees A binary search tree is a binary tree in which every node satisfies the following: the key of every node in the left subtree is.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Introduction to trees.
B+ Tree What is a B+ Tree Searching Insertion Deletion.
Binary Tree. Binary Trees – An Informal Definition A binary tree is a tree in which no node can have more than two children Each node has 0, 1, or 2 children.
CS 261 – Fall 2009 Binary Search Trees Again, but in detail.
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
1 TK1924 Program Design & Problem Solving Session 2011/2012 L8: Binary Trees.
Searching: Binary Trees and Hash Tables CHAPTER 12 6/4/15 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education,
Binary Trees Chapter Definition And Application Of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two.
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 ),
AVL Trees Neil Ghani University of Strathclyde. General Trees Recall a tree is * A leaf storing an integer * A node storing a left subtree, an integer.
INTRODUCTION TO BINARY TREES P SORTING  Review of Linear Search: –again, begin with first element and search through list until finding element,
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
Tree (new ADT) Terminology:  A tree is a collection of elements (nodes)  Each node may have 0 or more successors (called children)  How many does a.
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
Starting at Binary Trees
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
Binary Search Tree Traversal Methods. How are they different from Binary Trees?  In computer science, a binary tree is a tree data structure in which.
Midterm CSG 110 Karl Lieberherr. Managing Software Development Managers of software development must first be software developers.
Lecture – Searching a Tree Neil Ghani University of Strathclyde.
AVL Trees. AVL Node Structure The AVL node structure follows the same structure as the binary search tree, with the addition of a term to store the.
Trees 2: Section 4.2 and 4.3 Binary trees. Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children
Binary Trees In computer science, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left.
H EAPS. T WO KINDS OF HEAPS : MAX AND MIN Max: Every child is smaller than its parent Meaning the max is the root of the tree 10 / \ 9 7 / \ 6 8 / \ 2.
Binary Tree. Some Terminologies Short review on binary tree Tree traversals Binary Search Tree (BST)‏ Questions.
1/14/20161 BST Operations Data Structures Ananda Gunawardena.
1 Chapter 4 Trees Basic concept How tree are used to implement the file system How tree can be used to evaluate arithmetic expressions How to use trees.
Binary Search Trees (BST)
CS 261 – Fall 2009 Binary Search Trees. Can we do something useful? How can we make a collection using the idea of a binary tree? How about starting with.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
Binary Tree Implementation. Binary Search Trees (BST) Nodes in Left subtree has smaller values Nodes in right subtree has bigger values.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Symbol tables.
CMSC 202, Version 5/02 1 Trees. CMSC 202, Version 5/02 2 Tree Basics 1.A tree is a set of nodes. 2.A tree may be empty (i.e., contain no nodes). 3.If.
1 Data Structures CSCI 132, Spring 2014 Lecture23 Analyzing Search Algorithms.
CS261 Data Structures Binary Search Trees Concepts.
(c) University of Washington20c-1 CSC 143 Binary Search Trees.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary Trees.
CSC317 1 Binary Search Trees (binary because branches either to left or to right) Operations: search min max predecessor successor. Costs? Time O(h) with.
Instructor: Lilian de Greef Quarter: Summer 2017
Recursive Objects (Part 4)
BST Trees
Week 6 - Wednesday CS221.
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
COMP 103 Binary Search Trees.
Chapter 20: Binary Trees.
Binary Search Trees.
Chapter 21: Binary Trees.
Binary Search Tree AVL Tree
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Binary Trees.
Binary Search Trees Chapter 9 2/22/2019 B.Ramamurthy.
CMSC 341 Splay Trees.
Binary Trees, Binary Search Trees
Building Java Programs
CSC 143 Binary Search Trees.
Chapter 20: Binary Trees.
Augmenting Data Structures: Interval Trees
CMSC 341 Splay Trees.
CS 261 – Data Structures Binary Search Trees.
Binary Trees, Binary Search Trees
Data Structures Using C++ 2E
Presentation transcript:

Playground Design Karl Lieberherr

Playground A collection of algorithms to define – what is wanted from a solve algorithm S in a particular domain (inputs/outputs) – how S is evaluated (quality) – what kind of claims can be made about S (expression with quantifiers) A playground defines the WHAT is desired about S and the avatars define the HOW S is implemented.

HSR Playground, valid When is a solution valid? Requirements for a valid solution (Dennis): - Strictly binary tree (2-tree) - Tree is ordered: < to the left, ≥ to the right - Exactly n leaf nodes in [0,n-1] with no repeats - Exactly n-1 question nodes in [1,n-1] with no repeats - No more than k subsequent left branches

valid Requirements for valid (Karl) A decision tree for HSR(n,k) is valid if (1) the tree is a binary search tree with inner nodes 1..n-1 exactly once and leaves 0..n-1 exactly once (left nodes are = root, for all subtrees). (2) all paths from the root to a leaf have at most k left branches.

Binary Search Trees = Ordered Binary Trees From: ml A "binary search tree" (BST) or "ordered binary tree" is a type of binary tree where the nodes are arranged in order: for each node, all elements in its left subtree are less-or-equal to the node ( ). We becomes >=.

Examples 5 -> TRUE / \ > FALSE / \ 2 7 / \ 1 6

Efficient 14. isBST() -- version 2 Version 1 above runs slowly since it traverses over some parts of the tree many times. A better solution looks at each node only once. The trick is to write a utility helper function isBSTRecur(struct node* node, int min, int max) that traverses down the tree keeping track of the narrowing min and max allowed values as it goes, looking at each node only once. The initial values for min and max should be INT_MIN and INT_MAX -- they narrow from there.

isBST2 /* Returns true if the given tree is a binary search tree (efficient version). */ int isBST2(struct node* node) { return(isBSTRecur(node, INT_MIN, INT_MAX)); }

isBSTUtil /* Returns true if the given tree is a BST and its values are >= min and <= max. */ int isBSTUtil(struct node* node, int min, int max) {

isBSTUtil /* Returns true if the given tree is a BST and its values are >= min and <= max. */ int isBSTUtil(struct node* node, int min, int max) { if (node==NULL) return(true); // false if this node violates the min/max constraint if (node->data data>max) return(false); // otherwise check the subtrees recursively, // tightening the min or max constraint return isBSTUtil(node->left, min, node->data) && isBSTUtil(node->right, node->data+1, max) ); }