DATA STRUCURES II CSC 2302. QUIZ 1. What is Data Structure ? 2. Mention the classifications of data structure giving example of each. 3. Briefly explain.

Slides:



Advertisements
Similar presentations
TREES Chapter 6. Trees - Introduction  All previous data organizations we've studied are linear—each element can have only one predecessor and successor.
Advertisements

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.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
CS 171: Introduction to Computer Science II
Trees Chapter 8.
ITEC200 – Week08 Trees. 2 Chapter Objectives Students can: Describe the Tree abstract data type and use tree terminology such as.
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.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
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.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Trees.
Binary Trees Chapter 6.
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
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.
CHAPTER 71 TREE. Binary Tree A binary tree T is a finite set of one or more nodes such that: (a) T is empty or (b) There is a specially designated node.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
COSC2007 Data Structures II
Trees. Tree Terminology Chapter 8: Trees 2 A tree consists of a collection of elements or nodes, with each node linked to its successors The node at the.
Advanced Algorithms Analysis and Design Lecture 8 (Continue Lecture 7…..) Elementry Data Structures By Engr Huma Ayub Vine.
Introduction to Data Structures. Definition Data structure is representation of the logical relationship existing between individual elements of data.
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.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 10: Trees Data Abstraction & Problem Solving with C++
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
1 Trees A tree is a data structure used to represent different kinds of data and help solve a number of algorithmic problems Game trees (i.e., chess ),
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
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 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.
Data Structure Chapter# 5 Tree Course Instructor AMEER JAMAL SHAH.
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Grammars and Parsing  Recursive Definitions of Properties.
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
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.
Lecture - 10 on Data Structures. 6:05:57 PM Prepared by, Jesmin Akhter, Lecturer, IIT,JU.
IKI 10100I: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100I: Data.
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.
Introduction to Trees IT12112 Lecture 05 Introduction Tree is one of the most important non-linear data structures in computing. It allows us to implement.
Binary Tree 10/22/081. Tree A nonlinear data structure Contain a distinguished node R, called the root of tree and a set of subtrees. Two nodes n1 and.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
1 CMPSCI 187 Computer Science 187 Introduction to Introduction to Programming with Data Structures Lecture 16: Trees Announcements 1.Programming project.
24 January Trees CSE 2011 Winter Trees Linear access time of linked lists is prohibitive  Does there exist any simple data structure for.
Binary Tree.
Foundation of Computing Systems Lecture 4 Trees: Part I.
Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
Data Structure and Algorithms
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.
What is a Tree? Formally, we define a tree T as a set of nodes storing elements such that the nodes have a parent-child relationship, that satisfies the.
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
Trees Chapter 15.
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
Data Structure Interview Question and Answers
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Binary Trees, Binary Search Trees
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
Binary Trees, Binary Search Trees
Trees.
Binary Trees, Binary Search Trees
Presentation transcript:

DATA STRUCURES II CSC 2302

QUIZ 1. What is Data Structure ? 2. Mention the classifications of data structure giving example of each. 3. Briefly explain the following : Stack, Queue, and an array. 4. Mention the operations that can be performed on any linear data structure.

DATA STRUCTURE A data structure is an arrangement of data in a computer’s memory. Arrays, Linked lists, queues, stacks, binary trees are examples of common data structures. Different data structures works well for a diffferent purpose. Algorithms are used to manipulate data contained in a given data structure.

Classification of data structures Data structure can be classified as either Linear data structure or Non-linear data structures A data stucture is said to be linear if all its elements form a sequence or linear list e.g array, queue, stack and Linked list A data structure is non-linear if its element does not form a linear list e.g Tree and Graph

Data structures operations The following operations can be perform on any linear data structure. Traversal : Processing each element in the list Search : Finding the location of the element with a given value Insertion : Adding new element to the list Deletion : Removing an element from the list

Cont. Sorting : Arranging the element in some type of order Merging : Combining two lists into a single lists

Array An array is a list of finite number n of similar data elements referenced respectively by a set of n consecutive numbers. Arrays can have n dimensions One-dimentional arrays are arrays in which each element is referenced by one subscript. A two- dimentional array is a collection of similar data elements where each element is referenced by two subscript.

STACK Some data structures allow insertion and deletion at any place in the list(beginning, middle and end) Stack and Queue allow only insertion and deletion at the beginning or the end of the list, not in the middle. Stack is a linear data structure in which item may be added or remove at only one end called TOP.

Cont. A handy mnemonic for stack is called LIFO Other names of stack are ‘’piles’’ or ‘’push down list”

Cont. Push() : Insert element in to stack POP() : Delete element from stack isEmpty() : returns true if stack has no element isFull() : Check to see if there is enough space makeEmpty () : Set stack empty Count () : returns amount of element in stack

Application of stack Used to perform efficient arithmetic operation Use for basic designing of an OS for interrupt handling Use to implement function call in nested procedure (eg if A is main program and B and C are sub-programs) Use in recursion

QUEUE Is a linear list of elements Deletion can only take place at one end called front Insertion can take place at rear Also called FIFO (First one enter first to go out) In computer science example of QUEUE is in timesharing, in which program with the same priority form a QUEUE.

DEQUE A DEQUE is a linear list in which element can be added or removed at both end, but not in the middle DEQUE refers to double ended QUEUE Two variation of DEQUE 1.Output restricted DEQUE : allow deletion at only one end, but allow insertion at both end 2.Input restricted DEQUE : allow insertion only at one end of the list, but allow deletion at both end

PRIORITY QUEUE Is a collection of element such that each element has been asssign a priority The following rules are applied when element are deleted and process 1) An element of higher priority is processed before any element of lower order 2) Two element with same priority are procced according to the order in which they were added to the QUEUE

Cont. Priority Queue are used in timesharing system progaram with high priority are proccesed first and progarm with same priority form a standard queue.

NON-LINEAR DATA STRUCTURE ?

TREES We have disscussed only linear data structure e.g Arrays, Stack and Queue, Lists Some other Linear data Structures not disscused are Strings and Lists Tree is a non-linear data structure Use mainly to represent hierachical relationship between elements e.g records, family tree and table of contents

Application of tree Organizational Chart File System Unix / windows File Structure

Cont. Definition : A tree is a finite set of one or more nodes. There are diferent kinds of tree : Binary tree, 2-Tree or extended binary tree and complete binary tree

Binary Tree A binary tree T is defined as a finite set of elements, called nodes, such that : (a) T is empty (Called the null tree or empty tree). (b) T contains a distinguish node R, called Root and the remaining nodes form an ordered pair of disjoint binary trees T1 and T2.

Terminologies in Tree Internal node : node that contains atleast one child External node ( Leaf) : Sometimes called terminal node and does not contain any child (node) Degree of node is the number of subtree Edge : Is the line from node to successor

Cont. Path : Sequence od edges (Connection of two or more edges) Level number : Each node is assign a level number, Root of tree starts with 0 always Generation : Node with the same level number are said to be of the same generation Depth of tree : Maximum number of node in a branch, depth can also be express as maximum number of level + 1

Cont. Similar Trees : Binary trees are similar if they have the same structure or shape. Tree are said to be copy if they are similar and if they have the same contents at corresponding nodes

Application of Binary Tree Some of the application of binary trees are (1) Arithmetic Expression or Expression Tree (2) Decision Tree

Arithmetic Expression Binary Trees are used to represent arithemetic expressions Internal node : Operators External Node : Operands

Example Consider algebraic expression E below ; This expression can be represented in binary Tree and each every algebraic expression will correspond to a unique tree and vice versa.

Cont. Each Variabe or constant in E appears as an ‘’ Internal ’’ node in T whose left and right subtrees correspond to the operands of the operation. Below is the Corresponding Tree

Complete Binary Tree A tree is said to be complete if all its level, except possibly the last, have the maximum number of possible nodes, and if all nodes at the last level appear as far left as possible.

Extended Binary Trees : 2-Trees A binary Tree T is said to be a 2-Tree or an extended binary tree if each node N has either 0 or 2 childern. Node with 0 Childern are called external node and are represented by square Node with 2 childern are called internal node and are represented with circle Any binary tree can be change to extended binary tree

Full Binary Tree A full binary tree is a binary tree in which every node in the tree has 2 children except the leaves of the tree. Or A full binary tree is a binary tree in which every node in the tree has exactly zero or 2 childern.

Tree traversal Three ways to traverse a tree (1) Preorder (2) Inorder (3) Postorder

Conti (a) PreOrder : Node-Left-Right (NLF) 1. Procces the root R 2. Traverse the left subtree of R in preorder 3. Traverse the right subtree of R in preorder

Cont. (a) InOrder : Left-Node-Righ(LNR) 1. Traverse the left subtree of R in preorder 2. Procces the root R 3. Traverse the right subtree of R in preorder

Cont. (a) Post-order : Left-Node-Righ(LNR) 1. Traverse the left subtree of R in preorder 2. Traverse the right subtree of R in preorder 3. Procces the root R

Example