Queue and Tree in C Yang Zhengwei CSCI2100B Data Structures Tutorial 5 1.

Slides:



Advertisements
Similar presentations
CS Fall 2012, Lab 08 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /17/2015 Tree - Data Structure  Basic.
Advertisements

Lab 1: 1. Download all my programs in your computer under the same folder. 2. The tree shown in the following figure represents an expression: (((( 3 +
1 A full binary tree A full binary tree is a binary tree in which all the leaves are on the same level and every non leaf node has two children. SHAPE.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Advanced Data Structures
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Stacks with Dynamic Memory Class Signature Class Node {public Data data; public Node next; } Class Stack {private Node top; public Stack(); public void.
Fall 2007CS 2251 Iterators and Tree Traversals. Fall 2007CS 2252 Binary Trees In a binary tree, each node has at most two subtrees A set of nodes T is.
Tree Traversal. Traversal Algorithms preorder inorder postorder.
CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Tree Traversal. Traversal Algorithms preorder inorder postorder.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Tree properties and traversals
DS.L.1 Lists, Stacks, and Queues (Review) Chapter 3 Overview Abstract Data Types Linked Lists, Headers, Circular Links Cursor (Array) Implementation Stacks.
1 Chapter 18 Trees Objective To learn general trees and recursion binary trees and recursion tree traversal.
Recursion and Binary Tree ICS 51 – Introductory Computer Organization.
1 Nell Dale Chapter 9 Trees Plus Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data Structures.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
12-CRS-0106 REVISED 8 FEB 2013 CSG2A3 ALGORITMA dan STRUKTUR DATA.
Stacks with Dynamic Memory Class Signature Class Node {public Data data; public Node next; } Class Stack {private Node top; public Stack(); public void.
Trees – Part 2 CS 367 – Introduction to Data Structures.
Binary Trees 2 Overview Trees. Terminology. Traversal of Binary Trees. Expression Trees. Binary Search Trees.
Tree Data Structures.
Lists, Stacks and Queues in C Yang Zhengwei CSCI2100B Data Structures Tutorial 4.
CS-2852 Data Structures LECTURE 11 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Binary Search Trees Data Structures Ananda Gunawardena
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Binary Trees In computer science, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left.
12-CRS-0106 REVISED 8 FEB 2013 CSG2A3 ALGORITMA dan STRUKTUR DATA.
CSE205 Review Session SAMUEL & JESSA. Recursion WHAT IS RECURSION?  Recursion is a tool a programmer can use to invoke a function call on itself. 
Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: Tel 3049.
Tree Implementations Chapter 24 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java,
1 Trees General Trees  Nonrecursive definition: a tree consists of a set of nodes and a set of directed edges that connect pairs of nodes.
Binary Tree Implementation. Binary Search Trees (BST) Nodes in Left subtree has smaller values Nodes in right subtree has bigger values.
COSC 2P03 Week 21 Stacks – review A Last-In First-Out (LIFO) structure Basic Operations: –push : insert data item onto top of stack –pop : remove data.
Data Structures -3 rd exam- 授課教授:李錫智. 1.[10] Suppose we want to implement a queue by using the following List operations: getLength(); remove(position);
1 Trees General Trees  Nonrecursive definition: a tree consists of a set of nodes and a set of directed edges that connect pairs of nodes.
DATA STRUCURES II CSC QUIZ 1. What is Data Structure ? 2. Mention the classifications of data structure giving example of each. 3. Briefly explain.
DS.T.1 Trees Chapter 4 Overview Tree Concepts Traversals Binary Trees Binary Search Trees AVL Trees Splay Trees B-Trees.
Planning & System installation
Lists, Stacks and Queues in C
Chapter 12 – Data Structures
Traversal From CSCE 3110 Data Structures & Algorithm Analysis
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
Fundamentals of Programming II Introduction to Trees
Recursive Objects (Part 4)
12 C Data Structures.
Planning & System installation
Binary and AVL Trees in C
Tree.
Section 8.1 Trees.
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
Trees 7/14/2009.
Principles of Computing – UFCFA3-30-1
Binary Tree Traversals
2018, Fall Pusan National University Ki-Joune Li
Stacks with Dynamic Memory
Trees.
Chapter 20: Binary Trees.
Binary Trees.
Binary and AVL Trees in C Hao Ma
Binary Tree Implementation
Binary Tree Implementation And Applications
Binary Tree Iterators Tree Traversals: preorder, inorder, postorder
Presentation transcript:

Queue and Tree in C Yang Zhengwei CSCI2100B Data Structures Tutorial 5 1

Queue ticket office of the Ocean park? 2

Queue Overview First In First Out (FIFO) Enqueue Dequeue 3

Queue Implementation A queue may be implemented using linked-list or array Implement a queue using array 4

Queue Implementation Implementing a queue using circular array 5

Queue Implementation createQueue 6

Queue Implementation enqueue 7

Queue Implementation dequeue 8

Queue Implementation isEmpty, isFull 9

Queue Implementation front, makeEmpty 10

Binary Tree Overview Binary tree – Degree of tree is 2 11

Trees – traversal (Recursion) Preorder 12

Trees – traversal (Recursion) Inorder 13

Trees – traversal (Recursion) Postorder 14

Trees - traversal Preorder A B D G H E C F I Inorder G D H B E A F I C Postorder G H D E B I F C A 15 A B C D E F I G H

Traversal(non-recursion) INORDER(node) parentStack = empty stack while (not parentStack.isEmpty() or node ≠ null) if (node ≠ null) parenStack.push(node) node = node.left else node = parentStack.pop() visit(node) node = node.right

A B E CD C B A A B E CD B A A B E CD D A A B E CD A A B E CD E A B E CD Output: C Output: Output: C B Output: C B DOutput: C B D A Output: C B D A E

Traversal(non recursion) PREORDER(node) parentStack = empty stack while (not parentStack.isEmpty() or node ≠ null) if (node ≠ null) visit(node) if (node.right ≠ null) parentStack.push(node.right) node = node.left else node = parentStack.pop() Preorder

POSTORDER (node) parentStack = empty stack lastnodevisited = null while (not parentStack.isEmpty() or node ≠ null) if (node ≠ null) parentStack.push(node) node = node.left else peeknode = parentStack.peek() if (peeknode.right ≠ null and lastnodevisited ≠ peeknode.right) /* if right child exists AND traversing node from left child, move right */ node = peeknode.right else visit(peeknode) lastnodevisited = parentStack.pop() Traversal(non recursion) Postorder