Extension of linked list

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Chapter 6 Structures By C. Shing ITEC Dept Radford University.
S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
Leftist Heaps Text Read Weiss, §23.1 (Skew Heaps) Leftist Heap Definition of null path length Definition of leftist heap Building a Leftist Heap Sequence.
CS 171: Introduction to Computer Science II
Fall 2007CS 2251 Trees Chapter 8. Fall 2007CS 2252 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information.
Binary Trees Terminology A graph G = is a collection of nodes and edges. An edge (v 1,v 2 ) is a pair of vertices that are directly connected. A path,
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Lec 15 April 9 Topics: l binary Trees l expression trees Binary Search Trees (Chapter 5 of text)
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Introduction to trees.
Data Structures Using C++1 Chapter 11 Binary Trees.
Advanced Algorithms Analysis and Design Lecture 8 (Continue Lecture 7…..) Elementry Data Structures By Engr Huma Ayub Vine.
Introduction Of Tree. Introduction A tree is a non-linear data structure in which items are arranged in sequence. It is used to represent hierarchical.
COP3530 Data Structures600 Stack Stack is one the most useful ADTs. Like list, it is a collection of data items. Supports “LIFO” (Last In First Out) discipline.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Binary Trees Chapter Definition And Application Of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 5 Prepared by İnanç TAHRALI.
Binary Trees 2 Overview Trees. Terminology. Traversal of Binary Trees. Expression Trees. Binary Search Trees.
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.
Due: 2007/11/12. Problem 1 Rewrite function Push and Pop (Program 3.10 and 3.12) using an additional variable lastOp as discussed on Page 146. The queue.
Tree Data Structures.
Starting at Binary Trees
1 5. Abstract Data Structures & Algorithms 5.1 Data Structure Fundamentals.
1 Storing Hierarchical Information Lists, Stacks, and Queues represent linear sequences Data often contain hierarchical relationships that cannot be expressed.
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
Rudiments of Trees a Joshua presentation DATA STRUCTURES.
Chapter 12 Abstract Data Type. Understand the concept of an abstract data type (ADT). Understand the concept of a linear list as well as its operations.
Graphs Upon completion you will be able to:
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
2/11/ IT 179 Recursive Definition of Tree Structures 1.Empty is a tree; the root is null 2.A node points to a finite number of the roots of some.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Symbol tables.
CMSC 202, Version 5/02 1 Trees. CMSC 202, Version 5/02 2 Tree Basics 1.A tree is a set of nodes. 2.A tree may be empty (i.e., contain no nodes). 3.If.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary Trees.
Data Structures and Algorithms Lists, Stacks, Queues, and Graphs Sorting and searching algorithms.
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.
Chapter 12 Abstract Data Type.
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
Trees Chapter 15.
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Week 6 - Wednesday CS221.
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
Tree.
TREE DATA STRUCTURE Data Structure 21-Sep-18 Tree
Binary Trees, Binary Search Trees
Chapter 20: Binary Trees.
Chapter 21: Binary Trees.
CS212: Data Structures and Algorithms
Binary Tree Traversal Methods
Extension of linked list
Stacks, Queues, and Deques
Zhen Jiang West Chester University
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Binary Tree Traversal Methods
Trees CMSC 202, Version 5/02.
Data Structures – Week #5
Binary Tree Traversal Methods
CMSC 202 Trees.
Data Structures and Algorithm Analysis Trees
Binary Trees, Binary Search Trees
CE 221 Data Structures and Algorithms
Stacks A list where insertions and deletions can occur only at the end of the list. linked list or array implementation topOfStack  operations:
Binary Trees, Binary Search Trees
Presentation transcript:

Extension of linked list Zhen Jiang West Chester University zjiang@wcupa.edu

Outline Double Cyclic Linked List Queue & Stack Binary Tree Expression Tree Networks

(Single) Linked list node NULL

Double Cyclic Linked List node NULL

Queue node Delete an item from the tail NULL Insert a new item at the head

Stack node NULL Insert a new item at the head Delete an item from the head

Implementation of stack with template http://www.cs.wcupa.edu/~zjiang/csc513_template.ppt

Use of Stack Project 5 Reading information via file http://www.cs.wcupa.edu/~zjiang/530_proj5_file.pdf Three stacks, one for each {}, (), and []. Left => push/insert Right => pop/delete the closest left symbol Evaluation of (postfix) expression

5 4 + 3 * 5 4 3 + * 5 4 * 3 + 5 4 3 * + (5 + 4) * 3 5 * (4 + 3) 5 * 4 + 3 5 + (4 + 3)

Read the formula from left to right Number => push Binary operator => 2 pops Right number popped first Then, left number popped. Calculate result = <second> op <first> Push (result) Until expression reading finishes and only one (final) result is left in stack

Disorder of the link connection node NULL

Tree Definition Each node u has n(u) children Considering the parent-child relationship is undirected, there is no cycle in a tree There is only one node called the root in the entire tree. It has children only but no parent.

Binary Tree Definition Definition of tree (3) For each node u, n(u)<3 L<S<R < is a relation between any two nodes in the tree

Constructor Assume each node has a number value so that we have the relation < Given a sequence: n1, n2, n3, …, ni, … n1 -> set root unit (node) ni -> call insertion(node, ni)

Insertion(p, n) If (p->v < n) If (p->v > n) If p->R not empty Insertion (p->R, n) else Set p->R If (p->v > n) Similar to the case (p->v < n)

Travel (print out all node values) Infix travel, L->S->R Postfix travel, L->R->S Prefix travel, S->L->R

Infix travel If node is not empty, Infix_print (node); Infix_print (p) If (p->L) infix_print(p->L) Cout << p->v If(p->R) infix_print (p->R)

Search If node is not empty, Search (node, n); Search (p, n) If (p->v == n) return true If (p->v < n) return Search (p->R, n) If (p->v > n) return Search (p->L, n) Terminating condition: if (!p) return false

Deletion Delete the root node If node is empty If node->L (or node->R) is empty tmp = node->R (or node->L) Delete node node = tmp

If neither node->L nor node->R is empty If node->L->R is empty node -> v = node->L->v tmp = node->L->L Delete node->L node->L = tmp Else tmp = node->L While (tmp->R->R) tmp = tmp->R node->v = tmp->R->V tmp2 = tmp->R->L Delete tmp->R tmp->R = tmp2

See if you can find a certain value in the tree and delete it! Delete (n) If (node->v == n) delete node; If (node->v < n) deletion (node, node-R, n, 1) If (node->v > n) deletion (node, node-L, n, 0)

Deletion (parent, start, value, flag) If start is empty // not found, done! If start->v < value If start->v > value Else //start->v == value If both start->L and start->R are empty Delete start If (flag)Parent ->R = NULL Else Parent -> L = NULL If start->L (or start->R) is empty

Deletion (parent, start, value, flag) Else //start->v == value If start->L (or start->R) is empty If (flag) Parent-R = Start->R (or start->L) Else Parent->L = Start->R Delete start If neither start->L nor start->R is empty

If start->L->R is empty start -> v = start->L->v tmp = start->L->L Delete start->L start->L = tmp Else tmp = start->L While (tmp->R->R) tmp = tmp->R start->v = tmp->R->V tmp2 = tmp->R->L Delete tmp->R tmp->R = tmp2

Expression Tree Definition Definition of binary tree (5) All leaves are numbers, and all intermediate nodes are operators To simplify the discussion in this class, we use binary operators only.

Evaluation If node is not empty, R_E(node); R_E(p) If p->v is not digit Lvalue = R_E(p->L); Rvalue = R_E(p->R); Return Lvalue <p->v> Rvalue; Else Return p->v

Print Construction Postfix From infix format http://www.cs.wcupa.edu/~zjiang/csc530_expressionTree.htm

Network Graph table Depth first search Width first search http://www.cs.wcupa.edu/~zjiang/csc530_graph_table.pdf Depth first search http://www.cs.wcupa.edu/~zjiang/csc530_depth.pdf Width first search http://www.cs.wcupa.edu/zjiang/csc530_width.pdf Shortest path construction http://www.cs.wcupa.edu/~zjiang/csc530_shortestpath.pdf

Spanning (travel) Project 7