Upcoming ACM Events Linux Crash Course Date: Time: Location: Weekly Crack the Coding Interview Date:

Similar documents
Section 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

Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College!

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

TREES. Trees - Introduction

Lecture Notes 16 - Trees CSS 501 Data Structures and Object-Oriented Programming Professor Clark F. Olson

Binary Trees, Binary Search Trees

Trees. (Trees) Data Structures and Programming Spring / 28

Chapter 10: Trees. A tree is a connected simple undirected graph with no simple circuits.

Data Structures and Algorithms for Engineers

Chapter 4 Trees. Theorem A graph G has a spanning tree if and only if G is connected.

CSI33 Data Structures

March 20/2003 Jayakanth Srinivasan,

Garbage Collection: recycling unused memory

Trees. CSE 373 Data Structures

Chapter 20: Binary Trees

Binary Trees and Binary Search Trees

Why Do We Need Trees?

Introduction to Computers and Programming. Concept Question

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

Data Structures. Trees. By Dr. Mohammad Ali H. Eljinini. M.A. Eljinini, PhD

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

Section Summary. Introduction to Trees Rooted Trees Trees as Models Properties of Trees

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang)

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

Stacks, Queues and Hierarchical Collections

F453 Module 7: Programming Techniques. 7.2: Methods for defining syntax

Binary Trees

CS302 - Data Structures using C++

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Friday, March 30. Last time we were talking about traversal of a rooted ordered tree, having defined preorder traversal. We will continue from there.

Lecture 2. Binary Trees & Implementations. Yusuf Pisan

MIDTERM Preparation. CSS 343: Data Structures Algorithms, and Discrete Math II

IX. Binary Trees (Chapter 10)

CS61B Lecture #20: Trees. Last modified: Mon Oct 8 21:21: CS61B: Lecture #20 1

12 Abstract Data Types

Chapter Summary. Introduction to Trees Applications of Trees Tree Traversal Spanning Trees Minimum Spanning Trees

Topic Binary Trees (Non-Linear Data Structures)

CSI33 Data Structures

CE 221 Data Structures and Algorithms

IX. Binary Trees (Chapter 10) Linear search can be used for lists stored in an array as well as for linked lists. (It's the method used in the find

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

Trees. Trees. CSE 2011 Winter 2007

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

A set of nodes (or vertices) with a single starting point

Trees, Binary Trees, and Binary Search Trees

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

CS301 - Data Structures Glossary By

LECTURE 13 BINARY TREES

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

Algorithms and Data Structures (INF1) Lecture 8/15 Hua Lu

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

Trees. T.U. Cluj-Napoca -DSA Lecture 2 - M. Joldos 1

An undirected graph is a tree if and only of there is a unique simple path between any 2 of its vertices.

13 BINARY TREES DATA STRUCTURES AND ALGORITHMS INORDER, PREORDER, POSTORDER TRAVERSALS

Analysis of Algorithms

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

Binary search trees. Binary search trees are data structures based on binary trees that support operations on dynamic sets.

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

Binary search trees 3. Binary search trees. Binary search trees 2. Reading: Cormen et al, Sections 12.1 to 12.3

Todays Lecture. Assignment 2 deadline: You have 5 Calendar days to complete.

Postfix (and prefix) notation

CSE 373 APRIL 17 TH TREE BALANCE AND AVL

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

Chapter Contents. Trees. Tree Concepts. Hierarchical Organization. Hierarchical Organization. Hierarchical Organization.

COMP 250 Fall binary trees Oct. 27, 2017

Topic 14. The BinaryTree ADT

Binary Trees. Height 1

CSCI2100B Data Structures Trees

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

INF2220: algorithms and data structures Series 1

TREES Lecture 10 CS2110 Spring2014

6-TREE. Tree: Directed Tree: A directed tree is an acyclic digraph which has one node called the root node

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

An Introduction to Trees

Lecture: Analysis of Algorithms (CS )

INF2220: algorithms and data structures Series 1

CISC 235 Topic 3. General Trees, Binary Trees, Binary Search Trees

Associate Professor Dr. Raed Ibraheem Hamed

There are many other applications like constructing the expression tree from the postorder expression. I leave you with an idea as how to do it.

Discussion 2C Notes (Week 8, February 25) TA: Brian Choi Section Webpage:

CMSC th Lecture: Graph Theory: Trees.

BBM 201 Data structures

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

4. Trees. 4.1 Preliminaries. 4.2 Binary trees. 4.3 Binary search trees. 4.4 AVL trees. 4.5 Splay trees. 4.6 B-trees. 4. Trees

Trees. Tree Structure Binary Tree Tree Traversals

Design and Analysis of Algorithms Lecture- 9: Binary Search Trees


tree nonlinear Examples

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Introduction to Binary Trees

3137 Data Structures and Algorithms in C++

Transcription:

Upcoming ACM Events Linux Crash Course Date: Oct. 2nd and 3rd Time: 1:15 pm - 3:15 pm Location: UW1-210 (10/02) and UW1-221 (10/03) Weekly Crack the Coding Interview Date: Weekly Fridays from Oct. 5th - Nov. 16th Time: 11:00 am - 1:00 pm Location: DISC-162 Weekly IOT Crash Course Date: Weekly Fridays from Oct. 5th - Nov. 9th Time: 1:30 pm - 3:30 pm Location: Makerspace Professional Development Workshops Date: Oct. 8th, Oct. 11th, and Oct. 12th Time: 6:00 pm - 8:00 pm Location: UW1-061 1

CSS 343 Data Structures, Algorithms, and Discrete Math II Lecture 1 Introduction Yusuf Pisan

Overview 1. Course Structure http://courses.washington.edu/css343/pisan/ 2. 342 Review 3. Trees 4. Huffman Encoding 5. Arithmetic Expression Trees 6. Assignment-1 3

4

342 Review 1. C++ classes, overloaded operators 2. Pointers & References 3. Array and link-based ADT implementations 4. Templates - for classes and functions 5. Recursion 6. Mathematical induction 7. Boolean algebra 8. Stack 9. List 10. Queue 11. Algorithm complexity - O(1), O(n), O(n log n),... 12. Trees - Binary trees, Binary Search Trees 5

Complexity? int foo(int n) { if (n == 0) return 1; else return n * foo(n - 1); } int mystery(const int anarray[], int first, int last, int target) { int index; if (first > last) index = - 1; else { int mid = first + (last - first) / 2; if (target == anarray[mid]) index = mid; else if (target < anarray[mid]) index = mystery(anarray, first, mid - 1, target); else index = mystery(anarray, mid + 1, last, target); } return index; } template<class ItemType> bool Grouch<ItemType>::mumble(const ItemType& newentry) { Node<ItemType>* nextnodeptr = new Node<ItemType>(); nextnodeptr->setitem(newentry); nextnodeptr->setnext( headptr); headptr = nextnodeptr; itemcount++; return true; } 6

Trees Single root, hierarchical - more than one immediate successor nodes, edges, leaves child, parent, sibling, ancestor, descendant subtree general, n-ary, binary tree height (root at level 1, empty tree has height 0) perfect or full - all nodes (except leaves) have 2 children, all leaves at same level complete - every level except last is filled AND the nodes at last level are as left as possible balanced - the height of the subtrees do not differ more than one degenerate - all nodes have 1 child 7

Why Trees? Good for searching when there is both add/delete operations. Used internally for libraries Games use Binary Space Partition, render only what is visible from front to back Radix Trees for IP routing Huffman Coding Tree for compression GGM Trees for generating random numbers Merkle Tree for cryptography Syntax Tree for parsing languages B-Tree for databases Directory structures, web pages, anything hierarchical 8

Binary Tree Traversal Visit all the nodes Preorder - root, left subtree, right subtree 1, 2, 4, 5, 3, 6, 7 Inorder - left subtree, root, right subtree 4, 2, 5, 1, 6, 3, 7 Postorder - left subtree, right subtree, root 4, 5, 2, 6, 7, 3, 1 9

Trees Exercise 1. What is the minimum height of a binary tree given the number of nodes: 0, 1, 2, 3, 4, 7, 8, 16, 32, 128, 1024? 2. What is the maximum height of a binary tree given the number of nodes above? 3. Preorder, Inorder, Postorder traversal for the tree given 4. Is the given tree full, complete, balanced, degenerate or neither? 5. Draw a binary tree that is a. full b. complete, but not full c. balanced, but not complete d. degenerate 10

Compression How do we compress a text file? Uncompressed file: 8 bits per character x Number of Characters A - 65-0100 0001 B - 66-0100 0010... Z - 90-0101 0000... a - 97-0110 0001 Characters are repeated, some are more frequent than others Words, sentences and paragraphs are repeated 11

Huffman Encoding Prefix codes - the bit string for a letter never occurs as the first part of the bit string for another letter 1. Each letter is a tree with a weight as its frequency 2. Combine the trees with the lowest weight, creating a tree with a higher weight 3. Repeat step-2 until we get a single tree 4. Label left edges with "0", right edges with "1" to get the encoding for each letter gzip uses LZ77 and Huffman coding, lots of details at http://www.infinitepartitions.com/art001.html and https://stackoverflow.com/questions/20762094/how-are-zlib-gzip-and-zip-related-what-do-they-have-in-com mon-and-how-are-they 12

Final encoding A: 111 B: 110 C: 011 D: 010 E: 10 F: 00 Decode these 111 110111010 110101000 00111010 The average number of bits used to encode a symbol using this encoding is 3 * 0.08 + 3 * 0.10 + 3 * 0.12 + 3 * 0.15 + 2 * 0.20 + 2 * 0.35 = 2.45. 13

Huffman Exercise 1. Use Huffman coding to encode these symbols with given frequencies and the average number of bits required to encode a character 1.1. a: 0.20, b: 0.10, c: 0.15, d: 0.25, e: 0.30. 1.2. A: 0.10, B: 0.25, C: 0.05, D: 0.15, E: 0.30, F: 0.07, G: 0.08. 2. Construct two different Huffman codes for these symbols and frequencies: t : 0.2, u: 0.3, v: 0.2, w: 0.3. 3. Use Huffman coding to encode these symbols with frequencies a: 0.4, b: 0.2, c: 0.2, d: 0.1, e: 0.1 in two different ways by breaking ties in the algorithm differently. 3.1. Select two trees with the largest number of vertices 3.2. Select two trees with the smallest number of vertices 14

Arithmetic Expression as Trees Inorder traversal gives infix form: ((x + y) 2) + ((x 4)/3 but needs parenthesis Preorder traversal gives prefix or polish notation: + + x y 2 / x 4 3 easy to parse, evaluate right to left when operator found, apply it to the operands and substitute result see https://en.wikipedia.org/wiki/polish_notation for example 15

Exercise: Arithmetic Expressions 1. Evaluate prefix expression + 2 3 5/ 2 3 4? 2. Postorder gives us postfix (reverse polish notation). What is the postfix form of ((x + y) 2) + ((x 4)/3)? 3. What is the value of the postfix expression 7 2 3 4 9 3/+ Evaluate it from left-to-right 4. Draw the corresponding trees a. + + 5 3 2 1 4 b. + 2 3 5 1 c. / 9 3 + 2 4 7 6 16

Assignment-1 17

Read Chapter-15: Trees Before Next Class Complete Canvas Quiz on Chapter-15 Implement constructors, operator<<, operator== and operator!= Write test cases Test your program on CSS Linux Lab Use valgrind to check for memory leaks Review lecture notes 18