More Trees 5/9/2-017 Be able to dry run a program that uses trees

Slides:



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

Stacks, Queues, and Linked Lists
Algorithm Analysis.
Data Structures and Algorithms1 B-Trees with Minimum=1 2-3 Trees.
Binary Trees Terminology A graph G = is a collection of nodes and edges. An edge (v 1,v 2 ) is a pair of vertices that are directly connected. A path,
1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in.
CSCE 3110 Data Structures & Algorithm Analysis Binary Search Trees Reading: Chap. 4 (4.3) Weiss.
Trees, Binary Search Trees, Recursion, Project 2 Bryce Boe 2013/08/01 CS24, Summer 2013 C.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Implementing Red Black Trees Ellen Walker CPSC 201 Data Structures Hiram College.
Chapter 4 Stacks Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving. Its called.
Lists ADT (brief intro):  Abstract Data Type  A DESCRIPTION of a data type  The data type can be anything: lists, sets, trees, stacks, etc.  What.
Reynolds 2006 Complexity1 Complexity Analysis Algorithm: –A sequence of computations that operates on some set of inputs and produces a result in a finite.
Chapter 7 Code Tables. VB Code Box 7-1 Event Procedure for Compute Button Private Sub hsbExemptions_Change() txtExemptions.Text =Str(hsbExemptions.Value)
data ordered along paths from root to leaf
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Recursion COMP 103 #
Sorting & Searching Review. Selection Sort 1. Find the smallest element 2. Move to the front of the array (swap with front) 3. Repeat Steps 1&2, but ignoring.
Pascal Programming Pointers and Dynamic Variables.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
1 Binary Trees and Binary Search Trees Based on Dale & Co: Object-Oriented Data Structures using C++ (graphics)
Binary Search Trees (BST)
Fundamentals of Algorithms MCS - 2 Lecture # 17. Binary Search Trees.
Stacks Queues Introduction to Trees. Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that.
Computer Science 2 Arrays of Records. First Record Program Input an unknown number of Team Names, School names, and Total scores. (While loop) –Output:
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
Pseudo-code 1 Running time of algorithm is O(n)
Stacks and Queues Chapter 4.
Binary Trees and Binary Search Trees
Analysis of Algorithms
COMP 103 Binary Search Trees.
Design and Analysis of Algorithms
Data Structures and Algorithms
- Alan Perlis Heaps "You think you know when you can learn,
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Example Programs.
Program options Write a program for one of the following
Computer Science Dynamics.
Computer Science 2 Hashing
Node Removal From BST Source:
Lesson Objectives Aims
Computer Science 2 Outline/Learning Objectives for the day:
CIS16 Application Development and Programming using Visual Basic.net
searching Concept: Linear search Binary search
Computer Science 2 Arrays of Records.
Computer Science 2 Arrays of Records.
Binary Search Trees (13.1/12.1)
Search,Sort,Recursion.
Computer Science Dynamics.
Computer Science Sorting.
Computer Science 2: Trees
Computer Science 2 Arrays of Records.
Binary Search Trees Chapter 9 2/22/2019 B.Ramamurthy.
Computer Science 2 Hashing.
Binary Search Trees Chapter 9 2/24/2019 B.Ramamurthy.
Robotics Programming Using Shaft Encoders
Deleting from a binary tree
Robotics Programming Using Shaft Encoders
Search,Sort,Recursion.
Computer Science 2 More Trees.
Deleting from a binary tree
Binary Search Counting
Computer Science I: Get out your notes.
Computer Science 2 Queue.
Time to finish first stack program
Computer Science 2 Queue Day 2.
Program options Write a program for one of the following
Program: Mini Phone Book 2/11/2016
Shadows CSE 681.
Computer Science
Presentation transcript:

More Trees 5/9/2-017 Be able to dry run a program that uses trees Finding someone in the tree.

Show the trees after adding the following 20, 10, 30, 15, 20, 5, 100 30, 8, 40, 20, 30, 15

Show the tree, and the screen procedure three(top:ptrtype); begin writeln(top^.num); if top^.left <> nil then three(top^.left); if top^.right <> nil then three(top^.right); end; procedure four(top:ptrtype); four(top^.left); four(top^.right); top:=nil; for count:= 1 to 5 do new(temp); readln(temp^.num); temp^.left:=nil; temp^.right:=nil; one(top, temp); two(top); three(top); four(top); end. Use the following values for input, in this order: 30, 10, 50, 15, 3. procedure one(var top, temp:ptrtype); begin if top=nil then top:=temp else if top^.num<temp^.num then one(top^.right, temp) else one(top^.left, temp); end; procedure two(top:ptrtype); if top^.left <> nil then two(top^.left); if top^.right <> nil then two(top^.right); writeln(top^.num);

Tree 1 Menu Push: Show all (High to low using the same tree) Add a name Show All (In order: Low to high) Push: Show all (High to low using the same tree) Push: Add a procedure to check is someone is in the tree. (If they are in the tree it says they are, if they are not, it says that are not.) Push: Make this a boolean function that returns true if they are in the tree and false if they are not. Push: Delete someone from the tree. Push: On the Show from a tree, have it show the information like a tree.

Finding someone in a Binary Search Tree How would you find the 800 in the tree? Starting at the root (top). What possible conditions are there when going through the tree?

Finding an item on a tree Pseudo Code for Finding an item Cases Nil: Not in the tree Name matches: Found Name is less than top’s name, look left Else Look Right

Translating to code Procedure FindValue(top: ptrtype: nam:string); Begin If top = nil then Writeln(nam, ‘ is not in the list’); End else if top^.name = nam then Writeln(Nam, ‘ has been found.’); End else if name < top^.name then FindValue(top^.left, nam) Else FindValue(top^.right, nam); End.

Tree 2 Menu (while loop) Add name and phone Show all names and phone numbers Find: Given a name, show the name and number Push: Delete someone from the list Push: Change someone’s information. Phone, name