CS Prelim Review – 10/15/09  First prelim is TOMORROW at 7:30 PM  Review session – Tonight 7:30 PM, Phillips 101  Things you should do:  Review every.

Slides:



Advertisements
Similar presentations
Chapter 12 Binary Search Trees
Advertisements

Comp 122, Spring 2004 Binary Search Trees. btrees - 2 Comp 122, Spring 2004 Binary Trees  Recursive definition 1.An empty tree is a binary tree 2.A node.
Binary Trees Chapter 6. Linked Lists Suck By now you realize that the title to this slide is true… By now you realize that the title to this slide is.
Computer Science C++ High School Level By Guillermo Moreno.
Main Index Contents 11 Main Index Contents Week 6 – Binary Trees.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
CS 171: Introduction to Computer Science II
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
CS 206 Introduction to Computer Science II 09 / 22 / 2008 Instructor: Michael Eckmann.
Lec 15 April 9 Topics: l binary Trees l expression trees Binary Search Trees (Chapter 5 of text)
1.1 Data Structure and Algorithm Lecture 12 Binary Search Trees Topics Reference: Introduction to Algorithm by Cormen Chapter 13: Binary Search Trees.
CS 261 – Winter 2010 Trees. Ubiquitous – they are everywhere in CS Probably ranks third among the most used data structure: 1.Vectors and Arrays 2.Lists.
Trees Weiss sec (preview) ch. 18 (sort of).
CHAPTER 12 Trees. 2 Tree Definition A tree is a non-linear structure, consisting of nodes and links Links: The links are represented by ordered pairs.
CSC 2300 Data Structures & Algorithms February 6, 2007 Chapter 4. Trees.
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
Lecture Objectives  To learn how to use a tree to represent a hierarchical organization of information  To learn how to use recursion to process trees.
CS Data Structures Chapter 15 Trees Mehmet H Gunes
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
CMSC 341 Introduction to Trees. 8/3/2007 UMBC CMSC 341 TreeIntro 2 Tree ADT Tree definition  A tree is a set of nodes which may be empty  If not empty,
Tree (new ADT) Terminology:  A tree is a collection of elements (nodes)  Each node may have 0 or more successors (called children)  How many does a.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
TREES Lecture 12 CS2110 – Fall Announcements  Prelim #1 is tonight!  Olin 155  A-L  5:30  M-Z  5:30  A4 will be posted today  Mid-semester.
Compiled by: Dr. Mohammad Omar Alhawarat
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
TREES. What is a tree ? An Abstract Data Type which emulates a tree structure with a set of linked nodes The nodes within a tree are organized in a hierarchical.
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Grammars and Parsing  Recursive Definitions of Properties.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
Trees By P.Naga Srinivasu M.tech,(MBA). Basic Tree Concepts A tree consists of finite set of elements, called nodes, and a finite set of directed lines.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
CMSC 341 Introduction to Trees. 2/21/20062 Tree ADT Tree definition –A tree is a set of nodes which may be empty –If not empty, then there is a distinguished.
CISC 235 Topic 3 General Trees, Binary Trees, Binary Search Trees.
Binary Tree. Some Terminologies Short review on binary tree Tree traversals Binary Search Tree (BST)‏ Questions.
Rooted Tree a b d ef i j g h c k root parent node (self) child descendent leaf (no children) e, i, k, g, h are leaves internal node (not a leaf) sibling.
TREES K. Birman’s and G. Bebis’s Slides. Tree Overview 2  Tree: recursive data structure (similar to list)  Each cell may have zero or more successors.
Binary Search Trees.  Understand tree terminology  Understand and implement tree traversals  Define the binary search tree property  Implement binary.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
TREES General trees Binary trees Binary search trees AVL trees Balanced and Threaded trees.
TREES Lecture 11 CS2110 – Spring Readings and Homework  Textbook, Chapter 23, 24  Homework: A thought problem (draw pictures!)  Suppose you use.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Trees CSIT 402 Data Structures II 1. 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical.
18-1 Chapter 18 Binary Trees Data Structures and Design in Java © Rick Mercer.
Question 4 Tutorial 8. Part A Insert 20, 10, 15, 5,7, 30, 25, 18, 37, 12 and 40 in sequence into an empty binary tree
1 CMSC 341 Introduction to Trees Textbook sections:
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
DS.T.1 Trees Chapter 4 Overview Tree Concepts Traversals Binary Trees Binary Search Trees AVL Trees Splay Trees B-Trees.
TREES From root to leaf. Trees  A tree is a non-linear collection  The elements are in a hierarchical arrangement  The elements are not accessible.
CSE 373 Data Structures Lecture 7
Binary Trees Linked lists: efficient insertion/deletion, inefficient search ArrayList: search can be efficient, insertion/deletion not Binary trees: efficient.
Binary Trees Linked lists: efficient insertion/deletion, inefficient search ArrayList: search can be efficient, insertion/deletion not Binary trees: efficient.
Week 6 - Wednesday CS221.
Trees Lecture 12 CS2110 – Fall 2017.
Tree.
Trees Lecture 12 CS2110 – Fall 2016.
Trees.
ITEC 2620M Introduction to Data Structures
Binary Trees, Binary Search Trees
Trees Lecture 9 CS2110 – Fall 2009.
Binary Trees, Binary Search Trees
Announcements Prelim 1 on Tuesday! A4 will be posted today
Chapter 20: Binary Trees.
Trees.
Binary Trees, Binary Search Trees
Trees Lecture 10 CS2110 – Spring 2013.
Presentation transcript:

CS Prelim Review – 10/15/09  First prelim is TOMORROW at 7:30 PM  Review session – Tonight 7:30 PM, Phillips 101  Things you should do:  Review every practice prelim #1  Review practice finals (ignore questions that cover topics you haven’t learned yet)  Review quizzes  Review lecture slides

Types  Primitive types  int, double, boolean, char, long, short, float, byte  compare with ==  Reference types  Everything else – anything that is an object type  String, HashMap, Integer  Arrays are reference types  compare with.equals

Inheritance  Subclasses inherit fields + methods of superclass  Overriding – subclass contains the same method as superclass (same name, parameters, static/not)  Shadowing – subclass contains the same field (instance variable) as superclass (this is BAD)  Casting – upcasting is always type-safe and OK  Downcasting is bad – sometimes doesn’t work (hard to predict)  For inheritance, types, see ScopeTester.java

Interfaces  Outline of a class  Methods in an interface must be implemented in any class that implements that interface  For example: Interface Iterable  If another programmer looks at your class and sees you implemented Iterable, they know for a fact that they can iterate through an object of your class = useful!  One interface can be implemented by many classes; one class can implement many interfaces

Static vs dynamic types  B var = new C();  Static type = B  Static type is used when calling fields; i.e. var.x will call the field x in class B  NEVER CHANGES  Dynamic type = C  Used when calling methods; i.e. var.hello() will call the method hello() in C  Changed by: var = new B();  Now, the dynamic type is B  Casting: var = (B) var – does not change any type

Recursion  Calling a method from within itself  Must have one or more base cases and a recursive case  You don’t need to know induction for Prelim 1  If a problem asks you to write a recursive method, you must call that method within itself  You should know how to run through a recursive method and figure out its output  See Recursion.java

Parsing  Understand grammars and how they are called recursively, e.g.  S -> kS | mS | bB  B -> b | c | d | B | C  C -> cC | c  Understand parse trees, e.g. arithmetic operations  Show the two types of parse trees on the board

Lists  Sequence of elements  Each element points to the next element in the list  Doubly linked lists – element points to the previous element in the list  Circular linked lists – last element points to the first element  See code – List.java, Node.java, ListTester.java  There are more List implementations on the website

Tree Overview 9  Tree: recursive data structure (similar to list)  Each cell may have zero or more successors (children)  Each cell has exactly one predecessor (parent) except the root, which has none  All cells are reachable from root  Binary tree: tree in which each cell can have at most two children: a left child and a right child General tree Binary tree Not a tree List-like tree

Tree Terminology 10  M is the root of this tree  G is the root of the left subtree of M  B, H, J, N, and S are leaves  N is the left child of P; S is the right child  P is the parent of N  M and G are ancestors of D  P, N, and S are descendants of W  Node J is at depth 2 (i.e., depth = length of path from root = number of edges)  Node W is at height 2 (i.e., height = length of longest path to a leaf)  A collection of several trees is called a...? MGWPJD NHBS

Things to know about trees  Know how to traverse (in-order, pre-order, post- order)  Know how to write methods for a tree (including binary search trees) – insert, delete, contains  Base cases – empty tree or leaf node  Recursive cases – Call method on left and right subtrees (or on the correct subtree, for example contains on a BST)  These methods are all in the lecture slides

Useful Facts about Binary Trees 12  2 d = maximum number of nodes at depth d  If height of tree is h  Minimum number of nodes in tree = h + 1  Maximum number of nodes in tree = … + 2 h = 2 h+1 – 1  Complete binary tree  All levels of tree down to a certain depth are completely filled depth Height 2, minimum number of nodes Height 2, maximum number of nodes

Traversals  Given the following tree, calculate the pre-order, in- order, and post-order traversals MGWPJDNHBS

GUIs  Understand how to write GUIs, such as creating frames, panels, buttons  Understand how events (e.g. ActionListener) work – given code for an ActionListener, what does pressing a button do?  Review the lecture notes – this is mainly straight memorization and a little problem solving  GUIs are tricky to write (they don’t behave the same on all PCs) but not difficult to understand

Questions?  Prelim is tomorrow 7:30 PM  Review session 7:30 PM in Phillips 101  Things you should do:  Review every practice prelim #1 Especially T/F – these can make or break your score  Review practice finals (ignore questions that cover topics you haven’t learned yet)  Review quizzes  Review lecture slides  Review this powerpoint and attached code