DM550 Introduction to Programming part 2. Jan Baumbach.

Size: px
Start display at page:

Download "DM550 Introduction to Programming part 2. Jan Baumbach."

Transcription

1 DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk

2 BINARY SORTING TREES 2

3 Binary Sort Tree special binary tree invariant for all subtrees: all elements smaller than root in left subtree all elements bigger than root in right subtree elements need to be comparable D interface Comparable B I use method compareto A C E our example tree is a sort tree nodes are of class Character G F H 3

4 SortTree ADT: Specification data are objects of some class E that extends Comparable operations are defined by the following interface public interface SortTree<E extends Comparable<E>> { public int size(); // number of elements public boolean contains(e elem); // true, if elem in tree public void add(e elem); // add elem to tree public void remove(e elem); // tremove elem from tree public List<E> traverse(); // in-order traversal public void balance(); // balance the tree } 4

5 SortTree ADT: Design & Implement. Design: use recursive data structure reuse class BinTreeNode<E> Implementation 1: public class BinSortTree<E extends Comparable<E>> implements SortTree<E> { private BinTreeNode<E> root = null; public int size() { return size(this.root); } private static <E extends Comparable<E>> int size(bintreenode<e> node) { if (node == null) { return 0; } return 1 + size(node.left) + size(node.right); } 5

6 SortTree ADT: Implementation Implementation 1 (continued): contains('g') D public boolean contains(e elem) { B I return contains(this.root, elem); } A C E private static <E extends Comparable<E>> boolean contains(bintreenode<e> node, E elem) { G if (node == null) { return false; } F switch (signum(elem.compareto(node.elem))) { case -1: return contains(node.left, elem); case 0: return true; case 1: return contains(node.right, elem); } throw new RuntimeException("compareTo error"); } H 6

7 SortTree ADT: Implementation Implementation 1 (continued): public void add(e elem) { this.root = add(this.root, elem); } private static int signum(int x) { return x == 0? 0 : (x > 0? 1 : -1); } private static <E extends Comparable<E>> BinTreeNode<E> add(bintreenode<e> node, E elem) { if (node == null) { return new BinTreeNode<E>(elem, null, null); } switch (signum(elem.compareto(node.elem))) { 7

8 SortTree ADT: Implementation Implementation 1 (continued): add('f') D case -1: node.left = add(node.left, elem); B I return node; A C E case 0: return node; case 1: G node.right = add(node.right, elem); return node; F H } throw new RuntimeException("compareTo error"); } 8

9 Binary Sort Tree: Removal first, find the node (as contains or add) four cases for node to be removed DC 1. no children delete('h') B I 2. only a left child 3. only a right child delete('g') A C EF 4. both left and right child easy to handle 1-3: 1. delete node delete('e') delete('d') F GF H 2. replace node by left child 3. replace node by right child 4. replace node by largest element in left subtree 9

10 SortTree ADT: Implementation Implementation 1 (continued): public void remove(e elem) { this.root = remove(this.root, elem); } private static <E extends Comparable<E>> E max(bintreenode<e> node) { return node.right == null? node.elem : max(node.right); } private static <E extends Comparable<E>> BinTreeNode<E> remove(bintreenode<e> node, E elem) { if (node == null) { return null; } switch (signum(elem.compareto(node.elem))) { 10

11 SortTree ADT: Implementation Implementation 1 (continued): case -1: return new BinTreeNode<E>(node.elem, remove(node.left, elem), node.right); case 0: if (node.left == null) { return node.right; } if (node.right == null) { return node.left; } E max = max(node.left); return new BinTreeNode<E>(max, remove(node.left, max), node.right); case 1: return new BinTreeNode<E>(node.elem, node.left, remove(node.right, elem)); } throw new RuntimeException("compareTo error"); } 11

12 SortTree ADT: Implementation Implementation 1 (continued): public java.util.list<e> traverse() { return traverse(this.root, new java.util.arraylist<e>()); } private static <E extends Comparable<E>> List<E> traverse(bintreenode<e> node, List<E> result) { if (node!= null) { traverse(node.left, result); result.add(node.elem); traverse(node.right, result); } return result; } 12

13 Sorting Tree Balancing A sorted tree is balanced iff for each node holds: Math.abs(size(node.left) - size(node.right)) <=1 Assume: size(node.right) > size(node.left)+1 i.e. more elements in the right subtree Idea: Move small elements from the right to the left subtree until balanced Recursively repeat for all nodes in the tree 13

14 Sorting Tree Balancing 1. Replace root node with smallest element in right subtree 2. Remove this smallest element from the right subtree 3. Add (former) root node to the left subtree 4. Repeat until balanced 5. Recursively repeat for subtrees to the left + right of the new root node 14

15 Sorting Tree Balancing lsize = 3 rsize = 7 D B I A C E N G M F H 15

16 Sorting Tree Balancing lsize = 3 rsize = 7 D B I A C E N Start with the root node. F G H M 16

17 Sorting Tree Balancing lsize = 3 rsize = 7 D B I A C E N rsize > lsize +1 F G H M à Find smallest element in right subgraph. 17

18 Sorting Tree Balancing lsize = 3 rsize = 7 D B I A C E N Replace root node with smallest element in right subgraph. F G H M 18

19 Sorting Tree Balancing lsize = 3 rsize = 7 E B I A C E N Replace root node with smallest element in right subgraph. F G H M 19

20 Sorting Tree Balancing lsize = 3 rsize = 7 E B I A C E N D G M Add (former) root node to the left subtree. F H 20

21 Sorting Tree Balancing lsize = 3 rsize = 7 E B I A C N D G M Remove (new) root node (= former smallest element of right subtree) from the right subtree. F H 21

22 Sorting Tree Balancing lsize = 4 rsize = 6 E B I A C N D G M Check if balanced. F H 22

23 Sorting Tree Balancing lsize = 4 rsize = 6 E B I A C N D G M No, as 6 > 4+1. F H à Start again with root node. 23

24 Sorting Tree Balancing lsize = 4 rsize = 6 E B I A C N D G M Find smallest element in right subtree. F H 24

25 Sorting Tree Balancing lsize = 4 rsize = 6 E B I A C N D G M Replace root node with this element. F H 25

26 Sorting Tree Balancing lsize = 4 rsize = 6 F B I A C N D G M Replace root node with this element. F H 26

27 Sorting Tree Balancing lsize = 4 rsize = 6 F B I A C N D G M Add (former) root to the left subtree. E F H 27

28 Sorting Tree Balancing lsize = 4 rsize = 6 F B I A C N D G M Remove (new) root from right subtree. E H 28

29 Sorting Tree Balancing lsize = 5 rsize = 5 F B I A C N D G M Check if balanced. E H 29

30 Sorting Tree Balancing lsize = 5 rsize = 5 F B I A C N D G M YES! à Repeat with left and right subtrees recursively. E H 30

31 Sorting Tree Balancing F lsize = 1 B rsize = 3 I A C N D G M Find smallest element in right subtree. E H 31

32 Sorting Tree Balancing F lsize = 1 C rsize = 3 I A D N B E G M 1. Replace root node with it. 2. Add (former) root to left subtree. 3. Remove it from the right subtree. H 32

33 Sorting Tree Balancing F lsize = 2 C rsize = 2 I A D N B E G M Balanced? H 33

34 Sorting Tree Balancing F lsize = 2 C rsize = 2 I A D N B E G M Balanced? H YES! à Check subtrees. 34

35 Sorting Tree Balancing F lsize = 2 C rsize = 2 I A D G N B E H M Continue until tree is balanced. 35

36 SortTree ADT: Implementation Implementation 1 (continued): public void balance() { this.root = balance(this.root); } private static <E extends Comparable<E>> E min(bintreenode<e> node) { return node.left == null? node.elem : min(node.left); } private static <E extends Comparable<E>> BinTreeNode<E> balance(bintreenode<e> node) { if (node == null) { return null; } int lsize = size(node.left); int rsize = size(node.right); 36

37 SortTree ADT: Implementation Implementation 1 (continued): while (lsize > rsize+1) { E max = max(node.left); lsize--; rsize++; node = new BinTreeNode<E>(max, remove(node.left, max), add(node.right, node.elem)); } while (rsize > lsize+1) { E min = min(node.right); rsize--; lsize++; node = new BinTreeNode<E>(min, add(node.left, node.elem), remove(node.right, min)); } return new BinTreeNode<E>(node.elem, balance(node.left), balance(node.right)); } } // DONE! 37

38 PROJECT 38

39 Organizational Details The project has to be passed to pass the course It has to be done individually. No co-operation! You may talk about the problem, however, and share ideas on how to solve it. Deliverables: Written 4-page report as specified in the project description Deadline: January 12, 2017, 23:59 ENOUGH - now for the ABSTRACT part 39

40 Sudoku solving Pen & paper game played on a 9 x 3 x 3 grid Goal: Distribute the numbers from 1-9 in each of the 3x3 fields such that in each 3x3-field, as well as in each 9er-row and each 9er-column every number occurs exactly once Task I: Implement ADT solving a given input game Task II: Implement a GUI 40

41 Sudoku solving 41

42 Sudoku solving 42

43 Sudoku solving X X 8 1 X X 5 X X 9 6 X X 8 X X X X X 5 X X 3 6 X 9 8 X X 7 X 6 9 X 1 2 X X 6 8 X 7 3 X X 8 1 X 4 5 X 6 X X 4 2 X 6 7 X X 8 X X X X X 4 X X 6 3 X X 5 X X 8 7 X X 43

44 Sudoku solving X X 8 1 X X 5 X X 9 6 X X 8 X X X X X 5 X X 3 6 X 9 8 X X 7 X 6 9 X 1 2 X X 6 8 X 7 3 X X 8 1 X 4 5 X 6 X X 4 2 X 6 7 X X 8 X X X X X 4 X X 6 3 X X 5 X X 8 7 X X

45 Sudoku solving Find the project description at df Task I: Implement ADT solving a given input game Task II: Implement a GUI Additional challenge: Use recursions in the solver! Hint: Use Java s SWING library when possible 45

46 THANKS! 46

47 MULTIVARIATE TREES 47

48 Multivariate Trees general class of trees nodes can have any number of children our application: k-permutations of n all sequences without repetition total of n elements sequences of length k < n Example: total of n = 3 elements sequences of length k = ,2 1,3 2,1 2,3 3,1 3,2 48

49 MTree ADT: Specification data are sequences of integers (List<Integer>) operations are defined by the following interface public interface MTreeADT extends javax.swing.tree.treemodel { public Object getroot(); public boolean isleaf(object node); public int getchildcount(object node); public Object getchild(object parent, int index); public int getindexofchild(object parent, Object child); } TreeModel specifies additional operations needed for JTree 49

50 MTree ADT: Design & Implement. Design: use recursive data structure Implementation: public class MTreeNode { private List<Integer> seq; // sequence of integers private List<MTreeNode> children = new ArrayList<MTreeNode>(); public MTreeNode(List<Integer> seq) { this.seq = seq; } public List<Integer> getseq() { return this.seq; } public List<MTreeNode> getchildren() { return this.children; } public String tostring() { return this.seq.tostring(); } } 50

51 MTree ADT: Implementation Implementation (continued): public class MTree implements MTreeADT { private MTreeNode root = new MTreeNode( new ArrayList<Integer>()); public Object getroot() { return this.root; } public boolean isleaf(object node) { return this.getchildcount(node) == 0; } public int getchildcount(object node) { return ((MTreeNode)node).getChildren().size(); } 51

52 MTree ADT: Implementation Implementation (continued) public class MTree implements MTreeADT { public Object getchild(object parent, int index) { return ((MTreeNode)parent).getChildren().get(index); } public int getindexofchild(object parent, Object child) { return ((MTreeNode)parent).getChildren().indexOf(child); } public void addtreemodellistener(treemodellistener l) {} public void removetreemodellistener(treemodellistener l) {} public void valueforpathchanged(treepath p, Object o) {} 52

53 MTree ADT: Implementation Implementation (continued) public class MTree implements MTreeADT { private static MTree maketree(string title) { MTree tree = new MTree(); JScrollPane content = new JScrollPane(new JTree(tree)); JFrame window = new JFrame(title); window.setcontentpane(content); window.setdefaultcloseoperation(jframe.exit_on_close); window.setsize(400,400); window.setvisible(true); return tree; } 53

54 MTree ADT: Implementation Implementation (continued) public class MTree implements MTreeADT { public static void main(string[] args) { int n = 3; int k = 2; MTree tree = maketree("mtree recursive"); tree.expandrecursively(n,k); } 54

55 MTree ADT: Implementation Implementation (continued) public class MTree implements MTreeADT { private void expandrecursively(int n, int k) { expandrecursively(this.root, n, k); } private List<Integer> copyadd(list<integer> seq, int i) { List<Integer> copyseq = new ArrayList<Integer>(seq); copyseq.add(i); return copyseq; } 55

56 MTree ADT: Implementation 56 Implementation (continued): private void expandrecursively(mtreenode node, List<Integer> seq = node.getseq(); if (seq.size() < k) { } } } } June 2009 for (int i = 1; i <= n; i++) { if (!seq.contains(i)) { int n, int k) { List<Integer> newseq = copyadd(seq, i); MTreeNode child = new MTreeNode(newSeq); node.getchildren().add(child); expandrecursively(child, n, k); ,2 1,3 2,1 2,3 3,1 3,2

57 MTree ADT: Implementation Implementation (continued): private void expandstack(int n, int k) { Stack<MTreeNode> stack = new LinkedStack<MTreeNode>(); stack.push(this.root); while (!stack.isempty()) { MTreeNode node = stack.pop(); List<Integer> seq = node.getseq(); if (seq.size()<k) { for (int i=1; i<=n; i++) { if (!seq.contains(i)) { MTreeNode child = new MTreeNode(copyAdd(seq, i)); node.getchildren().add(child); stack.push(child); }}} } } 57

58 MTree ADT: Implementation Implementation (continued): private void expandqueue(int n, int k) { Queue<MTreeNode> queue = new LinkedQueue<MTreeNode>(); queue.offer(this.root); while (!queue.isempty()) { MTreeNode node = queue.poll(); List<Integer> seq = node.getseq(); if (seq.size()<k) { for (int i=1; i<=n; i++) { if (!seq.contains(i)) { MTreeNode child = new MTreeNode(copyAdd(seq, i)); node.getchildren().add(child); queue.offer(child); }}} } } } // DONE! 58

DM537/DM550 Object-Oriented Programming. Jan Baumbach

DM537/DM550 Object-Oriented Programming. Jan Baumbach DM537/DM550 Object-Oriented Programming Jan Baumbach jan.baumbach@imada.sdu.dk! http://www.baumbachlab.net!! Adopted from previous slides of Peter Schneider-Kamp.! ABSTRACT DATA TYPES FOR (BINARY) TREES

More information

DM537 Object-Oriented Programming. Peter Schneider-Kamp.

DM537 Object-Oriented Programming. Peter Schneider-Kamp. DM537 Object-Oriented Programming Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm537/! ABSTRACT DATA TYPES FOR (BINARY) TREES 2 Trees trees store elements non-sequentially every

More information

DM503 Programming B. Peter Schneider-Kamp.

DM503 Programming B. Peter Schneider-Kamp. DM503 Programming B Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm503/! PROJECT PART 2 2 Organizational Details exam project consisting of 2 parts both parts have to be passed

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ ABSTRACT DATA TYPES FOR (BINARY) TREES 2 Trees

More information

DM550 Introduction to Programming part 2. Jan Baumbach.

DM550 Introduction to Programming part 2. Jan Baumbach. DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net MULTIVARIATE TREES 2 Multivariate Trees general class of trees nodes can have any number of children

More information

DM550 Introduction to Programming part 2. Jan Baumbach.

DM550 Introduction to Programming part 2. Jan Baumbach. DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net Sorting Tree Balancing A sorted tree is balanced iff for each node holds: Math.abs(size(node.left)

More information

Binary Search Trees. BinaryTree<E> Class (cont.) Section /27/2017

Binary Search Trees. BinaryTree<E> Class (cont.) Section /27/2017 Binary Search Trees Section.4 BinaryTree Class (cont.) public class BinaryTree { // Data members/fields...just the root is needed - Node root; // Constructor(s) + BinaryTree() + BinaryTree(Node

More information

a graph is a data structure made up of nodes in graph theory the links are normally called edges

a 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 information

CSE 143 Lecture 16. Binary Search Trees. read slides adapted from Marty Stepp and Hélène Martin

CSE 143 Lecture 16. Binary Search Trees. read slides adapted from Marty Stepp and Hélène Martin CSE 143 Lecture 16 Binary Search Trees read 17.3-17.4 slides adapted from Marty Stepp and Hélène Martin http://www.cs.washington.edu/143/ Binary search trees binary search tree ("BST"): a binary tree where

More information

Basics of programming 3. Java GUI and SWING

Basics of programming 3. Java GUI and SWING Basics of programming 3 Java GUI and SWING Complex widgets Basics of programming 3 BME IIT, Goldschmidt Balázs 2 Complex widgets JList elements can be selected from a list JComboBox drop down list with

More information

CS350: Data Structures Binary Search Trees

CS350: Data Structures Binary Search Trees Binary Search Trees James Moscola Department of Engineering & Computer Science York College of Pennsylvania James Moscola Introduction to Binary Search Trees A binary search tree is a binary tree that

More information

HEAPS & PRIORITY QUEUES

HEAPS & PRIORITY QUEUES HEAPS & PRIORITY QUEUES Lecture 13 CS2110 Spring 2018 Announcements 2 A4 goes out today! Prelim 1: regrades are open a few rubrics have changed No Recitations next week (Fall Break Mon & Tue) We ll spend

More information

Sorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min

Sorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min Binary Search Trees FRIDAY ALGORITHMS Sorted Arrays Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min 6 10 11 17 2 0 6 Running Time O(1) O(lg n) O(1) O(1)

More information

Announcements HEAPS & PRIORITY QUEUES. Abstract vs concrete data structures. Concrete data structures. Abstract data structures

Announcements HEAPS & PRIORITY QUEUES. Abstract vs concrete data structures. Concrete data structures. Abstract data structures Announcements A due TOMORROW. Late deadline is Sunday. A5 released. Due next Thursday. Deadline for Prelim 1 regrade requests is tomorrow. Remember to complete your TA evaluations by tonight. HEAPS & PRIORITY

More information

Data Structures and Algorithms

Data 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 information

Data Structures in Java

Data 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 information

CS 350 : Data Structures Binary Search Trees

CS 350 : Data Structures Binary Search Trees CS 350 : Data Structures Binary Search Trees David Babcock (courtesy of James Moscola) Department of Physical Sciences York College of Pennsylvania James Moscola Introduction to Binary Search Trees A binary

More information

Building Java Programs

Building 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 information

Abstract vs concrete data structures HEAPS AND PRIORITY QUEUES. Abstract vs concrete data structures. Concrete Data Types. Concrete data structures

Abstract vs concrete data structures HEAPS AND PRIORITY QUEUES. Abstract vs concrete data structures. Concrete Data Types. Concrete data structures 10/1/17 Abstract vs concrete data structures 2 Abstract data structures are interfaces they specify only interface (method names and specs) not implementation (method bodies, fields, ) HEAPS AND PRIORITY

More information

from inheritance onwards but no GUI programming expect to see an inheritance question, recursion questions, data structure questions

from inheritance onwards but no GUI programming expect to see an inheritance question, recursion questions, data structure questions Exam information in lab Tue, 18 Apr 2017, 9:00-noon programming part from inheritance onwards but no GUI programming expect to see an inheritance question, recursion questions, data structure questions

More information

Introduction to Trees. D. Thiebaut CSC212 Fall 2014

Introduction to Trees. D. Thiebaut CSC212 Fall 2014 Introduction to Trees D. Thiebaut CSC212 Fall 2014 A bit of History & Data Visualization: The Book of Trees. (Link) We Concentrate on Binary-Trees, Specifically, Binary-Search Trees (BST) How Will Java

More information

CS 206 Introduction to Computer Science II

CS 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 information

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority. 3. Priority Queues 3. Priority Queues ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority. Malek Mouhoub, CS340 Winter 2007 1 3. Priority Queues

More information

Spring 2018 Mentoring 8: March 14, Binary Trees

Spring 2018 Mentoring 8: March 14, Binary Trees CSM 6B Binary Trees Spring 08 Mentoring 8: March 4, 08 Binary Trees. Define a procedure, height, which takes in a Node and outputs the height of the tree. Recall that the height of a leaf node is 0. private

More information

ITI Introduction to Computing II

ITI 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 information

PRIORITY QUEUES AND HEAPS

PRIORITY QUEUES AND HEAPS PRIORITY QUEUES AND HEAPS Lecture 17 CS2110 Spring 201 Readings and Homework 2 Read Chapter 2 A Heap Implementation to learn about heaps Exercise: Salespeople often make matrices that show all the great

More information

ITI Introduction to Computing II

ITI 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 information

tree nonlinear Examples

tree nonlinear Examples The Tree ADT Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary tree implementation Examine a binary tree example 10-2

More information

CS24 Week 8 Lecture 1

CS24 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 information

Name CPTR246 Spring '17 (100 total points) Exam 3

Name CPTR246 Spring '17 (100 total points) Exam 3 Name CPTR246 Spring '17 (100 total points) Exam 3 1. Linked Lists Consider the following linked list of integers (sorted from lowest to highest) and the changes described. Make the necessary changes in

More information

Topic 14. The BinaryTree ADT

Topic 14. The BinaryTree ADT Topic 14 The BinaryTree ADT Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary tree implementation Examine a binary tree

More information

Name 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 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 information

The smallest element is the first one removed. (You could also define a largest-first-out priority queue)

The smallest element is the first one removed. (You could also define a largest-first-out priority queue) Priority Queues Priority queue A stack is first in, last out A queue is first in, first out A priority queue is least-first-out The smallest element is the first one removed (You could also define a largest-first-out

More information

Principles of Computer Science

Principles of Computer Science Principles of Computer Science Binary Trees 08/11/2013 CSCI 2010 - Binary Trees - F.Z. Qureshi 1 Today s Topics Extending LinkedList with Fast Search Sorted Binary Trees Tree Concepts Traversals of a Binary

More information

PRIORITY QUEUES AND HEAPS

PRIORITY QUEUES AND HEAPS 10//1 Readings and Homework Read Chapter A Heap Implementation to learn about heaps PRIORITY QUEUES AND HEAPS Lecture 17 CS10 Fall 01 Exercise: Salespeople often make matrices that show all the great features

More information

ext Total Score /20 /20 /15 /20 /25 /5 Grader

ext Total Score /20 /20 /15 /20 /25 /5 Grader NAME: NETID: CS2110 Fall 2013 Prelim 2 November 21, 2013 Write your name and Cornell netid. There are 5 questions plus one extra-credit question on 10 numbered pages. Check now that you have all the pages.

More information

CS 206 Introduction to Computer Science II

CS 206 Introduction to Computer Science II CS 206 Introduction to Computer Science II 02 / 24 / 2017 Instructor: Michael Eckmann Today s Topics Questions? Comments? Trees binary trees two ideas for representing them in code traversals start binary

More information

Programming II (CS300)

Programming 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 information

Data Structures and Algorithms

Data 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 information

Priority queues. Priority queues. Priority queue operations

Priority queues. Priority queues. Priority queue operations Priority queues March 8, 08 Priority queues The ADT priority queue stores arbitrary objects with priorities. An object with the highest priority gets served first. Objects with priorities are defined by

More information

CS 231 Data Structures and Algorithms Fall Binary Search Trees Lecture 23 October 29, Prof. Zadia Codabux

CS 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 information

ECE 242 Data Structures and Algorithms. Heaps I. Lecture 22. Prof. Eric Polizzi

ECE 242 Data Structures and Algorithms.  Heaps I. Lecture 22. Prof. Eric Polizzi ECE 242 Data Structures and Algorithms http://www.ecs.umass.edu/~polizzi/teaching/ece242/ Heaps I Lecture 22 Prof. Eric Polizzi Motivations Review of priority queue Input F E D B A Output Input Data structure

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures Dr. Malek Mouhoub Department of Computer Science University of Regina Fall 2002 Malek Mouhoub, CS3620 Fall 2002 1 6. Priority Queues 6. Priority Queues ffl ADT Stack : LIFO.

More information

CS171 Final Practice Exam

CS171 Final Practice Exam CS171 Final Practice Exam Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 150 minutes to complete this exam. Read each problem carefully, and review your

More information

CS211, LECTURE 20 SEARCH TREES ANNOUNCEMENTS:

CS211, 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 information

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer Prelim 2 CS 2110, November 20, 2014, 7:30 PM 1 2 3 4 5 Extra Total Question True/False Short Answer Complexity Induction Trees Graphs Extra Credit Max 20 10 15 25 30 5 100 Score Grader The exam is closed

More information

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

! 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 information

CS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux

CS 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 information

Tutorial 4: Binary Trees

Tutorial 4: Binary Trees Tutorial 4: Binary Trees Full Binary Tree Theorem The number of leaves in a non-empty full binary tree is one more than the number of internal nodes No. of leaf nodes = No. of internal nodes + 1 Relevant

More information

TREES Lecture 12 CS2110 Spring 2018

TREES 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 information

1. Binary Tree Traversal. 2. Binary Search Tree. 1 of 12. Consider the following tree: Pre-order: In-order: Post-order:

1. Binary Tree Traversal. 2. Binary Search Tree. 1 of 12. Consider the following tree: Pre-order: In-order: Post-order: 1. Binary Tree Traversal Consider the following tree: +---+ 4 +---+ 1 9 / / +---+ 6 0 2 +---+ 3 8 \ \ \ \ 7 5 Fill in each of the traversals below : Pre-order: In-order: Post-order: 2. Binary Search Tree

More information

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS T E W H A R E W Ā N A N G A O T E Student ID:....................... Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2015 TRIMESTER 2 COMP103 INTRODUCTION

More information

Module 6: Binary Trees

Module 6: Binary Trees Module : Binary Trees Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 327 E-mail: natarajan.meghanathan@jsums.edu Tree All the data structures we have seen

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ RECURSION (REVISITED) 2 Recursion (Revisited)

More information

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

! 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 information

Figure 18.4 A Unix directory. 02/10/04 Lecture 9 1

Figure 18.4 A Unix directory. 02/10/04 Lecture 9 1 Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss 2002 Addison Wesley Figure 18.4 A Unix directory 02/10/04 Lecture 9 1 Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss 2002

More information

References and Homework ABSTRACT DATA TYPES; LISTS & TREES. Abstract Data Type (ADT) 9/24/14. ADT example: Set (bunch of different values)

References 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 information

Heaps. Heaps. A heap is a complete binary tree.

Heaps. Heaps. A heap is a complete binary tree. A heap is a complete binary tree. 1 A max-heap is a complete binary tree in which the value in each internal node is greater than or equal to the values in the children of that node. A min-heap is defined

More information

CS S-06 Binary Search Trees 1

CS S-06 Binary Search Trees 1 CS245-2008S-06 inary Search Trees 1 06-0: Ordered List T Operations: Insert an element in the list Check if an element is in the list Remove an element from the list Print out the contents of the list,

More information

Prelim 2 Solutions. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Prelim 2 Solutions. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer Prelim 2 Solutions CS 2110, November 20, 2014, 7:30 PM 1 2 3 4 5 Extra Total Question True/False Short Answer Complexity Induction Trees Graphs Extra Credit Max 20 10 15 25 30 5 100 Score Grader The exam

More information

CSC 421: Algorithm Design & Analysis. Spring 2015

CSC 421: Algorithm Design & Analysis. Spring 2015 CSC 421: Algorithm Design & Analysis Spring 2015 Divide & conquer divide-and-conquer approach familiar examples: merge sort, quick sort other examples: closest points, large integer multiplication tree

More information

CSE 2123: Collections: Priority Queues. Jeremy Morris

CSE 2123: Collections: Priority Queues. Jeremy Morris CSE 2123: Collections: Priority Queues Jeremy Morris 1 Collections Priority Queue Recall: A queue is a specific type of collection Keeps elements in a particular order We ve seen two examples FIFO queues

More information

INFO1x05 Tutorial 6. Exercise 1: Heaps and Priority Queues

INFO1x05 Tutorial 6. Exercise 1: Heaps and Priority Queues INFO1x05 Tutorial 6 Heaps and Priority Queues Exercise 1: 1. How long would it take to remove the log n smallest elements from a heap that contains n entries, using the operation? 2. Suppose you label

More information

INF2220: algorithms and data structures Series 1

INF2220: 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 information

DM537 Object-Oriented Programming. Peter Schneider-Kamp.

DM537 Object-Oriented Programming. Peter Schneider-Kamp. DM537 Object-Oriented Programming Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm537/! RECURSION (REVISITED) 2 Recursion (Revisited) recursive function = a function that calls

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ JAVA PROJECT 2 Organizational Details exam =

More information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

CIS 121. Binary Search Trees

CIS 121. Binary Search Trees CIS 121 Binary Search Trees 1 Binary Search Tree n A Binary Search Tree is a Binary Tree in which, at every node v, the values stored in the left subtree of v are less than the value at v and the values

More information

TREES 11/1/18. Prelim Updates. Data Structures. Example Data Structures. Tree Overview. Tree. Singly linked list: Today: trees!

TREES 11/1/18. Prelim Updates. Data Structures. Example Data Structures. Tree Overview. Tree. Singly linked list: Today: trees! relim Updates Regrades are live until next Thursday @ :9M A few rubric changes are happening Recursion question: -0pts if you continued to print Exception handling write the output of execution of that

More information

COMP 250 Midterm #2 March 11 th 2013

COMP 250 Midterm #2 March 11 th 2013 NAME: STUDENT ID: COMP 250 Midterm #2 March 11 th 2013 - This exam has 6 pages - This is an open book and open notes exam. No electronic equipment is allowed. 1) Questions with short answers (28 points;

More information

DM503 Programming B. Peter Schneider-Kamp.

DM503 Programming B. Peter Schneider-Kamp. DM503 Programming B Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm503/! ABSTRACT DATATYPE FOR LISTS 2 List ADT: Specification data are all integers, here represented as primitive

More information

CS165 Practice Midterm Problems Fall 2018

CS165 Practice Midterm Problems Fall 2018 CS165 Practice Midterm Problems Fall 2018 The following is a collection of practice problems for the CS165: Data Structures and Applications second midterm. The questions are similar to what they would

More information

CompSci 201 Tree Traversals & Heaps

CompSci 201 Tree Traversals & Heaps CompSci 201 Tree Traversals & Heaps Jeff Forbes March 28, 2018 3/28/18 CompSci 201, Spring 2018, Heaps 1 R is for R Programming language of choice in Stats Random From Monte-Carlo to [0,1) Recursion Base

More information

CSE 214 Computer Science II Heaps and Priority Queues

CSE 214 Computer Science II Heaps and Priority Queues CSE 214 Computer Science II Heaps and Priority Queues Spring 2018 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Introduction

More information

DM537 Object-Oriented Programming. Peter Schneider-Kamp.

DM537 Object-Oriented Programming. Peter Schneider-Kamp. DM537 Object-Oriented Programming Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm537/! TYPE CASTS & FILES & EXCEPTION HANDLING 2 Type Conversion Java uses type casts for converting

More information

Programming Abstractions

Programming Abstractions Programming Abstractions C S 1 0 6 B Cynthia Lee Topics: Priority Queue Linked List implementation Sorted Unsorted Heap structure implementation TODAY S TOPICS NOT ON THE MIDTERM 2 Some priority queue

More information

Data Structures. Giri Narasimhan Office: ECS 254A Phone: x-3748

Data Structures. Giri Narasimhan Office: ECS 254A Phone: x-3748 Data Structures Giri Narasimhan Office: ECS 254A Phone: x-3748 giri@cs.fiu.edu Search Tree Structures Binary Tree Operations u Tree Traversals u Search O(n) calls to visit() Why? Every recursive has one

More information

CS171 Final Practice Exam

CS171 Final Practice Exam CS171 Final Practice Exam Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 150 minutes to complete this exam. Read each problem carefully, and review your

More information

Facebook. / \ / \ / \ Accenture Nintendo

Facebook. / \ / \ / \ Accenture Nintendo 1. Binary Tree Traversal Consider the following tree: +---+ 4 +---+ 1 9 / / +---+ 6 0 2 +---+ 3 8 \ \ \ \ 7 5 Fill in each of the traversals below : Pre-order: 4 1 6 3 7 0 8 5 9 2 In-order: 3 7 6 1 0 8

More information

Tree Structures. Definitions: o A tree is a connected acyclic graph. o A disconnected acyclic graph is called a forest

Tree Structures. Definitions: o A tree is a connected acyclic graph. o A disconnected acyclic graph is called a forest Tree Structures Definitions: o A tree is a connected acyclic graph. o A disconnected acyclic graph is called a forest o A tree is a connected digraph with these properties: There is exactly one node (Root)

More information

COMP : Trees. COMP20012 Trees 219

COMP : Trees. COMP20012 Trees 219 COMP20012 3: Trees COMP20012 Trees 219 Trees Seen lots of examples. Parse Trees Decision Trees Search Trees Family Trees Hierarchical Structures Management Directories COMP20012 Trees 220 Trees have natural

More information

Trees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different.

Trees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different. Chapter 6 Trees In a hash table, the items are not stored in any particular order in the table. This is fine for implementing Sets and Maps, since for those abstract data types, the only thing that matters

More information

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

Advanced 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 information

CmpSci 187: Programming with Data Structures Spring 2015

CmpSci 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 information

Binary Trees

Binary Trees Binary Trees 4-7-2005 Opening Discussion What did we talk about last class? Do you have any code to show? Do you have any questions about the assignment? What is a Tree? You are all familiar with what

More information

Binary Node. private Object element; private BinaryNode left; private BinaryNode right; 02/18/03 Lecture 12 1

Binary Node. private Object element; private BinaryNode left; private BinaryNode right; 02/18/03 Lecture 12 1 Binary Node class BinaryNode public BinaryNode( ) this( null, null, null ); public BinaryNode( Object theelement,binarynode lt,binarynode rt); public static int size( BinaryNode t ); // size of subtree

More information

BINARY SEARCH TREES cs2420 Introduction to Algorithms and Data Structures Spring 2015

BINARY SEARCH TREES cs2420 Introduction to Algorithms and Data Structures Spring 2015 BINARY SEARCH TREES cs2420 Introduction to Algorithms and Data Structures Spring 2015 1 administrivia 2 -assignment 7 due tonight at midnight -asking for regrades through assignment 5 and midterm must

More information

CMPSCI 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 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 information

Arun chakravarthy Alagar samy. Technical Skill. Java Code Challenge - Basic Java

Arun chakravarthy Alagar samy. Technical Skill. Java Code Challenge - Basic Java Arun chakravarthy Alagar samy E-MAIL arunchakkravarthy@gmail.com DATE OF LAST ACTIVITY 2017-11-27 TEST Java Code Challenge - Basic LANGUAGES USED Java Technical Skill CANDIDATE RESULT SKILL THRESHOLD Strongly

More information

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop. Tree A tree consists of a set of nodes and a set of edges connecting pairs of nodes. A tree has the property that there is exactly one path (no more, no less) between any pair of nodes. A path is a connected

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS LECTURE 13 Babeş - Bolyai University Computer Science and Mathematics Faculty 2017-2018 In Lecture 12... Binary Search Trees Binary Tree Traversals Huffman coding Binary Search Tree Today Binary Search

More information

Announcements. Biostatistics 615/815 Lecture 7: Data Structures. Recap : Radix sort. Recap : Elementary data structures. Another good and bad news

Announcements. Biostatistics 615/815 Lecture 7: Data Structures. Recap : Radix sort. Recap : Elementary data structures. Another good and bad news Announcements Biostatistics 615/815 Lecture 7: Data Structures Hyun Min Kang Januray 27th, 2011 Another good and bad news Homework #2 is finally announced Due is on Feb 7th, but better start earlier 815

More information

Largest Online Community of VU Students

Largest 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 information

» Access elements of a container sequentially without exposing the underlying representation

» Access elements of a container sequentially without exposing the underlying representation Iterator Pattern Behavioural Intent» Access elements of a container sequentially without exposing the underlying representation Iterator-1 Motivation Be able to process all the elements in a container

More information

TREES Lecture 12 CS2110 Fall 2016

TREES 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 information

Swing. Component overview. Java UI, summer semester 2017/2018 1

Swing. Component overview. Java UI, summer semester 2017/2018 1 Swing Component overview 1 Label class JLabel for displaying short text image both 2 Buttons many kinds of buttons all of them extends AbstractButton regular button (JButton) "click" button toggle button

More information

Outline. An Application: A Binary Search Tree. 1 Chapter 7: Trees. favicon. CSI33 Data Structures

Outline. 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 information

Review: Trees Binary Search Trees Sets in Java Collections API CS1102S: Data Structures and Algorithms 05 A: Trees II

Review: Trees Binary Search Trees Sets in Java Collections API CS1102S: Data Structures and Algorithms 05 A: Trees II 05 A: Trees II CS1102S: Data Structures and Algorithms Martin Henz February 10, 2010 Generated on Wednesday 10 th February, 2010, 10:54 CS1102S: Data Structures and Algorithms 05 A: Trees II 1 1 Review:

More information

Trees. Tree Structure Binary Tree Tree Traversals

Trees. Tree Structure Binary Tree Tree Traversals Trees Tree Structure Binary Tree Tree Traversals The Tree Structure Consists of nodes and edges that organize data in a hierarchical fashion. nodes store the data elements. edges connect the nodes. The

More information

void insert( Type const & ) void push_front( Type const & )

void insert( Type const & ) void push_front( Type const & ) 6.1 Binary Search Trees A binary search tree is a data structure that can be used for storing sorted data. We will begin by discussing an Abstract Sorted List or Sorted List ADT and then proceed to describe

More information