Unit 9 Practice Test (AB27-30)
|
|
- Moses Jackson
- 6 years ago
- Views:
Transcription
1 Unit 9 Practice Test (AB27-30) Name 1. Consider the following method: public static int checktree(treenode root) return 0; int x = checktree(root.getleft()); if ( x >= 0 && checktree(root.getright()) == x) return x + 1; return 1; checktree(root) returns a non-negative value if and only if the tree rooted in root A) is not empty and the root is a leaf B) is empty or the root is a leaf or the root has two children C) has no nodes with only one child D) is empty or the root has left and right subtrees of the same depth E) is a full tree (it is balanced and every parent has two children) 2. Consider the following class. Assume any used methods of the IncomingCall objects are defined as intuitively make sense. public class CallerId private LinkedList calls; public CallerId() calls = new LinkedList(); //precondition: calls holds IncomingCall objects //postcondition: all calls that came from target are removed from the calls list public void removeall(string target) < code not shown > < other methods not shown > If removeall works as specified in the pre- and postconditions, which of the following code segments can serve as removeall s body? I. for (int i = 0; i < calls.size(); i++) if (((IncomingCall)calls.get(i)).getSource().equals(target)) calls.remove(i);
2 II. int i = 0; while (i < calls.size()) if (((IncomingCall)calls.get(i)).getSource().equals(target)) calls.remove(i); i++; III. Iterator iter = calls.iterator(); while (iter.hasnext()) if (((IncomingCall)iter.next()).getSource().equals(target)) iter.remove(); A) I only B) II only C) I and II D) II and III E) I, II, and III 3. Suppose ListNode head refers to the first node of a linked list. Consider the following code fragment: ListNode node, temp; for (node = head; node!= null; node = node.getnext()) while (node.getnext()!= null && node.getnext().getvalue().equals(node.getvalue())) node.setnext((node.getnext().getnext())); If head refers to a linked list with 11 nodes that hold the letters M, I, S, S, I, S, S, I, P, P, I (in that order), what letters are stored in the nodes of this list after the above code is executed? A) M B) M, I, S C) M, I, I, I, I D) M, I, S, P E) M, I, S, I, S, I, P, I
3 4. Consider the following method: public int mysterycount(treenode root) int count = 0; if (root!= null) count = mysterycount(root.getleft()) + mysterycount(root.getright()); if ((root.getleft() == null && root.getright() == null) (root.getleft()!= null && root.getright()!= null && root.getleft().getvalue().equals( root.getright().getvalue()))) count++; return count; If root refers to the tree which value is returned by mystercount(root)? A) 1 B) 3 C) 4 D) 5 E) 10 A / \ / \ B C / \ / \ D D C C / \ / \ E E E E 5. a) Write a boolean method isvalidautree as started below. The method returns true if and only if the tree is empty or if it is a valid expression tree: that is, the children of each node match the number of inputs for the AU stored in that node. //precondition: root is null or refers to the root of a binary // tree that hods AU objects as values in its nodes. //postcondition: returns true if root is null or if root refers to // a valid AU tree; otherwise returns false; in a // valid AU tree the number of children of each node // matches the number of inputs of the AU stored in // that node; a node with a one-input AU has only a // left child. Solution 1 public static boolean isvalidautree(treenode root) if((root.getvalue().numinputs()==0)&& (root.getleft()==null)&&
4 (root.getright()==null))) if ((root.getvalue().numinputs()==1)&& (root.getleft().isvalidautree())&& (root.getright()==null))) if ((root.getvalue().numinputs()==2)&& (root.getleft().isvalidautree())&& (root.getright().isvalidautree())) return false; Solution 2 public static boolean isvalidautree(treenode root) int numchildren; TreeNode left = root.getleft(); TreeNode right = root.getright(); if (left == null && right!= null) return false; if (left!= null && right!= null) numchildren = 2; if (left!= null && right == null) numchildren = 1; numchildren = 0; return numchildren == (root.getvalue().numinputs() && isvalidautree(left) && isvalidautree(right)) b) To evaluate an AU tree, we need to evaluate the left and right subtrees of the root, if present, then use the results as the inputs for the AU in the root. Write the method evaluate as started below. //precondition: root!= null; // isvalidautree(root) == true //postcondition: returns the value computed from the expression // tree root; the register field of the AU in each // node is set to the result of evaluating that // node s subtree public static int evaluate(treenode root)
5 TreeNode left = root.getleft(); TreeNode right = root.getright(); int x = 0, y = 0; if (left!= null) x = evaluate(left); if (right!= null) y = evaluate(right); return ((AU)root.getValue()).compute(x, y); 6. Review all vocabulary words from AB28-30.
Chapter 20: Binary Trees
Chapter 20: Binary Trees 20.1 Definition and Application of Binary Trees Definition and Application of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two other
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 11: Binary Search Trees MOUNA KACEM mouna@cs.wisc.edu Fall 2018 General Overview of Data Structures 2 Introduction to trees 3 Tree: Important non-linear data structure
More informationa graph is a data structure made up of nodes in graph theory the links are normally called edges
1 Trees Graphs a graph is a data structure made up of nodes each node stores data each node has links to zero or more nodes in graph theory the links are normally called edges graphs occur frequently in
More informationCSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.
Name: Class: Date: CSCI-401 Examlet #5 True/False Indicate whether the sentence or statement is true or false. 1. The root node of the standard binary tree can be drawn anywhere in the tree diagram. 2.
More informationSTUDENT LESSON AB30 Binary Search Trees
STUDENT LESSON AB30 Binary Search Trees Java Curriculum for AP Computer Science, Student Lesson AB30 1 STUDENT LESSON AB30 Binary Search Trees INTRODUCTION: A binary tree is a different kind of data structure
More informationTREES Lecture 12 CS2110 Fall 2016
TREES Lecture 12 CS2110 Fall 2016 Prelim 1 tonight! 2 5:30 prelim is very crowded. You HAVE to follow these directions: 1. Students taking the normal 5:30 prelim (not the quiet room) and whose last names
More informationJava 1996 AP Computer Science Question 3
Java 1996 AP Computer Science Question 3 http://www.cs.duke.edu/csed/ap/exams/1996/ab3.html 1 of 2 7/8/2003 5:07 PM Java 1996 AP Computer Science Question 3 Assume that binary trees are implemented using
More informationCS211, LECTURE 20 SEARCH TREES ANNOUNCEMENTS:
CS211, LECTURE 20 SEARCH TREES ANNOUNCEMENTS: OVERVIEW: motivation naive tree search sorting for trees and binary trees new tree classes search insert delete 1. Motivation 1.1 Search Structure continuing
More informationOutline. An Application: A Binary Search Tree. 1 Chapter 7: Trees. favicon. CSI33 Data Structures
Outline Chapter 7: Trees 1 Chapter 7: Trees Approaching BST Making a decision We discussed the trade-offs between linked and array-based implementations of sequences (back in Section 4.7). Linked lists
More informationTREES. Tree Overview 9/28/16. Prelim 1 tonight! Important Announcements. Tree terminology. Binary trees were in A1!
//16 Prelim 1 tonight! :3 prelim is very crowded. You HAVE to follow these directions: 1. Students taking the normal :3 prelim (not the quiet room) and whose last names begin with A through Da MUST go
More informationTree traversals and binary trees
Tree traversals and binary trees Comp Sci 1575 Data Structures Valgrind Execute valgrind followed by any flags you might want, and then your typical way to launch at the command line in Linux. Assuming
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Binary search tree (part I) Version of March 24, 2013 Abstract These lecture notes are meant
More informationChapter Contents. Trees. Tree Concepts. Hierarchical Organization. Hierarchical Organization. Hierarchical Organization.
Chapter Contents Chapter 18 Tree Concepts Hierarchical Organizations Tree Terminology Traversals of a Tree Traversals of a Binary Tree Traversals of a General Tree Java Interfaces for Interfaces for All
More informationAdvanced Java Concepts Unit 5: Trees. Notes and Exercises
Advanced Java Concepts Unit 5: Trees. Notes and Exercises A Tree is a data structure like the figure shown below. We don t usually care about unordered trees but that s where we ll start. Later we will
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Binary search tree (part I) Version of March 24, 2013 Abstract These lecture notes are meant
More informationTREES Lecture 12 CS2110 Spring 2018
TREES Lecture 12 CS2110 Spring 2018 Important Announcements 2 A4 is out now and due two weeks from today. Have fun, and start early! Data Structures 3 There are different ways of storing data, called data
More informationData Structures in Java
Data Structures in Java Lecture 9: Binary Search Trees. 10/7/015 Daniel Bauer 1 Contents 1. Binary Search Trees. Implementing Maps with BSTs Map ADT A map is collection of (key, value) pairs. Keys are
More informationCS200: Balanced Search Trees
Value Oriented Data Structures CS200: Balanced Search Trees Walls & Mirrors Chapters 12,13 Homework 4 extension Next week: Programming quiz during recit Midterm 2 April 8 th (in class) New partners and
More informationModule 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.
The Lecture Contains: Index structure Binary search tree (BST) B-tree B+-tree Order file:///c /Documents%20and%20Settings/iitkrana1/My%20Documents/Google%20Talk%20Received%20Files/ist_data/lecture13/13_1.htm[6/14/2012
More informationBinary Trees. Examples:
Binary Trees A tree is a data structure that is made of nodes and pointers, much like a linked list. The difference between them lies in how they are organized: In a linked list each node is connected
More informationTREES Lecture 10 CS2110 Spring2014
TREES Lecture 10 CS2110 Spring2014 Readings and Homework 2 Textbook, Chapter 23, 24 Homework: A thought problem (draw pictures!) Suppose you use trees to represent student schedules. For each student there
More information! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge
Trees & Heaps Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Fall 2018 Jill Seaman!1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every
More informationMulti-way Search Trees. (Multi-way Search Trees) Data Structures and Programming Spring / 25
Multi-way Search Trees (Multi-way Search Trees) Data Structures and Programming Spring 2017 1 / 25 Multi-way Search Trees Each internal node of a multi-way search tree T: has at least two children contains
More informationINF2220: algorithms and data structures Series 1
Universitetet i Oslo Institutt for Informatikk A. Maus, R.K. Runde, I. Yu INF2220: algorithms and data structures Series 1 Topic Trees & estimation of running time (Exercises with hints for solution) Issued:
More informationCS24 Week 8 Lecture 1
CS24 Week 8 Lecture 1 Kyle Dewey Overview Tree terminology Tree traversals Implementation (if time) Terminology Node The most basic component of a tree - the squares Edge The connections between nodes
More informationAP Computer Science AB 2007 Free-Response Questions
AP Computer Science AB 007 Free-Response Questions The College Board: Connecting Students to College Success The College Board is a not-for-profit membership association whose mission is to connect students
More informationLargest Online Community of VU Students
WWW.VUPages.com http://forum.vupages.com WWW.VUTUBE.EDU.PK Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions
More informationAlgorithms and complexity: 2 The dictionary problem: search trees
Algorithms and complexity: 2 The dictionary problem: search trees The dictionary problem Given: a set of objects (data) where each element can be identified by a unique key (integer, string,... ). Goal:
More informationThe Problem with Linked Lists. Topic 18. Attendance Question 1. Binary Search Trees. -Monty Python and The Holy Grail
Topic 18 Binary Search Trees "Yes. Shrubberies are my trade. I am a shrubber. My name is 'Roger the Shrubber'. I arrange, design, and sell shrubberies." -Monty Python and The Holy Grail The Problem with
More informationName Section Number. CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice
Name Section Number CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice All Sections Bob Wilson OPEN BOOK / OPEN NOTES: You will have all 90 minutes until the start of the next class period.
More informationData Structure. Chapter 5 Trees (Part II) Angela Chih-Wei Tang. National Central University Jhongli, Taiwan
Data Structure Chapter 5 Trees (Part II) Angela Chih-Wei Tang Department of Communication Engineering National Central University Jhongli, Taiwan 2010 Spring Threaded Binary Tree Problem: There are more
More informationCSI33 Data Structures
Outline Department of Mathematics and Computer Science Bronx Community College November 13, 2017 Outline Outline 1 C++ Supplement.1: Trees Outline C++ Supplement.1: Trees 1 C++ Supplement.1: Trees Uses
More informationBinary Tree. Binary tree terminology. Binary tree terminology Definition and Applications of Binary Trees
Binary Tree (Chapter 0. Starting Out with C++: From Control structures through Objects, Tony Gaddis) Le Thanh Huong School of Information and Communication Technology Hanoi University of Technology 11.1
More informationCSI33 Data Structures
Outline Department of Mathematics and Computer Science Bronx Community College November 21, 2018 Outline Outline 1 C++ Supplement 1.3: Balanced Binary Search Trees Balanced Binary Search Trees Outline
More informationData Structures and Algorithms
Data Structures and Algorithms CS245-2017S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list
More informationBRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE
BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE CSI Section E01 AVL Trees AVL Property While BST structures have average performance of Θ(log(n))
More information- 1 - Handout #22S May 24, 2013 Practice Second Midterm Exam Solutions. CS106B Spring 2013
CS106B Spring 2013 Handout #22S May 24, 2013 Practice Second Midterm Exam Solutions Based on handouts by Eric Roberts and Jerry Cain Problem One: Reversing a Queue One way to reverse the queue is to keep
More informationData Structures and Algorithms
Data Structures and Algorithms CS245-2008S-19 B-Trees David Galles Department of Computer Science University of San Francisco 19-0: Indexing Operations: Add an element Remove an element Find an element,
More informationRecursion, Binary Trees, and Heaps February 18
Recursion, Binary Trees, and Heaps February 18 19 20 Recursion Review BST: Begin Slides Early Dismissal Problems on board BST Problems 23 24 25 26 27 Binary Tree problems QUIZ: Drawing trees and Traversals
More information! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge
Trees (& Heaps) Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Spring 2015 Jill Seaman 1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root -
More informationAlgorithms. AVL Tree
Algorithms AVL Tree Balanced binary tree The disadvantage of a binary search tree is that its height can be as large as N-1 This means that the time needed to perform insertion and deletion and many other
More informationCOSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)
COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back
More informationBinary Search Trees. Contents. Steven J. Zeil. July 11, Definition: Binary Search Trees The Binary Search Tree ADT...
Steven J. Zeil July 11, 2013 Contents 1 Definition: Binary Search Trees 2 1.1 The Binary Search Tree ADT.................................................... 3 2 Implementing Binary Search Trees 7 2.1 Searching
More informationBuilding Java Programs
Building Java Programs Binary Trees reading: 17.1 17.3 2 Trees in computer science TreeMap and TreeSet implementations folders/files on a computer family genealogy; organizational charts AI: decision trees
More informationPriority Queues and Huffman Trees
Priority Queues and Huffman Trees 1 the Heap storing the heap with a vector deleting from the heap 2 Binary Search Trees sorting integer numbers deleting from a binary search tree 3 Huffman Trees encoding
More informationThe code XXX1XXX, XXX2XXX, XXX3XXX represents pieces of code that are missing from the method that are needed to make it work properly.
1) ITERATION (FOR) public void createtriangle(int n) for ( XXX1XXX ) for ( XXX2XXX ) System.out.print( XXX3XXX ); System.out.print("\n"); The code XXX1XXX, XXX2XXX, XXX3XXX represents pieces of code that
More informationECE 242 Data Structures and Algorithms. Trees IV. Lecture 21. Prof.
ECE 22 Data Structures and Algorithms http://www.ecs.umass.edu/~polizzi/teaching/ece22/ Trees IV Lecture 2 Prof. Eric Polizzi Summary previous lectures Implementations BST 5 5 7 null 8 null null 7 null
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 12: Heaps and Priority Queues MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Heaps and Priority Queues 2 Priority Queues Heaps Priority Queue 3 QueueADT Objects are added and
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 10 / 10 / 2016 Instructor: Michael Eckmann Today s Topics Questions? Comments? A few comments about Doubly Linked Lists w/ dummy head/tail Trees Binary trees
More informationFriday Four Square! 4:15PM, Outside Gates
Binary Search Trees Friday Four Square! 4:15PM, Outside Gates Implementing Set On Monday and Wednesday, we saw how to implement the Map and Lexicon, respectively. Let's now turn our attention to the Set.
More informationECE 244 Programming Fundamentals Fall Lab Assignment #5: Binary Search Trees
ECE 244 Programming Fundamentals Fall 2012 1. Objectives Lab Assignment #5: Binary Search Trees The objectives of this assignment are to provide you with more practice on the use of the various C++ concepts/constructs
More informationTree Travsersals and BST Iterators
Tree Travsersals and BST Iterators PIC 10B May 25, 2016 PIC 10B Tree Travsersals and BST Iterators May 25, 2016 1 / 17 Overview of Lecture 1 Sorting a BST 2 In-Order Travsersal 3 Pre-Order Traversal 4
More informationExam Informatik D-MATH/D-PHYS :00 11:00
Exam Informatik D-MATH/D-PHYS 25. 1. 2013 09:00 11:00 Dr. Bernd Gartner Examinee: Last name:... First name:... Stud. no.:... With my signature I attest, that I was able to sit the exam under regular conditions
More informationINF2220: algorithms and data structures Series 1
Universitetet i Oslo Institutt for Informatikk I. Yu, D. Karabeg INF2220: algorithms and data structures Series 1 Topic Function growth & estimation of running time, trees Issued: 24. 08. 2016 Exercise
More informationBinary Search Trees. Chapter 21. Binary Search Trees
Chapter 21 Binary Search Trees Binary Search Trees A Binary Search Tree is a binary tree with an ordering property that allows O(log n) retrieval, insertion, and removal of individual elements. Defined
More informationTrees! Ellen Walker! CPSC 201 Data Structures! Hiram College!
Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College! ADTʼs Weʼve Studied! Position-oriented ADT! List! Stack! Queue! Value-oriented ADT! Sorted list! All of these are linear! One previous item;
More information1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking
Review for Test 2 (Chapter 6-10) Chapter 6: Template functions & classes 1) What is the primary purpose of template functions? A. To allow a single function to be used with varying types of arguments B.
More informationIntroduction to Computer Science II CS S-18 Linked Lists
Introduction to Computer Science II CS112-2012S-18 Linked Lists David Galles Department of Computer Science University of San Francisco 18-0: Linked Lists Linked List node Data Pointer to the next element
More informationData and File Structures Laboratory
Binary Trees Assistant Professor Machine Intelligence Unit Indian Statistical Institute, Kolkata September, 2018 1 Basics 2 Implementation 3 Traversal Basics of a tree A tree is recursively defined as
More informationCOMP 103 Introduction to Data Structures and Algorithms
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:..................... EXAMINATIONS 2005 END-YEAR COMP 103 Introduction to Data
More informationCMPSCI 187: Programming With Data Structures. Lecture #28: Binary Search Trees 21 November 2011
CMPSCI 187: Programming With Data Structures Lecture #28: Binary Search Trees 21 November 2011 Binary Search Trees The Idea of a Binary Search Tree The BinarySearchTreeADT Interface The LinkedBinarySearchTree
More informationTree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.
Trees, Binary Search Trees, and Heaps CS 5301 Fall 2013 Jill Seaman Tree: non-recursive definition Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every node (except
More informationCS 151. Binary Trees. Friday, October 5, 12
CS 151 Binary Trees 1 Binary Tree Examples Without telling you what a binary tree is, here are some examples (that I will draw on the board): The dots/circles are called nodes, or vertices (singular: one
More informationTrees. (Trees) Data Structures and Programming Spring / 28
Trees (Trees) Data Structures and Programming Spring 2018 1 / 28 Trees A tree is a collection of nodes, which can be empty (recursive definition) If not empty, a tree consists of a distinguished node r
More informationMotivation Computer Information Systems Storage Retrieval Updates. Binary Search Trees. OrderedStructures. Binary Search Tree
Binary Search Trees CMPUT 115 - Lecture Department of Computing Science University of Alberta Revised 21-Mar-05 In this lecture we study an important data structure: Binary Search Tree (BST) Motivation
More informationCSE 214 Computer Science II Introduction to Tree
CSE 214 Computer Science II Introduction to Tree Fall 2017 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Tree Tree is a non-linear
More informationEXAMINATIONS 2005 END-YEAR. COMP 103 Introduction to Data Structures and Algorithms
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I ÎÍÏ V I C T O R I A UNIVERSITY OF WELLINGTON EXAMINATIONS 2005 END-YEAR COMP 103 Introduction to Data Structures and Algorithms Time Allowed:
More informationCMSC 341 Lecture 15 Leftist Heaps
Based on slides from previous iterations of this course CMSC 341 Lecture 15 Leftist Heaps Prof. John Park Review of Heaps Min Binary Heap A min binary heap is a Complete binary tree Neither child is smaller
More informationCSCI-1200 Data Structures Fall 2014 Lecture 18 Trees, Part III
Review from Lecture 17 CSCI-1200 Data Structures Fall 2014 Lecture 18 Trees, Part III Overview of the ds set implementation begin, find, destroy_tree, insert In-order, pre-order, and post-order traversal;
More informationTitle Description Participants Textbook
Podcast Ch18c Title: BST delete operation Description: Deleting a leaf; deleting a node with one nonnull child; deleting a node with two nonnull children Participants: Barry Kurtz (instructor); John Helfert
More informationCSCI-1200 Data Structures Fall 2018 Lecture 19 Trees, Part III
CSCI-1200 Data Structures Fall 2018 Lecture 19 Trees, Part III Review from Lecture 17 & 18 Overview of the ds set implementation begin, find, destroy_tree, insert In-order, pre-order, and post-order traversal;
More informationCSCI-1200 Data Structures Spring 2015 Lecture 20 Trees, Part III
CSCI-1200 Data Structures Spring 2015 Lecture 20 Trees, Part III Review from Lecture 18 & 19 Overview of the ds set implementation begin, find, destroy_tree, insert In-order, pre-order, and post-order
More informationBinary Trees: Practice Problems
Binary Trees: Practice Problems College of Computing & Information Technology King Abdulaziz University CPCS-204 Data Structures I Warmup Problem 1: Searching for a node public boolean recursivesearch(int
More informationDiscussion 2C Notes (Week 8, February 25) TA: Brian Choi Section Webpage:
Discussion 2C Notes (Week 8, February 25) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs32 Trees Definitions Yet another data structure -- trees. Just like a linked
More informationCSCI212 Computer Science. Binary Trees/Heaps/Binary Search Trees
CSCI212 Computer Science Binary Trees/Heaps/Binary Search Trees Tree Terminology 0 A tree is a non-linear abstract data type that stores elements hierarchically. 0 With the exception of the top element
More informationReferences and Homework ABSTRACT DATA TYPES; LISTS & TREES. Abstract Data Type (ADT) 9/24/14. ADT example: Set (bunch of different values)
9// References and Homework Text: Chapters, and ABSTRACT DATA TYPES; LISTS & TREES Homework: Learn these List methods, from http://docs.oracle.com/javase/7/docs/api/java/util/list.html add, addall, contains,
More informationSome Search Structures. Balanced Search Trees. Binary Search Trees. A Binary Search Tree. Review Binary Search Trees
Some Search Structures Balanced Search Trees Lecture 8 CS Fall Sorted Arrays Advantages Search in O(log n) time (binary search) Disadvantages Need to know size in advance Insertion, deletion O(n) need
More informationCS 231 Data Structures and Algorithms Fall Binary Search Trees Lecture 23 October 29, Prof. Zadia Codabux
CS 231 Data Structures and Algorithms Fall 2018 Binary Search Trees Lecture 23 October 29, 2018 Prof. Zadia Codabux 1 Agenda Ternary Operator Binary Search Tree Node based implementation Complexity 2 Administrative
More informationData Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University
Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University U Kang (2016) 1 In This Lecture The concept of binary tree, its terms, and its operations Full binary tree theorem Idea
More informationCMSC 341 Lecture 15 Leftist Heaps
Based on slides from previous iterations of this course CMSC 341 Lecture 15 Leftist Heaps Prof. John Park Review of Heaps Min Binary Heap A min binary heap is a Complete binary tree Neither child is smaller
More informationSCJ2013 Data Structure & Algorithms. Binary Search Tree. Nor Bahiah Hj Ahmad
SCJ2013 Data Structure & Algorithms Binary Search Tree Nor Bahiah Hj Ahmad Binary Search Tree A binary search tree has the following properties: For every node n in the tree Value of n is greater than
More informationChapter 4: Trees. 4.2 For node B :
Chapter : Trees. (a) A. (b) G, H, I, L, M, and K.. For node B : (a) A. (b) D and E. (c) C. (d). (e).... There are N nodes. Each node has two pointers, so there are N pointers. Each node but the root has
More informationTrees: examples (Family trees)
Ch 4: Trees it s a jungle out there... I think that I will never see a linked list useful as a tree; Linked lists are used by everybody, but it takes real smarts to do a tree Trees: examples (Family trees)
More informationGeneric BST Interface
Generic BST Interface Here s a partial generic BST interface: public class BST
More informationRecitation 9. Prelim Review
Recitation 9 Prelim Review 1 Heaps 2 Review: Binary heap min heap 1 2 99 4 3 PriorityQueue Maintains max or min of collection (no duplicates) Follows heap order invariant at every level Always balanced!
More informationCSCI-1200 Data Structures Spring 2018 Lecture 18 Trees, Part III
CSCI-1200 Data Structures Spring 2018 Lecture 18 Trees, Part III Review from Lecture 16 & 17 Overview of the ds set implementation begin, find, destroy_tree, insert In-order, pre-order, and post-order
More informationWe have the pointers reference the next node in an inorder traversal; called threads
Leaning Objective: In this Module you will be learning the following: Threaded Binary Tree Introduction: Threaded Binary Tree is also a binary tree in which all left child pointers that are NULL (in Linked
More informationCS350: Data Structures Red-Black Trees
Red-Black Trees James Moscola Department of Engineering & Computer Science York College of Pennsylvania James Moscola Red-Black Tree An alternative to AVL trees Insertion can be done in a bottom-up or
More informationAlgorithms. Deleting from Red-Black Trees B-Trees
Algorithms Deleting from Red-Black Trees B-Trees Recall the rules for BST deletion 1. If vertex to be deleted is a leaf, just delete it. 2. If vertex to be deleted has just one child, replace it with that
More informationCS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux
CS 231 Data Structures and Algorithms Fall 2018 Recursion and Binary Trees Lecture 21 October 24, 2018 Prof. Zadia Codabux 1 Agenda ArrayQueue.java Recursion Binary Tree Terminologies Traversal 2 Administrative
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 10: Search and Heaps MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Search and Heaps 2 Linear Search Binary Search Introduction to trees Priority Queues Heaps Linear Search
More informationTree Structures. A hierarchical data structure whose point of entry is the root node
Binary Trees 1 Tree Structures A tree is A hierarchical data structure whose point of entry is the root node This structure can be partitioned into disjoint subsets These subsets are themselves trees and
More informationexamines every node of a list until a matching node is found, or until all nodes have been examined and no match is found.
A examines every node of a list until a matching node is found, or until all nodes have been examined and no match is found. For very long lists that are frequently searched, this can take a large amount
More informationCS61B Fall 2015 Guerrilla Section 3 Worksheet. 8 November 2015
Fall 2015 8 November 2015 Directions: In groups of 4-5, work on the following exercises. Do not proceed to the next exercise until everyone in your group has the answer and understands why the answer is
More informationSelf-Balancing Search Trees. Chapter 11
Self-Balancing Search Trees Chapter 11 Chapter Objectives To understand the impact that balance has on the performance of binary search trees To learn about the AVL tree for storing and maintaining a binary
More informationFall, 2015 Prof. Jungkeun Park
Data Structures and Algorithms Binary Search Trees Fall, 2015 Prof. Jungkeun Park Copyright Notice: This material is modified version of the lecture slides by Prof. Rada Mihalcea in Univ. of North Texas.
More informationConsider the search operation FindKey (): find an element of a particular key value in a binary tree. This operation takes O(n) time in a binary
1 Consider the search operation FindKey (): find an element of a particular key value in a binary tree. This operation takes O(n) time in a binary tree. In a binary tree of 10 6 nodes 10 6 steps required
More informationCmpSci 187: Programming with Data Structures Spring 2015
CmpSci 187: Programming with Data Structures Spring 2015 Lecture #17, Implementing Binary Search Trees John Ridgway April 2, 2015 1 Implementing Binary Search Trees Review: The BST Interface Binary search
More informationWhy Trees? Alternatives. Want: Ordered arrays. Linked lists. A data structure that has quick insertion/deletion, as well as fast search
Why Trees? Alternatives Ordered arrays Fast searching (binary search) Slow insertion (must shift) Linked lists Want: Fast insertion Slow searching (must start from head of list) A data structure that has
More informationAdvanced Java Concepts Unit 5: Trees. Notes and Exercises
dvanced Java Concepts Unit 5: Trees. Notes and Exercises Tree is a data structure like the figure shown below. We don t usually care about unordered trees but that s where we ll start. Later we will focus
More information