CS : Data Structures
|
|
- Barnaby Lambert
- 6 years ago
- Views:
Transcription
1 CS : Data Structures Michael Schatz Oct 17, 2016 Lecture 19: Trees and Graphs
2 Assignment 6: Due Sunday Oct 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently written!
3 Part 1: Trees
4 Balancing Trees Balanced Binary Tree Minimum possible height Unbalanced Tree Non-minimum height What is the height of a balanced binary tree? What is the height of a balanced 3-ary tree? What is the height of a k-ary tree? How much taller is a binary tree than a k-ary tree? What is the maximum height of an unbalanced tree? lg n log 3 n log k n lg n/log k n = lg k n-1 L
5 Tree Heights
6 Tree Heights
7 Tree Heights (~1M leaves) Binary Tree H=20 3-ary Tree H=13
8
9
10 Tree Heights (~1M leaves) Binary Tree H=20 3-ary Tree H=13 What is the height with 1M total nodes?
11 Tree Interface public interface Tree<T>{ Position <T> insertroot(t t ) throws TreeNotEmptyException; Why insertroot? Position <T> insertchild(position <T> p, T t) throws InvalidPositionException; boolean empty(); Position <T> root() throws TreeEmptyException; Position <T>[] children(position <T> p) Why children()? throws InvalidPositionException, LeafException; Position <T> parent(position<t> p) throws InvalidPositionException ; boolean leaf (Position <T> p) throws InvalidPositionException ; What should parent(root()) return? T remove(position<t> p) What should remove(root()) do? throws InvalidPositionException, NotALeafException;
12 Tree Traversals + 1 * 2 3 Note here we visit children from left to right, but could go right to left Notice we visit internal nodes 3 times: 1: stepping down from parent 2: after visiting first child 3: after visiting second child Different algs work at different times 1: preorder + 1 * 2 3 2: inorder * 3 3: postorder * +
13 Traversal Implementations How to traverse? B A C D basictraversal(node n): // just entered from top basictraversal(n.left) // just got back from left basictraversal(n.middle) // just got back from middle basictraversal(n.right) // just got back from right return // leave to top E F G H I J K L
14 PreOrder Traversals [A] [D,C,B] [D,C,F,E] [D,C,F] [D,C,J] [D,C] [D] [I, H, G] Stack leads to a Depth-First Search B A C D How to preorder print? PreOrderTraversal(Node n): Stack s s.push(n) while (!s.empty()): Node x = s.pop() print(x) for c in x.children: s.push(c) E F G H I J K L
15 Level Order Traversals [A] [D,C,B] [F,E,D,C] [F,E,D] [I,H,G,F,E] [I,H,G,F] [J,I,H,G] [J,I,H] Queue leads to a Breadth-First Search B A C D How to level order print? (A) (B C D) (E F G H I) (J K L) LevelOrderTraversal(Node n): Queue q s.enqueue(n) while (!q.empty()): Node x = q.dequeue() print(x) for c in x.children: s.enqueue(c) E F G H I J K L
16 Call back interface public interface Tree<T> {... preorder(operation<t> o); inorder(operation<t> o); postorder(operation<t> o);... This works, but we will need 3 separate methods that have almost exactly the same code // The Operation<T> interface would look like this: public interface Operation<T> { void do(position<t> p); public class PrintOperation<T> implements Operation<T> { public void do(position<t> p) { System.out.println(p.get()); PrintOperation op = new PrintOperation(); tree.inorder(op);
17 Multiple Traversals public abstract class Operation<T> { void pre(position<t> p) { void in(position<t> p) { void post(position<t> p) { public interface Tree<T> {... traverse(operation<t> o);... Client extends Operation<T> but overrides just the methods that are needed J // Tree implementation pseudo-code: nicetraversal(node n, Operation o): if n is not null: o.pre(n) nicetraversal(n.left, o) o.in(n) nicetraversal(n.right, o) o.post(n)
18 Implementation (1) public class TreeImplementation<T> implements Tree<T> {... private static class Node<T> implements Position<T> { T data; Node<T> parent; ArrayList<Node<T>> children; public Node(T t) { this.children = new ArrayList<Node<T>>(); this.data = t; public T get() { return this.data; public void put(t t) { this.data = t; Constructor ensures children, data are initialized correctly What other fields might we want to include? (Hint: Position<>) Should set the color field to point to this Tree so Position<> can be checked
19 ArrayList
20 Traversal private void recurse(node<t> n, Operation<T> o) { if (n == null) { return; o.pre(n); for (Node<T> c: n.children) { this.recurse(c, o); // figure out when to call o.in(n) o.post(n); Private helper method working with Node<T> rather than Position<T> public void traverse(operation<t> o) { this.recurse(this.root, o); Just make sure we start at root When should we call o.in()? We don t want to call the in method after we visit the last child. We do want to call the in method even for a node with no children
21 Alternate Implementation parent parent siblings children[0] children[1] children[2] children A B C D A B C D E F G E F G Simple Implementation Overhead managing children[] Less Space Overhead (Except remove may require doubly linked lists)
22 More to come
23 Part 2:Graphs
24 Graphs are Everywhere! Computers in a network, Friends on Facebook, Roads & Cities on GoogleMaps, Webpages on Internet, Cells in your body,
25 Graphs A B Nodes aka vertices People, Proteins, Cities, Genes, Neurons, Sequences, Numbers, Edges aka arcs A is connected to B A is related to B A regulates B A precedes B A interacts with B A activates B
26 Graph Types A A A A B B C B C D C D E D E B E F G H F Cycle C A I J G B C List Tree Directed Acyclic Graph D E Complete
27 Definitions (1) A B C D Directed Edge E Self Edge (Unusual but usually allowed) Undirected Edge A and B are adjacent An edge connected to a vertex is incident on that vertex The number of edges incident on a vertex is the degree of that vertex For directed graphs, separately report indegree and outdegree A multigraph allows multiple edges between the same pair of nodes, a simple graph does not allow multiple edges (most common)
28 Definitions (2) A B H I C F G J D E A path is a sequence of edges e 1, e 2, e n in which each edge starts from the vertex the previous edge ended at A path that starts and ends at the same node is a cycle The number of edges in a path is called the length of the path A graph is connected if there is a path between every pair of nodes, otherwise it is disconnected into >1 connected components
29 The Road to the White House Maps Nodes: Cities / Intersections: Name / GPS Location Edges: Roads / Flight Path: Distance, Time, Cost
30 Graph Interface public interface Graph<V,E> {... Position<V> insertvertex(v v); Separate generic types for vertices <V> and edges <E> Position<E> insertedge(position<v> from, Position<V> to, E e) throws InvalidPositionException, InsertionException; V removevertex(position<v> p) throws InvalidPositionException, RemovalException; E removeedge(position<e> p) throws InvalidPositionException; Iterable<Position<V>> vertices(); Iterable<Position<E>> edges(); Iterable<Position<E>> incomingedges(position<v> p) throws InvalidPositionException; Iterable<Position<E>> outgoingedges(position<v> p) throws InvalidPositionException;... Can iterate through all the nodes OR iterate through all the edges as different algorithms may require one or the other
31 Representing Graphs A B Graph nodes C D E Node Node Node Node Node Node F A B C D in: out: E F G Edge Edge Edge Incidence List Good for sparse graphs Compact storage A D B D D F A: C, D, E D: F B: D, E E: F C: F, G G: edges
32 Representing Graphs A B Graph Do we need a separate edges list? nodes C D E Node Node Node Node Node Node F A B C D in: out: E F G Edge Edge Edge Incidence List Good for sparse graphs Compact storage A D B D D F A: C, D, E D: F B: D, E E: F C: F, G G: edges
33 Representing Graphs A B Graph nodes C D E Node Node Node Node Node Node F A B C D in: out: E F G Edge Edge Edge Incidence List Good for sparse graphs Compact storage A D B D D F A: C, D, E D: F B: D, E E: F C: F, G G: Note the labels in the edges are really references to the corresponding node objects!
34 Representing Graphs A B Complexity Analysis If n is the number of vertices, and m is the number of edges, we need O(n + m) space to represent the graph C D E F When we insert a vertex, allocate one object and two empty edge lists: O(1) When we insert an edge we allocate one object and insert the edge into appropriate lists for the incident vertices: O(1) G Incidence List Good for sparse graphs Compact storage A: C, D, E D: F B: D, E E: F C: F, G G: Remove a node? Remove an edge? Find/check edge between nodes? O(1); Only after edges removed O(d) where d is max degree; O(n) worse case O(d); O(n) worst case
35 Representing Graphs A B C D E F G A B C D E F G A B 1 1 C 1 1 D 1 E 1 F 1 G Adjacency Matrix Good for dense graphs Fast, Fixed storage: N 2 bits or N 2 weights Incidence List Good for sparse graphs Compact storage: ~8 bytes/edge A: C, D, E D: F B: D, E E: F C: F, G G: Edge List Easy, good if you (mostly) need to iterate through the edges ~16 bytes / edge A,C B,C C,F A,D B,D C,G A,E B,E D,F E,F F,G Tools Graphviz: Gephi: Cytoscape: digraph G { A->B B->C A->C $ dot -Tpdf -o g.pdf g.dot
36 Graph Interface public interface Graph<V,E> {... Position<V> insertvertex(v v); Separate generic types for vertices <V> and edges <E> Position<E> insertedge(position<v> from, Position<V> to, E e) throws InvalidPositionException, InsertionException; V removevertex(position<v> p) throws InvalidPositionException, RemovalException; E removeedge(position<e> p) throws InvalidPositionException; Iterable<Position<V>> vertices(); Iterable<Position<E>> edges(); Iterable<Position<E>> incomingedges(position<v> p) throws InvalidPositionException; Iterable<Position<E>> What will insertedge outgoingedges(position<v> into Graph<String, Integer> p) return? throws InvalidPositionException;... What will insertedge into Graph<Integer, Integer> return?
37 Graph Interface 2 public interface Edge<T> extends Position<T> { public interface Vertex<T> extends Position<T> { public interface Graph<V,E> {... Vertex<V> insertvertex(v v); Edge<E> insertedge(vertex<v> from, Vertex<V> to, E e) throws InvalidVertexException, InsertionException; V removevertex(vertex<v> p) throws InvalidVertexException, RemovalException; E removeedge(edge<e> p) throws InvalidEdgeException; Iterable<Vertex<V>> vertices(); Iterable<Edge<E>> edges();... Now clients can check at compile time if their types are correct What else is missing from the interface?
38 Graph Interface 3 public interface Graph<V,E> {... Vertex<V> fromvertex(edge<e> e)... Vertex<V> tovertex(edge<e> e) Now clients can check their code to see where the edges go! Don t just define an interface, try to use it!
39 Next Steps 1. Reflect on the magic and power of Trees, Graphs, and Sets! 2. Assignment 5 due Sunday October 10pm
40 Welcome to CS Questions?
CS : Data Structures
CS 600.226: Data Structures Michael Schatz Oct 14, 2016 Lecture 18: Tree Implementation Assignment 5: Due Sunday Oct 9 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently
More informationCS : Data Structures Michael Schatz. Oct Lecture 15. Graphs
CS 600.226: Data Structures Michael Schatz Oct 3 2018 Lecture 15. Graphs 1. Questions on HW4 2. Recap on Trees 3. Graphs genda ssignment 4: Due riday Oct 5 @ 10pm https://github.com/schatzlab/datastructures2018/blob/master/assignments/assignment04/redme.md
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Oct 12, 2016 Lecture 17: Trees Assignment 5: Due Sunday Oct 9 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently written!
More informationCS : Data Structures Michael Schatz. Oct Lecture 18. Midterm review 2
CS 600.226: Data Structures Michael Schatz Oct 10 2018 Lecture 18. Midterm review 2 Midterm Topics Topics 01.Intro (kd-tree) 02.Interfaces 03.ArraysGenericsExceptions 04.Lists 05.Iterators 06.Complexity
More informationUNIT IV -NON-LINEAR DATA STRUCTURES 4.1 Trees TREE: A tree is a finite set of one or more nodes such that there is a specially designated node called the Root, and zero or more non empty sub trees T1,
More informationData Structures Question Bank Multiple Choice
Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution
More informationMarch 20/2003 Jayakanth Srinivasan,
Definition : A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. Definition : In a multigraph G = (V, E) two or
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 informationTrees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology
Trees : Part Section. () (2) Preorder, Postorder and Levelorder Traversals Definition: A tree is a connected graph with no cycles Consequences: Between any two vertices, there is exactly one unique path
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 informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Oct 20, 2016 Lecture 21: Graphs and Sets Assignment 6: Due Monday Oct 24 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently
More informationTree. 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 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 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 informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Oct 3, 2016 Lecture 14: Machine Code Optimization Assignment 5: Due Sunday Oct 9 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should
More information12/5/17. trees. CS 220: Discrete Structures and their Applications. Trees Chapter 11 in zybooks. rooted trees. rooted trees
trees CS 220: Discrete Structures and their Applications A tree is an undirected graph that is connected and has no cycles. Trees Chapter 11 in zybooks rooted trees Rooted trees. Given a tree T, choose
More informationGRAPHS Lecture 19 CS2110 Spring 2013
GRAPHS Lecture 19 CS2110 Spring 2013 Announcements 2 Prelim 2: Two and a half weeks from now Tuesday, April16, 7:30-9pm, Statler Exam conflicts? We need to hear about them and can arrange a makeup It would
More informationTrees. Truong Tuan Anh CSE-HCMUT
Trees Truong Tuan Anh CSE-HCMUT Outline Basic concepts Trees Trees A tree consists of a finite set of elements, called nodes, and a finite set of directed lines, called branches, that connect the nodes
More informationUNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items.
UNIT III TREES A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items. Tree: A tree is a finite set of one or more nodes such that, there
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Oct 3, 2016 Lecture 13: More Lists Assignment 4: Due Sunday Oct 2 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently
More informationCS61B Lecture #20: Trees. Last modified: Wed Oct 12 12:49: CS61B: Lecture #20 1
CS61B Lecture #2: Trees Last modified: Wed Oct 12 12:49:46 216 CS61B: Lecture #2 1 A Recursive Structure Trees naturally represent recursively defined, hierarchical objects with more than one recursive
More informationR10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May
www.jwjobs.net R10 SET - 1 II B. Tech I Semester, Supplementary Examinations, May - 2012 (Com. to CSE, IT, ECC ) Time: 3 hours Max Marks: 75 *******-****** 1. a) Which of the given options provides the
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 informationCS61B Lecture #20: Trees. Last modified: Mon Oct 8 21:21: CS61B: Lecture #20 1
CS61B Lecture #20: Trees Last modified: Mon Oct 8 21:21:22 2018 CS61B: Lecture #20 1 A Recursive Structure Trees naturally represent recursively defined, hierarchical objects with more than one recursive
More informationCOMP 250 Fall binary trees Oct. 27, 2017
The order of a (rooted) tree is the maximum number of children of any node. A tree of order n is called an n-ary tree. It is very common to use trees of order 2. These are called binary trees. Binary Trees
More informationCMSC th Lecture: Graph Theory: Trees.
CMSC 27100 26th Lecture: Graph Theory: Trees. Lecturer: Janos Simon December 2, 2018 1 Trees Definition 1. A tree is an acyclic connected graph. Trees have many nice properties. Theorem 2. The following
More informationCS200 Midterm 2 Fall 2007
CS200 Midterm 2 Fall 2007 Name Topic Possible Received Generics, programming 10 Trees 35 Priority Queues, Heaps 30 Graphs 25 TOTAL 100 1. Generics/Programming [10 points] a. [4 points] Why is it important
More informationTrees. CSE 373 Data Structures
Trees CSE 373 Data Structures Readings Reading Chapter 7 Trees 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical relationships File directories
More informationAdvanced Tree Data Structures
Advanced Tree Data Structures Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park Binary trees Traversal order Balance Rotation Multi-way trees Search Insert Overview
More informationBinary 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 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 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 informationGRAPHS Lecture 17 CS2110 Spring 2014
GRAPHS Lecture 17 CS2110 Spring 2014 These are not Graphs 2...not the kind we mean, anyway These are Graphs 3 K 5 K 3,3 = Applications of Graphs 4 Communication networks The internet is a huge graph Routing
More informationCS 220: Discrete Structures and their Applications. graphs zybooks chapter 10
CS 220: Discrete Structures and their Applications graphs zybooks chapter 10 directed graphs A collection of vertices and directed edges What can this represent? undirected graphs A collection of vertices
More information8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))
DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES UNIT IV NONLINEAR DATA STRUCTURES Part A 1. Define Tree [N/D 08]
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 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 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 informationtree 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 informationTREES. Trees - Introduction
TREES Chapter 6 Trees - Introduction All previous data organizations we've studied are linear each element can have only one predecessor and successor Accessing all elements in a linear sequence is O(n)
More informationR10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May
Code No: R21051 R10 SET - 1 II B. Tech I Semester, Supplementary Examinations, May - 2012 DATA STRUCTURES (Com. to CSE, IT, ECC ) Time: 3 hours Max Marks: 75 Answer any FIVE Questions All Questions carry
More informationThis course is intended for 3rd and/or 4th year undergraduate majors in Computer Science.
Lecture 9 Graphs This course is intended for 3rd and/or 4th year undergraduate majors in Computer Science. You need to be familiar with the design and use of basic data structures such as Lists, Stacks,
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 information6-TREE. Tree: Directed Tree: A directed tree is an acyclic digraph which has one node called the root node
6-TREE Data Structure Management (330701) Tree: A tree is defined as a finite set of one or more nodes such that There is a special node called the root node R. The remaining nodes are divided into n 0
More informationUses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010
Uses for About Binary January 31, 2010 Uses for About Binary Uses for Uses for About Basic Idea Implementing Binary Example: Expression Binary Search Uses for Uses for About Binary Uses for Storage Binary
More informationTrees Algorhyme by Radia Perlman
Algorhyme by Radia Perlman I think that I shall never see A graph more lovely than a tree. A tree whose crucial property Is loop-free connectivity. A tree which must be sure to span. So packets can reach
More informationR13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)
SET - 1 II B. Tech I Semester Supplementary Examinations, May/June - 2016 PART A 1. a) Write a procedure for the Tower of Hanoi problem? b) What you mean by enqueue and dequeue operations in a queue? c)
More informationGraphs Introduction and Depth first algorithm
Graphs Introduction and Depth first algorithm Carol Zander Introduction to graphs Graphs are extremely common in computer science applications because graphs are common in the physical world. Everywhere
More informationObjective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)
Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113) 1. The number of interchanges required to sort 5, 1, 6, 2 4 in ascending order using Bubble Sort (A)
More informationCSC 321: Data Structures. Fall 2018
CSC 321: Data Structures Fall 2018 Graphs & search graphs, isomorphism simple vs. directed vs. weighted adjacency matrix vs. adjacency lists graph traversals depth-first search, breadth-first search finite
More informationCS204 Discrete Mathematics. 11 Trees. 11 Trees
11.1 Introduction to Trees Def. 1 A tree T = (V, E) is a connected undirected graph with no simple circuits. acyclic connected graph. forest a set of trees. A vertex of degree one is called leaf. Thm.
More informationIntroduction to Computers and Programming. Concept Question
Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 7 April 2 2004 Concept Question G1(V1,E1) A graph G(V, where E) is V1 a finite = {}, nonempty E1 = {} set of G2(V2,E2) vertices and
More informationTrees. Eric McCreath
Trees Eric McCreath 2 Overview In this lecture we will explore: general trees, binary trees, binary search trees, and AVL and B-Trees. 3 Trees Trees are recursive data structures. They are useful for:
More informationLecture 26: Graphs: Traversal (Part 1)
CS8 Integrated Introduction to Computer Science Fisler, Nelson Lecture 6: Graphs: Traversal (Part ) 0:00 AM, Apr, 08 Contents Introduction. Definitions........................................... Representations.......................................
More informationCOMP 250 Fall Solution - Homework #4
COMP 250 Fall 2013 - Solution - Homework #4 1) // Evaluates a single operation static public double apply(string op, double x1, double x2) { if (op.equals("add")) return x1+x2; if (op.equals("mult")) return
More informationTodays Lecture. Assignment 2 deadline: You have 5 Calendar days to complete.
Trees! Todays Lecture Assignment 2 deadline: 11 pm Monday 2/17 President s day. You have 5 Calendar days to complete. Trees What are trees in computer science? Data Structures for Trees Algorithms useful
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 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 informationAnnouncements Problem Set 4 is out!
CSC263 Week 8 Announcements Problem Set 4 is out! Due Tuesday (Nov 17) Other Announcements Drop date Nov 8 Final exam schedule is posted CSC263 exam Dec 11, 2-5pm This week s outline Graphs BFS Graph A
More informationChapter 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 information12 Abstract Data Types
12 Abstract Data Types 12.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT). Define
More informationBasic Graph Definitions
CMSC 341 Graphs Basic Graph Definitions A graph G = (V,E) consists of a finite set of vertices, V, and a finite set of edges, E. Each edge is a pair (v,w) where v, w V. V and E are sets, so each vertex
More informationCS171 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 informationSection 5.5. Left subtree The left subtree of a vertex V on a binary tree is the graph formed by the left child L of V, the descendents
Section 5.5 Binary Tree A binary tree is a rooted tree in which each vertex has at most two children and each child is designated as being a left child or a right child. Thus, in a binary tree, each vertex
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 04 / 06 / 2018 Instructor: Michael Eckmann Today s Topics Questions? Comments? Graphs Definition Terminology two ways to represent edges in implementation traversals
More informationCS61B Lecture #20. Today: Trees. Readings for Today: Data Structures, Chapter 5. Readings for Next Topic: Data Structures, Chapter 6
CS61B Lecture #20 Today: Trees Readings for Today: Data Structures, Chapter 5 Readings for Next Topic: Data Structures, Chapter 6 Last modified: Wed Oct 14 03:20:09 2015 CS61B: Lecture #20 1 A Recursive
More informationAn Introduction to Trees
An Introduction to Trees Alice E. Fischer Spring 2017 Alice E. Fischer An Introduction to Trees... 1/34 Spring 2017 1 / 34 Outline 1 Trees the Abstraction Definitions 2 Expression Trees 3 Binary Search
More informationGraphs & Digraphs Tuesday, November 06, 2007
Graphs & Digraphs Tuesday, November 06, 2007 10:34 PM 16.1 Directed Graphs (digraphs) like a tree but w/ no root node & no guarantee of paths between nodes consists of: nodes/vertices - a set of elements
More informationData Structure. IBPS SO (IT- Officer) Exam 2017
Data Structure IBPS SO (IT- Officer) Exam 2017 Data Structure: In computer science, a data structure is a way of storing and organizing data in a computer s memory so that it can be used efficiently. Data
More informationCOMP 250 Fall recurrences 2 Oct. 13, 2017
COMP 250 Fall 2017 15 - recurrences 2 Oct. 13, 2017 Here we examine the recurrences for mergesort and quicksort. Mergesort Recall the mergesort algorithm: we divide the list of things to be sorted into
More informationSection Summary. Introduction to Trees Rooted Trees Trees as Models Properties of Trees
Chapter 11 Copyright McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education. Chapter Summary Introduction to Trees Applications
More informationCSI 604 Elementary Graph Algorithms
CSI 604 Elementary Graph Algorithms Ref: Chapter 22 of the text by Cormen et al. (Second edition) 1 / 25 Graphs: Basic Definitions Undirected Graph G(V, E): V is set of nodes (or vertices) and E is the
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 informationTopic 18 Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb
Topic 18 "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb Definitions A tree is an abstract data type one entry point, the root Each node is either a leaf
More informationDATA STRUCTURES AND ALGORITHMS. Hierarchical data structures: AVL tree, Bayer tree, Heap
DATA STRUCTURES AND ALGORITHMS Hierarchical data structures: AVL tree, Bayer tree, Heap Summary of the previous lecture TREE is hierarchical (non linear) data structure Binary trees Definitions Full tree,
More informationBACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY
BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY General definitions; Representations; Graph Traversals; Topological sort; Graphs definitions & representations Graph theory is a fundamental tool in sparse
More informationROOT: A node which doesn't have a parent. In the above tree. The Root is A.
TREE: A tree is a finite set of one or more nodes such that there is a specially designated node called the Root, and zero or more non empty sub trees T 1, T 2...T k, each of whose roots are connected
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 informationTrees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.
Trees Q: Why study trees? : Many advance DTs are implemented using tree-based data structures. Recursive Definition of (Rooted) Tree: Let T be a set with n 0 elements. (i) If n = 0, T is an empty tree,
More informationMULTIMEDIA 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 informationTrees. Dr. Ronaldo Menezes Hugo Serrano Ronaldo Menezes, Florida Tech
Trees Dr. Ronaldo Menezes Hugo Serrano (hbarbosafilh2011@my.fit.edu) Introduction to Trees Trees are very common in computer science They come in different variations They are used as data representation
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 informationPrelim 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 informationAnnouncements. Midterm exam 2, Thursday, May 18. Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps. Break around 11:45am
Announcements Midterm exam 2, Thursday, May 18 Closed book/notes but one sheet of paper allowed Covers up to stacks and queues Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps
More informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 4 Graphs Definitions Traversals Adam Smith 9/8/10 Exercise How can you simulate an array with two unbounded stacks and a small amount of memory? (Hint: think of a
More informationGraph and Digraph Glossary
1 of 15 31.1.2004 14:45 Graph and Digraph Glossary A B C D E F G H I-J K L M N O P-Q R S T U V W-Z Acyclic Graph A graph is acyclic if it contains no cycles. Adjacency Matrix A 0-1 square matrix whose
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 informationand 6.855J February 6, Data Structures
15.08 and 6.855J February 6, 003 Data Structures 1 Overview of this Lecture A very fast overview of some data structures that we will be using this semester lists, sets, stacks, queues, networks, trees
More information9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology
Introduction Chapter 4 Trees for large input, even linear access time may be prohibitive we need data structures that exhibit average running times closer to O(log N) binary search tree 2 Terminology recursive
More information( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&
CSE 0 Name Test Summer 008 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time for the following code is in which set? for (i=0; i
More informationDirect Addressing Hash table: Collision resolution how handle collisions Hash Functions:
Direct Addressing - key is index into array => O(1) lookup Hash table: -hash function maps key to index in table -if universe of keys > # table entries then hash functions collision are guaranteed => need
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 informationData Structures Brett Bernstein
Data Structures Brett Bernstein Final Review 1. Consider a binary tree of height k. (a) What is the maximum number of nodes? (b) What is the maximum number of leaves? (c) What is the minimum number of
More informationA6-R3: DATA STRUCTURE THROUGH C LANGUAGE
A6-R3: DATA STRUCTURE THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered in the TEAR-OFF
More informationLec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)
Lec 17 April 8 Topics: binary Trees expression trees Binary Search Trees (Chapter 5 of text) Trees Linear access time of linked lists is prohibitive Heap can t support search in O(log N) time. (takes O(N)
More informationTrees. Courtesy to Goodrich, Tamassia and Olga Veksler
Lecture 12: BT Trees Courtesy to Goodrich, Tamassia and Olga Veksler Instructor: Yuzhen Xie Outline B-tree Special case of multiway search trees used when data must be stored on the disk, i.e. too large
More informationJana Kosecka. Red-Black Trees Graph Algorithms. Many slides here are based on E. Demaine, D. Luebke slides
Jana Kosecka Red-Black Trees Graph Algorithms Many slides here are based on E. Demaine, D. Luebke slides Binary Search Trees (BSTs) are an important data structure for dynamic sets In addition to satellite
More informationIS 709/809: Computational Methods in IS Research. Graph Algorithms: Introduction
IS 709/809: Computational Methods in IS Research Graph Algorithms: Introduction Nirmalya Roy Department of Information Systems University of Maryland Baltimore County www.umbc.edu Motivation Several real-life
More informationBBM 201 Data structures
BBM 201 Data structures Lecture 11: Trees 2018-2019 Fall Content Terminology The Binary Tree The Binary Search Tree Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, 2013
More informationCSE 373 MAY 10 TH SPANNING TREES AND UNION FIND
CSE 373 MAY 0 TH SPANNING TREES AND UNION FIND COURSE LOGISTICS HW4 due tonight, if you want feedback by the weekend COURSE LOGISTICS HW4 due tonight, if you want feedback by the weekend HW5 out tomorrow
More information