Back To LinkedLists 1. 3 public Node left; 4 public Node right; 6 public Node(int data, Node left, Node right) {
|
|
- Harriet Snow
- 5 years ago
- Views:
Transcription
1 Adam Blank Leture Autumn 0 CSE 3X Aelerated Computer Programming I/II CSE 3X: Aelerated Computer Programming I/II Binary Trees Outline Bak To LinkedLists Consider the following standard LinkedList: LinkedLists to BinaryTrees front 0 3 Why Do We Care About Binary Trees? 3 Printing Reursively Binary Tree Traversals Reall the definition of a ListNode publi lass Node { publi int data; 3 publi Node next; publi Node(int data, Node next) { 6 this.data = data; 7 this.next = next; 8 } 9 } What if we added more fields? Multiple data fields? Multiple next fields? Bak To LinkedLists Nodes with Multiple next Fields publi lass Node { publi int data; 3 publi Node next; publi Node next; 6 publi Node(int data, Node next, Node next) { 7 this.data = data; 8 this.next = next; 9 this.next = next; 0 } } front 0 (yellow is next; red is next) 3 Introduing Trees 3 Binary Trees publi lass Node { publi int data; 3 publi Node left; publi Node right; 6 publi Node(int data, Node left, Node right) { 7 this.data = data; 8 this.left = left; 9 this.right = right; 0 } } 3 0 leaf leaf leaf (red is right; yellow is left)
2 Bak To LinkedLists Consider the following LinkedList of a mathematial expression: front Uses of Trees Parsing (Programming Languages, Math, et.) + ( ) + ( 7 3 ) 7 3 What s bad about it? It doesn t really help us with the struture Looking at it doesn t really show us what s going on Implementing TreeSet What about this struture instead? Diretory File Struture Douments + Videos Courses Fun.mp Yay.mp Hello.mp CSE CSE3 7 3 grades.txt HW answers.txt HW Now we an see the order of operations muh more learly! More Uses of Trees 6 Printing A LinkedList (Again) 7 Reursive Trees (inluding things like games of Ti-Ta-Toe) words() a b d words() words() words() words() publi void print() { Node urrent = this.front; 3 while (urrent!= null) { System.out.print(urrent.data + " "); urrent = urrent.next; a b d a b d a b d a b d aa ab a ad ba bb b bd a b d da db d dd We d like to figure out how to print trees. Sine LinkedLists are simpler versions of trees, they might help. Compression (this will be your last assignment!) How do we go in every diretion in a tree? USE RECURSION! Printing a LinkedList Reursively 8 Printing a Tree Reursively 9 To print a LinkedList... Print the front of the list Print the next of the list (reursively) To print a BinaryTree... Print the of the tree Print the left of the tree (reursively) Print the right of the tree (reursively) Code publi void print() { print(this.front); publi void print(node ) { 6 if (!= null) { 7 System.out.print(.data + " "); 8 print(.next); 9 } 0 } Code publi void print() { print(this.); publi void print(node ) { 6 if (!= null) { 7 System.out.print(.data + " "); 8 print(.left); 9 print(.right); 0 } }
3 Printing a Tree Example 0 Printing a Tree Example publi void print(node ) { // = 3 System.out.print(.data + " "); print(.left); print(.right); publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); >> >> Printing a Tree Example publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); publi System.out.print(.data void print(node ) + { "//"); = 3 print(.left); 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); Printing a Tree Example 3 publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); publi System.out.print(.data void print(node ) + { "//"); = 3 print(.left); 3 print(.right); publi System.out.print(.data void print(node ) + { "//"); = null print(.left); // is null! 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); >> 3 >> 3 Printing a Tree Example publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); publi System.out.print(.data void print(node ) + { "//"); = 3 print(.left); 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); Printing a Tree Example publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); publi System.out.print(.data void print(node ) + { "//"); = 3 print(.left); 3 print(.right); publi System.out.print(.data void print(node ) + { "//"); = null print(.left); // is null! 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); 3 >> 3 >> 3
4 Printing a Tree Example 6 publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); publi System.out.print(.data void print(node ) + { "//"); = 3 print(.left); 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); Printing a Tree Example 7 publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); >> 3 >> 3 Printing a Tree Example 8 publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); Printing a Tree Example 9 publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); >> >> Printing a Tree Example 0 publi void print(node ) { // = 3 System.out.print(.data + " "); print(.left); print(.right); Printing a Tree Example publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); >> >>
5 Printing a Tree Example publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); publi System.out.print(.data void print(node ) + { "//"); = 6 print(.left); 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); Printing a Tree Example 3 publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); >> 6 >> 6 Printing a Tree Example publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); publi System.out.print(.data void print(node ) + { "//"); = 7 print(.left); 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); Printing a Tree Example publi void print(node ) { // = 3 publi System.out.print(.data void print(node ) + { "//"); = print(.left); 3 print(.right); System.out.print(.data + " "); print(.left); print(.right); >> >> Printing a Tree Example 6 publi void print(node ) { // = 3 System.out.print(.data + " "); print(.left); print(.right); >> Tree Traversals 7 Pre-Order Traversal publi void print(node ) { 3 System.out.print(.data + " "); // print print(.left); // left print(.right); // right In-Order Traversal publi void print(node ) { 3 print(.left); // left System.out.print(.data + " "); // print print(.right); // right Post-Order Traversal publi void print(node ) { 3 print(.left); // left print(.right); // right System.out.print(.data + " "); // print
6 Tree Traversal Example 8 Consider the following binary tree: 0 3 Traversal Trik 9 To Quikly Generate A Traversal a path around the tree As you pass a node on the proper side, proess it: Pre-Order: left In-Order: bottom Post-Order: right Compute the Pre-Order, In-Order, and Post-Order Traversals: Pre-Order: 0,, 3,, 3, 66, 7, In-Order: 3,,, 0, 66, 3, 7, Post-Order: 3,,, 66,, 7, 3, Binary Tree method 30 Binary Tree methods are just normal reursive funtions. The base ase/reursive alls will always be similar. Writing a Binary Tree Method The base ase is urrent == null. First reursive ase is method(urrent.left) Seond reursive ase is method(urrent.right) publi type method(...) { return method(this.,...); private type method(treenode urrent,...) { if (urrent == null) { /* DO BASE CASE */ } 6 7 // Do the left reursive ase: 8 type leftresult = method(urrent.left,...); 9 0 // Do the right reursive ase: type rightresult = method(urrent.right,...); 3 /* Use the left and right results... */ return...; } Binary Tree ontains() 3 ontains() Write a method, in the IntTree lass, alled ontains(): publi boolean ontains(int value); that returns true if the tree ontains value and false otherwise. publi boolean ontains(int value) { return ontains(this., value); private boolean ontains(inttreenode urrent, int value) { /* If the tree is null, it definitely doesn t ontain value... */ 6 if (urrent == null) { return false; } 7 8 /* If urrent *is* value, we found it! */ 9 else if (urrent.data == value) { return true; } 0 else { boolean leftcontainsvalue = ontains(urrent.left, value); 3 boolean rightcontainsvalue = ontains(urrent.right, value); return leftcontainsvalue rightcontainsvalue; } Some Tree Tips! 3 Trees are just generalized LinkedLists. So, all of the things you learned about referenes with LinkedLists are going to apply to trees as well Almost all the tree methods you write will be reursive (and will have a private helper that takes in the ) Make sure you understand all the traversals; the trik an be very useful.
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 informationData Structures in Java
Data Strutures in Java Leture 8: Trees and Tree Traversals. 10/5/2015 Daniel Bauer 1 Trees in Computer Siene A lot of data omes in a hierarhial/nested struture. Mathematial expressions. Program struture.
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 informationBinary Search Trees. Ravi Chugh March 28, 2014
Binary Search Trees Ravi Chugh March 28, 2014 1 Review: Linked Lists Goal: Program that keeps track of friends Problem: Arrays have fixed length SoluIon: Linked Lists null 2 Review: Linked Lists class
More informationRecursion examples: Problem 2. (More) Recursion and Lists. Tail recursion. Recursion examples: Problem 2. Recursion examples: Problem 3
Reursion eamples: Problem 2 (More) Reursion and s Reursive funtion to reverse a string publi String revstring(string str) { if(str.equals( )) return str; return revstring(str.substring(1, str.length()))
More information1. 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 informationCSE 143 Lecture 19. Binary Trees. read slides created by Marty Stepp
CSE 143 Lecture 19 Binary Trees read 17.1-17.2 slides created by Marty Stepp http://www.cs.washington.edu/143/ Trees tree: A directed, acyclic structure of linked nodes. directed : Has one-way links between
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 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 informationCSE143 Summer 2008 Final Exam Part B KEY August 22, 2008
CSE143 Summer 2008 Final Exam Part B KEY August 22, 2008 Name : Section (eg. AA) : TA : This is an open-book/open-note exam. Space is provided for your answers. Use the backs of pages if necessary. The
More informationIntroduction to Computer Science II CS S-20 Linked Lists III
Introduction to Computer Science II CS112-2012S-20 Linked Lists III David Galles Department of Computer Science University of San Francisco 20-0: Linked List Previous Practical Example: removeat(int index)
More informationFacebook. / \ / \ / \ 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 informationCSE143 Summer 2008 Final Exam Part A KEY August 21, 2008
CSE143 Summer 28 Final Exam Part A KEY August 21, 28 Name : Section (eg. AA) : TA : This is an open-book/open-note exam. Space is provided for your answers. Use the backs of pages if necessary. The exam
More information/department of mathematics and computer science 1/58
=! # Linked lists and binary search trees Linked list: % $ " A N J A N J A N J A N J E A @ E I J A A A J @ K > A A N J E A @ E I J = @ @ - A A J @ K > A L E @ C A J 5 E A E J E I A H J - A A J ) J @ K
More informationCSE 143X. Accelerated Computer Programming I/II
Adam Blank Lecture 12a Autumn 2015 CSE 143X Accelerated Computer Programming I/II CSE 143X: Accelerated Computer Programming I/II Linked Lists I Outline 1 Learn how LinkedIntList is implemented 2 Learn
More informationToday s Goals 2. Get familiar with the idea of references (things that point to objects) So far, the only real data structure we ve seen is arrays
Adam Blank Lecture a Autumn CSE X: Accelerated Computer Programming I/II CSE X List Nodes Accelerated Computer Programming I/II More Than Arrays Today s Goals Get familiar with the idea of references (things
More informationCS S-20 Linked Lists IV 1
CS112-2012S-20 Linked Lists IV 1 20-0: Doubly Linked List Deleting from (and inserting into!) a linked can be challenging because you need to find the node before the node you are looking for Once you
More informationCS 151. Linked Lists, Recursively Implemented. Wednesday, October 3, 12
CS 151 Linked Lists, Recursively Implemented 1 2 Linked Lists, Revisited Recall that a linked list is a structure that represents a sequence of elements that are stored non-contiguously in memory. We can
More informationPoints off Total off Net Score. CS 314 Final Exam Spring 2017
Points off 1 2 3 4 5 6 Total off Net Score CS 314 Final Exam Spring 2017 Your Name Your UTEID Instructions: 1. There are 6 questions on this test. 100 points available. Scores will be scaled to 300 points.
More informationUnit 9 Practice Test (AB27-30)
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()) ==
More informationCS S-20 Linked Lists III 1. We can then use the next pointer of the previous node to do removal (example on board)
CS112-2012S-20 Linked Lists III 1 20-0: Linked List ious Practical Example: removeat(int index) remove( o) 20-1: removeat First need to get to node before the one we want to remove We can then use the
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 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 informationYour friends the Trees. Data Structures
Your friends the Trees Data Structures LETS PLAY A GAME! I guess a number from 1 to 100 You can ask me a yes/no question PRIZES!! Your turn in pairs I guess a number from 1 to 100 You can ask a yes/no
More informationDefinitions Homework. Quine McCluskey Optimal solutions are possible for some large functions Espresso heuristic. Definitions Homework
EECS 33 There be Dragons here http://ziyang.ees.northwestern.edu/ees33/ Teaher: Offie: Email: Phone: L477 Teh dikrp@northwestern.edu 847 467 2298 Today s material might at first appear diffiult Perhaps
More informationIntroduction to Computer Science II CS S-20 Linked Lists IV
Introduction to Computer Science II CS112-2012S-20 Linked Lists IV David Galles Department of Computer Science University of San Francisco 20-0: Doubly Linked List Deleting from (and inserting into!) a
More informationCSE 143. Lecture 7: Linked List Basics reading: 16.2
CSE 143 Lecture 7: Linked List Basics reading: 16.2 References vs. objects variable = value; a variable (left side of = ) is an arrow (the base of an arrow) a value (right side of = ) is an object (a box;
More informationDepartment of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Test I Solutions
Department of Eletrial Engineering and Computer iene MAACHUETT INTITUTE OF TECHNOLOGY 6.035 Fall 2016 Test I olutions 1 I Regular Expressions and Finite-tate Automata For Questions 1, 2, and 3, let the
More informationCS 151. Binary Search Trees. Wednesday, October 10, 12
CS 151 Binary Search Trees 1 Binary Search Tree A binary search tree stores comparable elements in a binary tree such that for every node r all nodes in the left BST are
More information: Advanced Programming Final Exam Summer 2008 June 27, 2008
15-111 : Advanced Programming Final Exam Summer 2008 June 27, 2008 Name: Andrew ID: Answer the questions in the space provided following each question. We must be able to clearly understand your answer.
More informationIntroduction to Object-Oriented Programming
Introduction to Object-Oriented Programming Linked Lists Christopher Simpkins chris.simpkins@gatech.edu CS 1331 (Georgia Tech) Linked Lists 1 / 13 Linked Lists Dynamic data structures Singly linked lists
More informationLinked Lists. Linked List Nodes. Walls and Mirrors Chapter 5 10/25/12. A linked list is a collection of Nodes: item next -3.
Linked Lists Walls and Mirrors Chapter 5 Linked List Nodes public class Node { private int item; private Node next; public Node(int item) { this(item,null); public Node(int item, Node next) { setitem(item);
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 informationCSE 143: Computer Programming II Autumn Sample Solutions
CSE 43: Computer Programming II Autumn 206 Final Exam Name: Sample Solutions E-mail: bovik @washington.edu TA: The Best Section: A9 INSTRUCTIONS: You have 0 minutes to complete the exam. You will receive
More informationCSE 143, Winter 2010 Final Exam Thursday, March 18, 2010
CSE 143, Winter 2010 Final Exam Thursday, March 18, 2010 Personal Information: Name: Section: Student ID #: TA: You have 110 minutes to complete this exam. You may receive a deduction if you keep working
More informationCS18000: Programming I
CS18000: Programming I Dynamic Data Structures 12 April 2010 Prof. Chris Clifton More on Dynamic Data Structures Difficulties with Dynamic Data Structures: Removing self Solution 1: Violate Encapsulation
More informationDoubly LinkedList is Symmetrical! LinkedList Efficiency. Monday, April 8, 13. insert insert remove remove remove walk
How Can We Improve the State of Experimental Evaluation in Computer Siene Peter Sweeney IBM Researh, TJ Watson Friday, April 12, 12:00 Kendade 307 1 Doubly LinkedList is Symmetrial! insert insert remove
More informationData 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 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 informationCSC148-Section:L0301
Slides adapted from Professor Danny Heap course material winter17 CSC148-Section:L0301 Week#8-Friday Instructed by AbdulAziz Al-Helali a.alhelali@mail.utoronto.ca Office hours: Wednesday 11-1, BA2230.
More informationBoolean Expressions and if 9/14/2007
Boolean Expressions and if 9/14/2007 1 Opening Discussion Do you have any questions about the quiz? Let's look at solutions to the interclass problem. Minute essay questions. What functions will we be
More informationIn addition to the correct answer, you MUST show all your work in order to receive full credit.
In addition to the correct answer, you MUST show all your work in order to receive full credit. Questions Mark: Question1) Multiple Choice Questions /10 Question 2) Binary Trees /15 Question 3) Linked
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 informationStack ADT. ! push(x) puts the element x on top of the stack! pop removes the topmost element from the stack.
STACK Stack ADT 2 A stack is an abstract data type based on the list data model All operations are performed at one end of the list called the top of the stack (TOS) LIFO (for last-in first-out) list is
More informationAbout This Lecture. Trees. Outline. Recursive List Definition slide 1. Recursive Tree Definition. Recursive List Definition slide 2
Revised 21-Mar-05 About This Lecture 2 Trees In this lecture we study a non-linear container called a Tree and a special kind of Tree called a Binary Tree. CMPUT 115 - Lecture 18 Department of Computing
More informationAlgorithms for External Memory Lecture 6 Graph Algorithms - Weighted List Ranking
Algorithms for External Memory Leture 6 Graph Algorithms - Weighted List Ranking Leturer: Nodari Sithinava Sribe: Andi Hellmund, Simon Ohsenreither 1 Introdution & Motivation After talking about I/O-effiient
More informationLinked Lists. References and objects
Linked Lists slides created by Marty Stepp http://www.cs.washington.edu/143/ Modified by Sarah Heckman Reading: RS Chapter 16 References and objects In Java, objects and arrays use reference semantics.
More informationCSE 143 Sample Final Exam #5
CSE 143 Sample Final Exam #5 1. Inheritance and Polymorphism. Consider the following classes (System.out.println has been abbreviated as S.o.pln): public class Blue extends Green { public void one() {
More informationp[4] p[3] p[2] p[1] p[0]
CMSC 425 : Sring 208 Dave Mount and Roger Eastman Homework Due: Wed, Marh 28, :00m. Submit through ELMS as a df file. It an either be distilled from a tyeset doument or handwritten, sanned, and enhaned
More informationCIS265 Homework7 A (partial) solution showing creation/traversal of an expression-tree made from a a valid arithmetical expression
CIS265 Homework7 A (partial) solution showing creation/traversal of an expression-tree made from a a valid arithmetical expression Driver package csu.matos; import java.util.stack; import java.util.stringtokenizer;
More informationCS Introduction to Data Structures Week 5, 2017
CS 367 - Introduction to Data Structures Week 5, 2017 Homework h2 graded. Email TA (di3@wisc.edu) by Tuesday, July 18 th - 5 pm. Homework h4 posted, complete as soon as possible; Due by Sunday, July 23
More informationAdam Blank Lecture 4 Winter 2015 CSE 143. Computer Programming II
Adam Blank Lecture 4 Winter 2015 CSE 143 Computer Programming II CSE 143: Computer Programming II Efficiency; Interfaces Questions From Last Time 1 Does a constructor have to use all the fields specified
More informationCSC 321: Data Structures. Fall 2012
CSC 321: Data Structures Fall 2012 Proofs & trees proof techniques direct proof, proof by contradiction, proof by induction trees tree recursion BinaryTree class 1 Direct proofs the simplest kind of proof
More informationGray Codes for Reflectable Languages
Gray Codes for Refletable Languages Yue Li Joe Sawada Marh 8, 2008 Abstrat We lassify a type of language alled a refletable language. We then develop a generi algorithm that an be used to list all strings
More informationAnalyzing Complexity of Lists
Analyzing Complexity of Lists Operation Sorted Array Sorted Linked List Unsorted Array Unsorted Linked List Search( L, x ) O(logn) O( n ) O( n ) O( n ) Insert( L, x ) O(logn) O( n ) + O( 1 ) O( 1 ) + O(
More informationCOMP 103. 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 2004 END-YEAR COMP 103 Data Structures and Algorithms Time Allowed: 3 Hours Instructions:
More informationCommunications of the ACM Learning to Learn Denning & Flores https://cacm.acm.org/magazines/2016/12/ learning-to-learn/fulltext
Communications of the ACM Learning to Learn Denning & Flores https://cacm.acm.org/magazines/2016/12/210369-learning-to-learn/fulltext CS 2230 CS II: Data structures Meeting 22: tree traversal Brandon Myers
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 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 informationIX. Binary Trees (Chapter 10)
IX. Binary Trees (Chapter 10) -1- A. Introduction: Searching a linked list. 1. Linear Search /* To linear search a list for a particular Item */ 1. Set Loc = 0; 2. Repeat the following: a. If Loc >= length
More informationToday s Outline. Motivation. Disjoint Sets. Disjoint Sets and Dynamic Equivalence Relations. Announcements. Today s Topics:
Today s Outline Disjoint Sets and Dynamic Equivalence Relations Announcements Assignment # due Thurs 0/ at pm Today s Topics: Disjoint Sets & Dynamic Equivalence CSE Data Structures and Algorithms 0//0
More informationFacebook. / \ / \ / \ 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 informationDM537 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 informationCSE 143. Computer Programming II
Adam Blank Lecture 11 Spring 2015 CSE 143 Computer Programming II CSE 143: Computer Programming II Recursive Programming public static void solveproblem() { solveproblem(); } Outline 1 Writing Recursive
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 informationLecture 14. Recursion
Leture 14 Reursion Announements for Today Prelim 1 Tonight at 5:15 OR 7:30 A D (5:15, Uris G01) E-K (5:15, Statler) L P (7:30, Uris G01) Q-Z (7:30, Statler) Graded y noon on Sun Sores will e in CMS In
More informationCSC 321: Data Structures. Fall 2016
CSC 321: Data Structures Fall 2016 Trees & recursion trees, tree recursion BinaryTree class BST property BinarySearchTree class: override add, contains search efficiency 1 Trees a tree is a nonlinear data
More informationCryptol Crib Sheet 1
Cryptol Crib Sheet 1 1 To Use Cryptol: 1. From the linux ommand line: prompt> to get this: Cryptol version 1.8.4, Copyright (C) 2004-2008 Galois, In. www..net Type :? for help Cryptol> 2. To load a soure
More informationCS 2230 CS II: Data structures. Meeting 21: trees Brandon Myers University of Iowa
CS 2230 CS II: Data structures Meeting 21: trees Brandon Myers University of Iowa Today s learning objectives Define tree (a data structure that can store data hierarchically) and describe trees in terms
More informationRuntime Support for OOLs Part II Comp 412
COMP 412 FALL 2017 Runtime Support for OOLs Part II Comp 412 soure IR Front End Optimizer Bak End IR target Copright 2017, Keith D. Cooper & Linda Torzon, all rights reserved. Students enrolled in Comp
More informationCMSC 330, Fall 2013, Practice Problems 3
CMSC 330, Fall 2013, Practice Problems 3 1. OCaml and Functional Programming a. Define functional programming b. Define imperative programming c. Define higher-order functions d. Describe the relationship
More informationLinked List using a Sentinel
Linked List using a Sentinel Linked List.h / Linked List.h Using a sentinel for search Created by Enoch Hwang on 2/1/10. Copyright 2010 La Sierra University. All rights reserved. / #include
More informationComputer Science II Fall 2009
Name: Computer Science II Fall 2009 Exam #2 Closed book and notes. This exam should have five problems and six pages. Problem 0: [1 point] On a scale of 0 5, where 5 is highest, I think I deserve a for
More informationRun Time Environment. Implementing Object-Oriented Languages
Run Time Environment Implementing Objet-Oriented Languages Copright 2017, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers lass at the Universit of Southern California have epliit
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 informationData Structures and Algorithms
Data Structures and Algorithms First Semester 2017/2018 Linked Lists Eng. Anis Nazer Linked List ADT Is a list of nodes Each node has: data (can be any thing, int, char, Person, Point, day,...) link to
More informationCS61BL Summer 2013 Midterm 2
CS61BL Summer 2013 Midterm 2 Sample Solutions + Common Mistakes Question 0: Each of the following cost you.5 on this problem: you earned some credit on a problem and did not put your five digit on the
More informationExtracting Partition Statistics from Semistructured Data
Extrating Partition Statistis from Semistrutured Data John N. Wilson Rihard Gourlay Robert Japp Mathias Neumüller Department of Computer and Information Sienes University of Strathlyde, Glasgow, UK {jnw,rsg,rpj,mathias}@is.strath.a.uk
More informationCS 61BL Midterm 2 Review Session. Chris Gioia, Patrick Lutz, Ralph Arroyo, Sarah Kim
CS 61BL Midterm 2 Review Session Chris Gioia, Patrick Lutz, Ralph Arroyo, Sarah Kim Algorithmic Analysis Recall the definitions of: 1. f(n) is in O(g(n)) 2. f(n) is in big Omega of g(n) 3. f(n) is in big
More informationCOL106: Data Structures and Algorithms. Ragesh Jaiswal, IIT Delhi
Stack and Queue How do we implement a Queue using Array? : A collection of nodes with linear ordering defined on them. Each node holds an element and points to the next node in the order. The first node
More informationTotal 100
CS331 SOLUTION Problem # Points 1 10 2 15 3 25 4 20 5 15 6 15 Total 100 1. ssume you are dealing with a ompiler for a Java-like language. For eah of the following errors, irle whih phase would normally
More informationChapter 2: Introduction to Maple V
Chapter 2: Introdution to Maple V 2-1 Working with Maple Worksheets Try It! (p. 15) Start a Maple session with an empty worksheet. The name of the worksheet should be Untitled (1). Use one of the standard
More information3137 Data Structures and Algorithms in C++
3137 Data Structures and Algorithms in C++ Lecture 3 July 12 2006 Shlomo Hershkop 1 Announcements Homework 2 out tonight Please make sure you complete hw1 asap if you have issues, please contact me will
More informationLecture 7: Implementing Lists, Version 2
CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 7: Implementing Lists, Version 2 Contents 1 The Impact of addfirst on Lists 1 2 Mutating List Contents 2 2.1 The Basic List Classes...................................
More information1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam
1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Exam Name: Email Address: TA: Section: You have three hours to complete this exam. For coding questions, you do not need to include
More informationLinked List Nodes (reminder)
Outline linked lists reminders: nodes, implementation, invariants circular linked list doubly-linked lists iterators the Java foreach statement iterator implementation the ListIterator interface Linked
More information1 The Knuth-Morris-Pratt Algorithm
5-45/65: Design & Analysis of Algorithms September 26, 26 Leture #9: String Mathing last hanged: September 26, 27 There s an entire field dediated to solving problems on strings. The book Algorithms on
More informationInterconnection Styles
Interonnetion tyles oftware Design Following the Export (erver) tyle 2 M1 M4 M5 4 M3 M6 1 3 oftware Design Following the Export (Client) tyle e 2 e M1 M4 M5 4 M3 M6 1 e 3 oftware Design Following the Export
More informationDepartment of Electrical and Computer Engineering University of Wisconsin Madison. Fall
Department of Eletrial and Computer Engineering University of Wisonsin Madison ECE 553: Testing and Testable Design of Digital Systems Fall 2014-2015 Assignment #2 Date Tuesday, September 25, 2014 Due
More informationLast time s big ideas
Last time s big ideas 1. When we want an array of objects, we store their references in the array 2. It is important to distinguish between the specification and implementation of a class 3. public and
More informationPriority Queues and Huffman Encoding
Priority Queues and Huffman Encoding Introduction to Homework 7 Hunter Schafer Paul G. Allen School of Computer Science - CSE 143 I Think You Have Some Priority Issues ER Scheduling. How do we efficiently
More informationLinked List. ape hen dog cat fox. tail. head. count 5
Linked Lists Linked List L tail head count 5 ape hen dog cat fox Collection of nodes with a linear ordering Has pointers to the beginning and end nodes Each node points to the next node Final node points
More informationPrinciples 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 informationCSE 143, Winter 2009 Final Exam Thursday, March 19, 2009
CSE 143, Winter 2009 Final Exam Thursday, March 19, 2009 Personal Information: Name: Section: Student ID #: TA: You have 110 minutes to complete this exam. You may receive a deduction if you keep working
More informationTe Whare Wananga o te Upoko o te Ika a Maui EXAMINATIONS 2003 END-YEAR COMP 103. Data Structures and Algorithms
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui EXAMINATIONS 2003 END-YEAR Data Structures and Algorithms Time Allowed: 3 Hours Instructions: There are a total of 180 marks
More informationDM550 / 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 informationProgramming 2. Topic 8: Linked Lists, Basic Searching and Sorting
RMIT School of Computer Science and Information Technology Programming 2 Topic 8: Linked Lists, Basic Searching and Sorting Lecture Slides COPYRIGHT 2008 RMIT University. Original content by: Peter Tilmanis,
More informationPriority Queues and Huffman Encoding
Priority Queues and Huffman Encoding Introduction to Homework 7 Hunter Schafer Paul G. Allen School of Computer Science - CSE 143 I Think You Have Some Priority Issues ER Scheduling. How do we efficiently
More informationCSE 143 Au03 Final Exam Page 1 of 15
CSE 143 Au03 Final Exam Page 1 of 15 Reference information about many standard Java classes appears at the end of the test. You might want to tear off those pages to make them easier to refer to while
More informationCSE 143: Computer Programming II Summer 2015 HW6: 20 Questions (due Thursday, August 13, :30pm)
CSE 143: Computer Programming II Summer 2015 HW6: 20 Questions (due Thursday, August 13, 2015 11:30pm) This assignment focuses on binary trees and recursion. Turn in the following files using the link
More information