Data Structures (INE2011)

Similar documents
MA 513: Data Structures Lecture Note Partha Sarathi Mandal

Algorithms & Data Structures Homework 8 HS 18 Exercise Class (Room & TA): Submitted by: Peer Feedback by: Points:

CS 360 Exam 2 Fall 2014 Name

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution

Lecture 3. XML Into RDBMS. XML and Databases. Memory Representations. Memory Representations. Traversals and Pre/Post-Encoding. Memory Representations

NON-DETERMINISTIC FSA

CISC 320 Introduction to Algorithms Spring 2014

Welcome. Balanced search trees. Balanced Search Trees. Inge Li Gørtz

6. Suppose lim = constant> 0. Which of the following does not hold?

These slides are from 2014 and contain a semi-serious error at one point in the

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of:

Data Structures (Classroom Practice Booklet Solutions)

Intermediate Math Circles Wednesday 17 October 2012 Geometry II: Side Lengths

Discrete Structures Lecture 11

CIT 596 Theory of Computation 1. Graphs and Digraphs

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4.

Suffix Trays and Suffix Trists: Structures for Faster Text Indexing

Discrete Structures, Test 2 Monday, March 28, 2016 SOLUTIONS, VERSION α

AVL Trees. D Oisín Kidney. August 2, 2018

Advanced Implementations of Tables: Balanced Search Trees and Hashing

Solutions for HW9. Bipartite: put the red vertices in V 1 and the black in V 2. Not bipartite!

Section 1.3 Triangles

Ch. 2.3 Counting Sample Points. Cardinality of a Set

Alignment of Long Sequences. BMI/CS Spring 2016 Anthony Gitter

Computational Biology Lecture 18: Genome rearrangements, finding maximal matches Saad Mneimneh

Necessary and sucient conditions for some two. Abstract. Further we show that the necessary conditions for the existence of an OD(44 s 1 s 2 )

CS 2204 DIGITAL LOGIC & STATE MACHINE DESIGN SPRING 2014

Finite State Automata and Determinisation

Lecture 3 ( ) (translated and slightly adapted from lecture notes by Martin Klazar)

XML and Databases. Exam Preperation Discuss Answers to last year s exam. Sebastian Maneth NICTA and UNSW

Pre-Lie algebras, rooted trees and related algebraic structures

Nondeterministic Finite Automata

Arrow s Impossibility Theorem

, g. Exercise 1. Generator polynomials of a convolutional code, given in binary form, are g. Solution 1.

A Differential Approach to Inference in Bayesian Networks

Algorithm Design and Analysis

Unit 4. Combinational Circuits

Common intervals of genomes. Mathieu Raffinot CNRS LIAFA

Nondeterminism and Nodeterministic Automata

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Activities. 4.1 Pythagoras' Theorem 4.2 Spirals 4.3 Clinometers 4.4 Radar 4.5 Posting Parcels 4.6 Interlocking Pipes 4.7 Sine Rule Notes and Solutions

Lecture Notes No. 10

Connected-components. Summary of lecture 9. Algorithms and Data Structures Disjoint sets. Example: connected components in graphs

KENDRIYA VIDYALAYA IIT KANPUR HOME ASSIGNMENTS FOR SUMMER VACATIONS CLASS - XII MATHEMATICS (Relations and Functions & Binary Operations)

= state, a = reading and q j

Regular languages refresher

COMP 250. Lecture 20. tree traversal. Oct. 25/26, 2017

Linear Algebra Introduction

Algorithm Design and Analysis

UNIT 3 Indices and Standard Form Activities

M A T H F A L L CORRECTION. Algebra I 2 1 / 0 9 / U N I V E R S I T Y O F T O R O N T O

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

THE STERN-BROCOT TREE

In Linear Time from Regular Expressions to NFAs

where the box contains a finite number of gates from the given collection. Examples of gates that are commonly used are the following: a b

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

Lecture 11 Binary Decision Diagrams (BDDs)

Identifying and Classifying 2-D Shapes

Boolean Algebra cont. The digital abstraction

Foundations of Computer Science Comp109

Outline. Binary Tree

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

Global alignment. Genome Rearrangements Finding preserved genes. Lecture 18

Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Bayesian Networks: Approximate Inference

Probability. b a b. a b 32.

Balanced binary search trees

Alpha Algorithm: A Process Discovery Algorithm

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

Binary Search Trees. Lecture 29 Section Robb T. Koether. Hampden-Sydney College. Fri, Apr 8, 2016

(e) if x = y + z and a divides any two of the integers x, y, or z, then a divides the remaining integer

Chapter 5 Plan-Space Planning

@#? Text Search ] { "!" Nondeterministic Finite Automata. Transformation NFA to DFA and Simulation of NFA. Text Search Using Automata

THE PYTHAGOREAN THEOREM

Functions. mjarrar Watch this lecture and download the slides

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

Java II Finite Automata I

Section 3.2 Recursively Defined Functions and Procedures

Project 3: Using Identities to Rewrite Expressions

Lecture 6: Coding theory

Sequence Analysis, WS 14/15, D. Huson & R. Neher (this part by D. Huson & J. Fischer) January 21,

Parse trees, ambiguity, and Chomsky normal form

Hardware Verification 2IMF20

CS 491G Combinatorial Optimization Lecture Notes

Geometric Sequences. Geometric Sequence a sequence whose consecutive terms have a common ratio.

DATABASE DESIGN I - 1DL300

Can one hear the shape of a drum?

Graph Theory. Simple Graph G = (V, E). V={a,b,c,d,e,f,g,h,k} E={(a,b),(a,g),( a,h),(a,k),(b,c),(b,k),...,(h,k)}

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

Farey Fractions. Rickard Fernström. U.U.D.M. Project Report 2017:24. Department of Mathematics Uppsala University

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

On-Line Construction. of Suffix Trees. Overview. Suffix Trees. Notations. goo. Suffix tries

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

Chapter 4 State-Space Planning

BİL 354 Veritabanı Sistemleri. Relational Algebra (İlişkisel Cebir)

Surds and Indices. Surds and Indices. Curriculum Ready ACMNA: 233,

INF1383 -Bancos de Dados

Transcription:

Dt Strutures (INE2011) Eletronis nd Communition Engineering Hnyng University Hewoon Nm Leture 7 INE2011 Dt Strutures 1

Binry Tree Trversl Mny inry tree opertions re done y perorming trversl o the inry tree. In trversl, eh element o the inry tree is visited extly one. Binry tree trversl methods Pre-order In-order Post-order Level order INE2011 Dt Strutures 2

Binry Tree Trversl Trversing eh node nd sutree L : moving let V : visit R : moving right Six possile omintions o trversl LVR, LRV, VLR, VRL, RVL, RLV Trverse let eore right VLR : pre-order LVR : in-order LRV : post-order INE2011 Dt Strutures 3

Binry Tree Trversl Pre-order exmple d e g h i d g h e i INE2011 Dt Strutures 4

Binry Tree Trversl In-order exmple d e g h i g d h e i INE2011 Dt Strutures 5

Binry Tree Trversl Post-order exmple d e g h i g h d i e INE2011 Dt Strutures 6

Binry Tree Trversl Pre-order, in-order, post-order void PreOrder(TreeNode *t) { i (t!= NULL) { Visit(t); PreOrder(t->letChild); PreOrder(t->rightChild); } } void InOrder(TreeNode *t) { i (t!= NULL) { InOrder(t->letChild); Visit(t); InOrder(t->rightChild); } } void PostOrder(TreeNode *t) { i (t!= NULL) { PostOrder(t->letChild); PostOrder(t->rightChild); Visit(t); } } INE2011 Dt Strutures 7

Binry Tree Trversl Level order exmple d e g h i d e g h i INE2011 Dt Strutures 8

Threded Binry Trees Threds Mny null pointers in inry tree Reple null pointers with the in-order predeessor or the inorder suessor d e d e g h i g h i g d h e i INE2011 Dt Strutures 9

Threded Binry Trees Clss or threded node lss treenode { privte: dt int dt; let hild treenode *let; ool letthred; treenode *right; ool rightthred; right hild letthred rightthred d e }; g h i - I letthred is true, *let ontins thred, otherwise pointer. - Sme or rightthred. g d h e i INE2011 Dt Strutures 10

Binry Tree Constrution Cn you onstrut the inry tree rom given trversl sequene? When trversl sequene hs more thn one element, the inry tree is not uniquely deined Thereore, the tree rom whih the sequene ws otined nnot e reonstruted uniquely Pre-order = Cn you onstrut the inry tree, given two trversl sequenes? INE2011 Dt Strutures 11

Binry Tree Constrution Pre-order = In-order = d g h e i g d h e i Sn the pre-order let to right using the in-order to seprte let nd right sutrees Step 1 is the root o the tree. gdhei re in the let sutree. re in the right sutree. g d h e i INE2011 Dt Strutures 12

Binry Tree Constrution Pre-order = In-order = d g h e i g d h e i Step 2 is the next root o the tree. gdh re in the let sutree. ei re in the right sutree. g d h e i INE2011 Dt Strutures 13

Binry Tree Constrution Pre-order = In-order = d g h e i g d h e i Step 3 d is the next root o the tree. g is in the let sutree. h is in the right sutree. d e i g h INE2011 Dt Strutures 14

Binry Tree Constrution Pre-order = In-order = d g h e i g d h e i Step 4 e is the next root o the tree. i is in the right sutree. d e g h i INE2011 Dt Strutures 15

Binry Tree Constrution Pre-order = In-order = d g h e i g d h e i Step 5 is the next root o the tree. is in the let sutree. d e g h i INE2011 Dt Strutures 16

Binry Tree Constrution Pre-order = In-order = d g h e i g d h e i Step 6 is the next root o the tree. is in the right sutree. d e g h i INE2011 Dt Strutures 17

Binry Tree Constrution Post-order = g h d i e In-order = g d h e i Sn the pre-order let to right using the in-order to seprte let nd right sutrees Step 1 is the root o the tree. gdhei re in the let sutree. re in the right sutree. g d h e i Step 2 6 Similr to the previous exmple with pre-order nd in-order INE2011 Dt Strutures 18

Binry Tree Constrution Level order = In-order = d e g h i g d h e i Sn the pre-order let to right using the in-order to seprte let nd right sutrees Step 1 is the root o the tree. gdhei re in the let sutree. re in the right sutree. g d h e i Step 2 6 Similr to the previous exmple with pre-order nd in-order INE2011 Dt Strutures 19

Joining nd Splitting Binry Tree Joining(Grting) nd Splitting(Pruning) Grting s Pruning p q e s e p q INE2011 Dt Strutures

Binry Serh Tree Ditionry opertions IsEmpty( ) Get(key) Insert(key, vlue) Delete(key) Treenode Eh node hs (key, vlue) pir 10 8 12 d e 15 17 20 INE2011 Dt Strutures lss treenode { privte: int key; hr vlue; treenode *let; treenode *right; }; 5 9 13 g h i 19 21

Binry Serh Tree Asend( ) Do n in-order trversl 15 10 20 8 12 d e 17 5 9 13 g h i 19 g d h e i INE2011 Dt Strutures 22

Binry Serh Tree Get(key) Serh the node with the key (input) Return the vlue o the node 15 Get(12) returns e 10 8 12 d e 5 9 13 g h i 17 20 19 INE2011 Dt Strutures 23

Binry Serh Tree Insert(key, vlue) Insert node t proper position sed on the key (input) 15 Insert(23, k) 10 8 12 d e 5 9 13 g h i 17 20 19 23 k INE2011 Dt Strutures 24

Binry Serh Tree Delete(key) No element with the delete key Element is in le Element is in degree 1 node Element is in degree 2 node INE2011 Dt Strutures 25

Binry Serh Tree Delete(key) Element is in le 15 Delete(9) 10 20 8 12 d e 17 5 9 13 g h i 19 INE2011 Dt Strutures 26

Binry Serh Tree Delete(key) Element is in degree 1 node 15 Delete(20) 10 20 8 12 d e 17 5 9 13 g h i 19 INE2011 Dt Strutures 27

Binry Serh Tree Delete(key) Element is in degree 1 node 15 Delete(12) 10 20 8 12 d e 17 5 9 13 g h i 19 INE2011 Dt Strutures 28

Binry Serh Tree Delete(key) Element is in degree 2 node Exmple 1 15 Delete(10) 10 20 Find the lrgest key in the let sutree Or the smllest key in the right sutree 7 12 d e 17 5 9 13 g h i 8 m 19 INE2011 Dt Strutures 29

Binry Serh Tree Delete(key) Element is in degree 2 node Exmple 1 15 Delete(10) 10 20 Find the lrgest key in the let sutree Or the smllest key in the right sutree 7 12 d e 17 5 9 13 g h i 8 m 19 INE2011 Dt Strutures 30

Binry Serh Tree Delete(key) Element is in degree 2 node Exmple 1 15 Delete(10) 9 h 20 7 12 d e 17 5 g 8 m 13 i 19 INE2011 Dt Strutures 31

Binry Serh Tree Delete(key) Element is in degree 2 node Exmple 2 15 Delete(15) 10 20 7 12 d e 17 5 9 13 g h i 19 INE2011 Dt Strutures 8 m 32

Binry Serh Tree Delete(key) Element is in degree 2 node Exmple 2 15 Delete(15) 10 20 Find the lrgest key in the let sutree 7 12 d e 17 5 9 13 g h i 19 8 m INE2011 Dt Strutures 33