Stacks, Queues and Hierarchical Collections. 2501ICT Logan
|
|
- Stuart Dalton
- 5 years ago
- Views:
Transcription
1 Stacks, Queues and Hierarchical Collections 2501ICT Logan
2 Contents Linked Data Structures Revisited Stacks Queues Trees Binary Trees Generic Trees Implementations 2
3 Queues and Stacks Queues and Stacks Linear Collections Can be implemented in different ways, e.g. Arrays Linked Lists Are often used in Operating Systems and run time environments Function/Method calling Stacks Process priority Queues 3
4 Queues FIFO collections First element enqueued is first to be dequeued Insertions occur at one end, the rear Removals occur at the other end, the front Priority Queue Extensions Reordering according to priority Few priorities: multiple Queues Many priorities: insert according to priority 4
5 Queues using Lists Queues using Lists Use the head and tail Pointers head NULL NULL front data rear tail Enqueue: Insert from the tail (rear) Dequeue: Remove from the head (front) 5
6 Priority Queues Priority Queues Implementation #1: Multiple Lists One list per priority Enqueue on the corresponding list Dequeue starting at the highest priority list Go to next lower priority if empty, etc. Does not require search operation to enqueue Requires two pointers (head/tail) per priority: Faster enqueue, but slower dequeue operation Useful if number of different priorities is small 6
7 Priority Queues (2) Priority Queues (2) #2: Priority Ordering Only one list Enqueue according to priority Higher priority entries overtake lower ones Dequeue always from the head Requires linear search to enqueue: O(n) Dequeue doesn t require search: O(1) Useful if number of different priorities is large 7
8 Queue Applications Queue Applications First-Come-First Serve Algorithms OS Process Scheduling Event Handling Modeling and Simulation of Real-World Processes E.g. checkout queue in a supermarket 8
9 Stacks LIFO collection The last element pushed onto the stack is the first to be retrieved Both push (insertion) and pop (deletion) operations occur at the top of the stack Implementation Arrays Singly linked lists 9
10 Array Implementation Array Implementation Index: i = 0; Push: stack[i++] = element; Pop: element = stack[--i]; Peek: element = stack[i-1]; Sneak preview, without changing i Watch Preconditions! 10
11 Stack Example Stack Example Parsing Matching Parenthesis expression = { letter } ( expression ) [ expression ] either a letter or an expression in brackets Legal examples a ab (a) (ab) [(a)] [a(b)cd] Illegal examples a) )( a( [[(]) [a)a] 11
12 Matching () Algorithm Matching () Algorithm For each character c in the String If c is (, [, or { Push c onto the stack Else if c is ), ], or } If the stack is empty: return false Else pop the top opening bracket and check if it matches the corresponding closing bracket Return true if the stack is empty 12
13 Hierarchical Collections Hierarchical Collections Tree definition Types of Trees Binary Expressions Expression Trees Tree traversals: pre-, in-, postorder Examples Generating Postfix, Parsing 13
14 Tree Definition Tree Definition Each node has at most one predecessor Parent D1 Many Successors Children Siblings D2 D3 Nodes sharing the same parent (eg, D2 and D3) 14
15 Tree Definition (2) Tree Definition (2) Topmost Node: root D1 Successors Children, Children of Children Also called descendants All nodes are successors of root D2 D4 D3 15
16 Tree Definition (3) Tree Definition (3) Leaf Nodes: Nodes without Successors E.g. D3 and D4 D1 Frontier: The set of all leaf nodes D2 D4 D3 16
17 Tree Definition (4) Tree Definition (4) Interior Nodes: Nodes with at least one successor E.g. D1 and D2 D1 Ancestors: Immediate or indirect predecessors E.g, D1 is an ancestor of D2, D3, and D4 D2 D4 D3 17
18 Tree Definition (5) Tree Definition (5) Levels are numbered from 0 Level 0 is always the root This tree has 3 Levels Level 0: D1 Level 1: D2 and D3 Level 2: D4 D2 D4 D1 D3 Level 0 Level 1 Level 2 18
19 Binary Trees Binary Trees Binary Trees allow at most two children per Node D1 Generic Trees allow any number of children per Node D2 D4 D3 19
20 Generic Trees Generic Trees Order of the Tree: Maximum Number of successors allowed for any given Node D1 E.g., Order: 3 D2 D5 D3 Generic Trees are sometimes called General Trees D4 20
21 Tree Applications Tree Applications Parsing Languages Computer Languages, Mathematical Formula Natural Languages Searchable Data Structures Databases (e.g., B-Trees) Heaps and Balanced Trees Sorting and organising Data 21
22 Parsers Read in Expressions E.g., (2 + 3) * 5 Check Syntactical Correctness Is everything where it should be? Create Parse Tree Evaluator checks semantic meaning and processes the data in the Tree to produce meaningful output 22
23 Binary Expressions Binary Expressions Stored in Binary Trees: e.g. 3+5 Numbers Leaf Nodes + Operators Interior Nodes Operands 3 5 Contained in Subtree of the Expression 23
24 Example Expression Example Expression 3 * *
25 Example Expression (2) Example Expression (2) 3 * (4 + 5) *
26 Operator Precedence Operator Precedence 3 * (4 + 5) * The higher the precedence, the lower in the tree! 3 + Overridden by parentheses!
27 Operator Precedence (2) Operator Precedence (2) If operators have equal precedence, the ones on the left appear lower in the tree when parsed from left to right!
28 Evaluating an Expression Tree Evaluating an Expression Tree Begin at the root Node If a number, return it, otherwise Run the operator w/ the results of Evaluating its left and right subtrees, and Return this value. 28
29 Evaluating Example Evaluating Example 3 * (4 + 5) *
30 Evaluating Example (2) Evaluating Example (2) 3 * (4 + 5) * * is an operator Evaluate left and right subtrees first!
31 Evaluating Example (3) Evaluating Example (3) 3 * (4 + 5) * 3 is a number Return
32 Evaluating Example (4) Evaluating Example (4) 3 * (4 + 5) * + is an operator Evaluate left and right subtrees first!
33 Evaluating Example (5) Evaluating Example (5) 3 * (4 + 5) * 4 is a number Return
34 Evaluating Example (6) Evaluating Example (6) 3 * (4 + 5) * 5 is a number Return
35 Evaluating Example (7) Evaluating Example (7) 3 * (4 + 5) * Add subtree results Return =
36 Evaluating Example (8) Evaluating Example (8) 3 * (4 + 5) * 27 Multiply subtree results Return 3 * 9 =
37 Evaluate Pseudocode Evaluate Pseudocode evaluate(node) { if node is a number return number; else { left = evaluate(node.left); right = evaluate(node.right); return compute(node, left, right); } } 37
38 Binary Tree Traversals Binary Tree Traversals Preorder Visit node, then go left, then go right Inorder Go left, then visit node then go right Postorder: Depth First Go left, then go right, then visit node Breadth First Level 0, then Level 1, then Level 2, etc. 38
39 Binary Tree Traversals (2) Binary Tree Traversals (2) Preorder, Inorder, and Postorder Correspond with Prefix, Infix, and Postfix Notations of an Expression Infix: Prefix = Polish Notation (PN) : +(3,5) Postfix = Reverse Polish Notation (RPN) : Use the Same Generic Recursive Algorithm! 39
40 Prefix Pseudocode Prefix Pseudocode String prefix(node) { if (node == NULL) return ; else return node + prefix(node.left) + prefix (node.right); } 40
41 Infix Pseudocode Infix Pseudocode String infix(node) { if (node == NULL) return ; else return infix(node.left) + node + infix (node.right); } 41
42 Postfix Pseudocode Postfix Pseudocode String postfix(node) { if (node == NULL) return ; else return postfix(node.left) + postfix (node.right) + node; } 42
43 A Binary Tree Structure A Binary Tree Structure struct BTNode { protected: BTNode *left; // left child BTNode *right; // right child Element_Type value; // the actual data // here go the usual access methods: // 43
44 A Binary Tree Constructor A Binary Tree Constructor BTNode ( Element_Type E = 0, BTNode *L=NULL, BTNode *R=NULL) : value (E), left ( L), right (R) {} }; 44
45 Creating a Binary Tree Creating a Binary Tree BTNode *test_left= new BTNode ( 3, NULL,NULL); OR BTNode *test_left= new BTNode ( 3 ); 3 nil nil 45
46 Creating a Binary Tree Creating a Binary Tree BTNode *test_left= new BTNode ( 3 ); BTNode *test_right= new BTNode ( 5 ); 3 5 nil nil 46
47 Creating a Binary Tree Creating a Binary Tree BTNode *test_left= new BTNode ( 3 ); BTNode *test_right= new BTNode ( 5 ); BTNode *test_root= new BTNode ( +,test_left,test_right);
48 Creating a Binary Tree Creating a Binary Tree BTNode *test_left= new BTNode ( 3 ); BTNode *test_right= new BTNode ( 5 ); BTNode *test_root= new BTNode ( +,test_left,test_right); Infix: Postfix: P fi +(3 5)
49 Grammar Parsing Grammar Parsing Recursive Definition, e.g Infix: Expression = Term { + - Term } Term = Factor { * / Factor } Factor = number ( Expression ) Represents standard math formulas, e.g * ( 5 - ( 6 / 7 ) ) Can be used to create a parse tree! 49
50 Recursive Descent Parsing Recursive Descent Parsing Expression = Term { + - Term } Term = Factor { * / Factor } Factor = number ( Expression ) Expression() { Term(); while (token == '+' token == '-') { get_token(); Term(); } } 50
51 Recursive Descent Parsing Recursive Descent Parsing Expression = Term { + - Term } Term = Factor { * / Factor } Factor = number ( Expression ) Term() { Factor(); while (token == '*' token == '/') { get_token(); Factor(); } } 51
52 Recursive Descent Parsing Recursive Descent Parsing Expression = Term { + - Term } Term = Factor { * / Factor } Factor = number ( Expression ) Factor() { switch (token) { case number: get_token(); break; case '(': get_token(); Expression(); if (token!= ')') error( No closing ')'"); get_token(); break; } } default: error(error '%s'\n", token); 52
53 References Lambert, K. A., & Osborne, M. (2004): A Framework for Program Design and Data Structures: Brooks/Cole. Chapters
54 Appendix C Language Examples
55 A Binary Tree Structure (C) A Binary Tree Structure (C) typedef struct BinTreeNode btnode; struct BinTreeNode { btnode *left; /* left child */ btnode *right; /* right child */ void *value; /* the actual data */ }; 55
56 A Binary Tree Constructor (C) A Binary Tree Constructor (C) btnode *newbtnode(void *data, btnode *left, btnode *right) { btnode *this = malloc(sizeof btnode); this->value = data; this->left = left; this->right = right; } return this; 56
57 Creating a Binary Tree (C) Creating a Binary Tree (C) btnode *left = newbtnode( 3, NULL, NULL); 3 NULL NULL 57
58 Creating a Binary Tree (C) Creating a Binary Tree (C) btnode *left = newbtnode( 3, NULL, NULL); btnode *right = newbtnode( 5, NULL, NULL); 3 5 NULL NULL 58
59 Creating a Binary Tree (C) Creating a Binary Tree (C) btnode *left = newbtnode( 3, NULL, NULL); btnode *right = newbtnode( 5, NULL, NULL); btnode *root = newbtnode( +, left, right);
60 Creating a Binary Tree (C) Creating a Binary Tree (C) btnode *left = newbtnode( 3, NULL, NULL); btnode *right = newbtnode( 5, NULL, NULL); btnode *root = newbtnode( +, left, right); Infix: Postfix: Prefix: +(3, 5) add(3, 5) 3 Functional Notation 5 60
61 Appendix Objective-C Language Examples
62 A Binary Tree Structure A Binary Tree BTNode: NSObject; { BTNode *left; // left child BTNode *right; // right child id value; // the actual data } // here go the usual access methods: // -setleft, 62
63 A Binary Tree Constructor A Binary Tree Constructor - initwithvalue: v left: (BTNode *) l right: (BTNode *) r { if (!(self = [self init])) return nil; value = v; left = l; right = r; } return self; 63
64 Creating a Binary Tree Creating a Binary Tree BTNode *left = [[BTNode alloc] 3 left: nil right: nil]; 3 nil nil 64
65 Creating a Binary Tree Creating a Binary Tree BTNode *left = [[BTNode alloc] 3 left: nil right: nil]; BTNode *right = [[BTNode alloc] 5 left: nil right: nil]; 3 5 nil nil 65
66 Creating a Binary Tree Creating a Binary Tree BTNode *left = [[BTNode alloc] 3 left: nil right: nil]; BTNode *right = [[BTNode alloc] 5 left: nil right: nil]; BTNode *root = [[BTNode alloc] + + left: left right: right];
67 Creating a Binary Tree Creating a Binary Tree BTNode *left = [[BTNode alloc] 3 left: nil right: nil]; BTNode *right = [[BTNode alloc] 5 left: nil right: nil]; BTNode *root = [[BTNode alloc] + + left: left right: right]; Infix: Postfix: Prefix: +(3, 5) add(3, 5) Functional notation
Stacks, Queues and Hierarchical Collections
Programming III Stacks, Queues and Hierarchical Collections 2501ICT Nathan Contents Linked Data Structures Revisited Stacks Queues Trees Binary Trees Generic Trees Implementations 2 Copyright 2002- by
More informationTree Applications. Processing sentences (computer programs or natural languages) Searchable data structures
Tree Applications Processing sentences (computer programs or natural languages) Searchable data structures Heaps (implement heap sort, priority queues) A Parse (Expression) Tree Source language program
More information12 Abstract Data Types
12 Abstract Data Types 12.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT). Define
More informationPostfix (and prefix) notation
Postfix (and prefix) notation Also called reverse Polish reversed form of notation devised by mathematician named Jan Łukasiewicz (so really lü-kä-sha-vech notation) Infix notation is: operand operator
More informationTREES. Trees - Introduction
TREES Chapter 6 Trees - Introduction All previous data organizations we've studied are linear each element can have only one predecessor and successor Accessing all elements in a linear sequence is O(n)
More informationMULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR
STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM
More informationRevision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,
[1] Big-O Analysis AVERAGE(n) 1. sum 0 2. i 0. while i < n 4. number input_number(). sum sum + number 6. i i + 1 7. mean sum / n 8. return mean Revision Statement no. of times executed 1 1 2 1 n+1 4 n
More informationSection 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
Section 5.5 Binary Tree A binary tree is a rooted tree in which each vertex has at most two children and each child is designated as being a left child or a right child. Thus, in a binary tree, each vertex
More informationAn Introduction to Trees
An Introduction to Trees Alice E. Fischer Spring 2017 Alice E. Fischer An Introduction to Trees... 1/34 Spring 2017 1 / 34 Outline 1 Trees the Abstraction Definitions 2 Expression Trees 3 Binary Search
More informationChapter 4 Trees. Theorem A graph G has a spanning tree if and only if G is connected.
Chapter 4 Trees 4-1 Trees and Spanning Trees Trees, T: A simple, cycle-free, loop-free graph satisfies: If v and w are vertices in T, there is a unique simple path from v to w. Eg. Trees. Spanning trees:
More informationTree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.
Tree A tree consists of a set of nodes and a set of edges connecting pairs of nodes. A tree has the property that there is exactly one path (no more, no less) between any pair of nodes. A path is a connected
More informationCSI33 Data Structures
Outline Department of Mathematics and Computer Science Bronx Community College November 13, 2017 Outline Outline 1 C++ Supplement.1: Trees Outline C++ Supplement.1: Trees 1 C++ Supplement.1: Trees Uses
More informationBinary Trees, Binary Search Trees
Binary Trees, Binary Search Trees Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search, insert, delete)
More informationFirst Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...
First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms.... Q1) What are some of the applications for the tree data structure? Q2) There are 8, 15, 13, and
More informationFormal Languages and Automata Theory, SS Project (due Week 14)
Formal Languages and Automata Theory, SS 2018. Project (due Week 14) 1 Preliminaries The objective is to implement an algorithm for the evaluation of an arithmetic expression. As input, we have a string
More informationTrees! Ellen Walker! CPSC 201 Data Structures! Hiram College!
Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College! ADTʼs Weʼve Studied! Position-oriented ADT! List! Stack! Queue! Value-oriented ADT! Sorted list! All of these are linear! One previous item;
More informationCS301 - Data Structures Glossary By
CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm
More informationRecursive Data Structures and Grammars
Recursive Data Structures and Grammars Themes Recursive Description of Data Structures Grammars and Parsing Recursive Definitions of Properties of Data Structures Recursive Algorithms for Manipulating
More informationTrees. Tree Structure Binary Tree Tree Traversals
Trees Tree Structure Binary Tree Tree Traversals The Tree Structure Consists of nodes and edges that organize data in a hierarchical fashion. nodes store the data elements. edges connect the nodes. The
More informationDATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305
Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n
More informationData Structures. Trees. By Dr. Mohammad Ali H. Eljinini. M.A. Eljinini, PhD
Data Structures Trees By Dr. Mohammad Ali H. Eljinini Trees Are collections of items arranged in a tree like data structure (none linear). Items are stored inside units called nodes. However: We can use
More information7.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
Chapter 7 Trees 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 Tree Terminology Parent Ancestor Child Descendant Siblings
More informationMID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.
MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions
More informationThe Stack and Queue Types
The Stack and Queue Types Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2012/csc1254.html 2 Programming Principle of the Day Do the simplest thing that could possibly work A good
More informationData Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.
Data Structures Outline Introduction Linked Lists Stacks Queues Trees Introduction dynamic data structures - grow and shrink during execution Linked lists - insertions and removals made anywhere Stacks
More informationCpt S 122 Data Structures. Course Review Midterm Exam # 1
Cpt S 122 Data Structures Course Review Midterm Exam # 1 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 1 When: Friday (09/28) 12:10-1pm Where:
More informationR13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)
SET - 1 II B. Tech I Semester Supplementary Examinations, May/June - 2016 PART A 1. a) Write a procedure for the Tower of Hanoi problem? b) What you mean by enqueue and dequeue operations in a queue? c)
More informationObjective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)
Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113) 1. The number of interchanges required to sort 5, 1, 6, 2 4 in ascending order using Bubble Sort (A)
More informationMarch 20/2003 Jayakanth Srinivasan,
Definition : A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. Definition : In a multigraph G = (V, E) two or
More informationName CPTR246 Spring '17 (100 total points) Exam 3
Name CPTR246 Spring '17 (100 total points) Exam 3 1. Linked Lists Consider the following linked list of integers (sorted from lowest to highest) and the changes described. Make the necessary changes in
More informationCSI33 Data Structures
Outline Department of Mathematics and Computer Science Bronx Community College October 19, 2016 Outline Outline 1 Chapter 7: Trees Outline Chapter 7: Trees 1 Chapter 7: Trees Uses Of Trees Chapter 7: Trees
More informationFORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE
TED (10)-3071 Reg. No.. (REVISION-2010) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours (Maximum marks: 100)
More informationGarbage Collection: recycling unused memory
Outline backtracking garbage collection trees binary search trees tree traversal binary search tree algorithms: add, remove, traverse binary node class 1 Backtracking finding a path through a maze is an
More informationFORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours
TED (10)-3071 Reg. No.. (REVISION-2010) (Maximum marks: 100) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours PART
More informationCS8391-DATA STRUCTURES QUESTION BANK UNIT I
CS8391-DATA STRUCTURES QUESTION BANK UNIT I 2MARKS 1.Define data structure. The data structure can be defined as the collection of elements and all the possible operations which are required for those
More informationData Structures Question Bank Multiple Choice
Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution
More informationCS24 Week 8 Lecture 1
CS24 Week 8 Lecture 1 Kyle Dewey Overview Tree terminology Tree traversals Implementation (if time) Terminology Node The most basic component of a tree - the squares Edge The connections between nodes
More informationCourse Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU
Course Review for Midterm Exam 1 Cpt S 223 Fall 2011 1 Midterm Exam 1 When: Friday (10/14) 1:10-2pm Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & in-class
More informationTrees. (Trees) Data Structures and Programming Spring / 28
Trees (Trees) Data Structures and Programming Spring 2018 1 / 28 Trees A tree is a collection of nodes, which can be empty (recursive definition) If not empty, a tree consists of a distinguished node r
More informationEC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3
UNIT 3 LINEAR DATA STRUCTURES 1. Define Data Structures Data Structures is defined as the way of organizing all data items that consider not only the elements stored but also stores the relationship between
More informationBinary Trees
Binary Trees 4-7-2005 Opening Discussion What did we talk about last class? Do you have any code to show? Do you have any questions about the assignment? What is a Tree? You are all familiar with what
More informationAbstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department
Abstract Data Structures IB Computer Science Content developed by Dartford Grammar School Computer Science Department HL Topics 1-7, D1-4 1: System design 2: Computer Organisation 3: Networks 4: Computational
More informationChapter 20: Binary Trees
Chapter 20: Binary Trees 20.1 Definition and Application of Binary Trees Definition and Application of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two other
More informationMIDTERM EXAMINATION Spring 2010 CS301- Data Structures
MIDTERM EXAMINATION Spring 2010 CS301- Data Structures Question No: 1 Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the
More informationUpcoming ACM Events Linux Crash Course Date: Time: Location: Weekly Crack the Coding Interview Date:
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
More informationTree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.
Trees, Binary Search Trees, and Heaps CS 5301 Fall 2013 Jill Seaman Tree: non-recursive definition Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every node (except
More information3137 Data Structures and Algorithms in C++
3137 Data Structures and Algorithms in C++ Lecture 3 July 12 2006 Shlomo Hershkop 1 Announcements Homework 2 out tonight Please make sure you complete hw1 asap if you have issues, please contact me will
More informationCS8391-DATA STRUCTURES
ST.JOSEPH COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERI NG CS8391-DATA STRUCTURES QUESTION BANK UNIT I 2MARKS 1.Explain the term data structure. The data structure can be defined
More informationE.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.
17CA 104DATA STRUCTURES Academic Year : 018-019 Programme : MCA Year / Semester : I / I Question Bank Course Coordinator: Mrs. C.Mallika Course Objectives The student should be able to 1. To understand
More informationData Structure. IBPS SO (IT- Officer) Exam 2017
Data Structure IBPS SO (IT- Officer) Exam 2017 Data Structure: In computer science, a data structure is a way of storing and organizing data in a computer s memory so that it can be used efficiently. Data
More information09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION
DATA STRUCTURES AND ALGORITHMS 09 STACK APPLICATION REVERSE POLISH NOTATION IMRAN IHSAN ASSISTANT PROFESSOR, AIR UNIVERSITY, ISLAMABAD WWW.IMRANIHSAN.COM LECTURES ADAPTED FROM: DANIEL KANE, NEIL RHODES
More informationLec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)
Lec 17 April 8 Topics: binary Trees expression trees Binary Search Trees (Chapter 5 of text) Trees Linear access time of linked lists is prohibitive Heap can t support search in O(log N) time. (takes O(N)
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 03 / 31 / 2017 Instructor: Michael Eckmann Today s Topics Questions? Comments? finish RadixSort implementation some applications of stack Priority Queues Michael
More informationComputer Science 210 Data Structures Siena College Fall Topic Notes: Trees
Computer Science 0 Data Structures Siena College Fall 08 Topic Notes: Trees We ve spent a lot of time looking at a variety of structures where there is a natural linear ordering of the elements in arrays,
More informationF453 Module 7: Programming Techniques. 7.2: Methods for defining syntax
7.2: Methods for defining syntax 2 What this module is about In this module we discuss: explain how functions, procedures and their related variables may be used to develop a program in a structured way,
More informationCS 8391 DATA STRUCTURES
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK CS 8391 DATA STRUCTURES UNIT- I PART A 1. Define: data structure. A data structure is a way of storing and organizing data in the memory for
More informationADTS, GRAMMARS, PARSING, TREE TRAVERSALS
3//15 1 AD: Abstract Data ype 2 Just like a type: Bunch of values together with operations on them. Used often in discussing data structures Important: he definition says ntthing about the implementation,
More informationCOMP 250 Fall binary trees Oct. 27, 2017
The order of a (rooted) tree is the maximum number of children of any node. A tree of order n is called an n-ary tree. It is very common to use trees of order 2. These are called binary trees. Binary Trees
More informationIntroduction to Computers and Programming. Concept Question
Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 7 April 2 2004 Concept Question G1(V1,E1) A graph G(V, where E) is V1 a finite = {}, nonempty E1 = {} set of G2(V2,E2) vertices and
More informationBasic Data Structures (Version 7) Name:
Prerequisite Concepts for Analysis of Algorithms Basic Data Structures (Version 7) Name: Email: Concept: mathematics notation 1. log 2 n is: Code: 21481 (A) o(log 10 n) (B) ω(log 10 n) (C) Θ(log 10 n)
More informationData Abstractions. National Chiao Tung University Chun-Jen Tsai 05/23/2012
Data Abstractions National Chiao Tung University Chun-Jen Tsai 05/23/2012 Concept of Data Structures How do we store some conceptual structure in a linear memory? For example, an organization chart: 2/32
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 07 / 26 / 2016 Instructor: Michael Eckmann Today s Topics Comments/Questions? Stacks and Queues Applications of both Priority Queues Michael Eckmann - Skidmore
More informationCE 221 Data Structures and Algorithms
CE 221 Data Structures and Algorithms Chapter 4: Trees (Binary) Text: Read Weiss, 4.1 4.2 Izmir University of Economics 1 Preliminaries - I (Recursive) Definition: A tree is a collection of nodes. The
More informationBinary Trees and Binary Search Trees
Binary Trees and Binary Search Trees Learning Goals After this unit, you should be able to... Determine if a given tree is an instance of a particular type (e.g. binary, and later heap, etc.) Describe
More information1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking
Review for Test 2 (Chapter 6-10) Chapter 6: Template functions & classes 1) What is the primary purpose of template functions? A. To allow a single function to be used with varying types of arguments B.
More informationLecture Notes 16 - Trees CSS 501 Data Structures and Object-Oriented Programming Professor Clark F. Olson
Lecture Notes 16 - Trees CSS 501 Data Structures and Object-Oriented Programming Professor Clark F. Olson Reading: Carrano, Chapter 15 Introduction to trees The data structures we have seen so far to implement
More informationAdvanced Java Concepts Unit 5: Trees. Notes and Exercises
Advanced Java Concepts Unit 5: Trees. Notes and Exercises A Tree is a data structure like the figure shown below. We don t usually care about unordered trees but that s where we ll start. Later we will
More informationCS W3134: Data Structures in Java
CS W3134: Data Structures in Java Lecture #10: Stacks, queues, linked lists 10/7/04 Janak J Parekh HW#2 questions? Administrivia Finish queues Stack/queue example Agenda 1 Circular queue: miscellany Having
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 10: Search and Heaps MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Search and Heaps 2 Linear Search Binary Search Introduction to trees Priority Queues Heaps Linear Search
More informationSection Summary. Introduction to Trees Rooted Trees Trees as Models Properties of Trees
Chapter 11 Copyright McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education. Chapter Summary Introduction to Trees Applications
More informationFriday, March 30. Last time we were talking about traversal of a rooted ordered tree, having defined preorder traversal. We will continue from there.
Friday, March 30 Last time we were talking about traversal of a rooted ordered tree, having defined preorder traversal. We will continue from there. Postorder traversal (recursive definition) If T consists
More informationBinary Trees. Height 1
Binary Trees Definitions A tree is a finite set of one or more nodes that shows parent-child relationship such that There is a special node called root Remaining nodes are portioned into subsets T1,T2,T3.
More informationPrinciples of Computer Science
Principles of Computer Science Binary Trees 08/11/2013 CSCI 2010 - Binary Trees - F.Z. Qureshi 1 Today s Topics Extending LinkedList with Fast Search Sorted Binary Trees Tree Concepts Traversals of a Binary
More informationPrepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1
QUESTION BANK ON COURSE: 304: PRELIMINARIES: 1. What is array of pointer, explain with appropriate example? 2 2. Differentiate between call by value and call by reference, give example. 3. Explain pointer
More informationData Structure - Binary Tree 1 -
Data Structure - Binary Tree 1 - Hanyang University Jong-Il Park Basic Tree Concepts Logical structures Chap. 2~4 Chap. 5 Chap. 6 Linear list Tree Graph Linear structures Non-linear structures Linear Lists
More informationAlgorithms and Data Structures
Algorithms and Data Structures PD Dr. rer. nat. habil. Ralf Peter Mundani Computation in Engineering / BGU Scientific Computing in Computer Science / INF Summer Term 2018 Part 2: Data Structures PD Dr.
More informationTree. Virendra Singh Indian Institute of Science Bangalore Lecture 11. Courtesy: Prof. Sartaj Sahni. Sep 3,2010
SE-286: Data Structures t and Programming Tree Virendra Singh Indian Institute of Science Bangalore Lecture 11 Courtesy: Prof. Sartaj Sahni 1 Trees Nature Lover sviewofatree leaves branches root 3 Computer
More informationSTACKS AND QUEUES. Problem Solving with Computers-II
STACKS AND QUEUES Problem Solving with Computers-II 2 Stacks container class available in the C++ STL Container class that uses the Last In First Out (LIFO) principle Methods i. push() ii. iii. iv. pop()
More informationDesign and Analysis of Algorithms Lecture- 9: Binary Search Trees
Design and Analysis of Algorithms Lecture- 9: Binary Search Trees Dr. Chung- Wen Albert Tsao 1 Binary Search Trees Data structures that can support dynamic set operations. Search, Minimum, Maximum, Predecessor,
More informationTopic 14. The BinaryTree ADT
Topic 14 The BinaryTree ADT Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary tree implementation Examine a binary tree
More informationDepartment of Computer Science and Technology
UNIT : Stack & Queue Short Questions 1 1 1 1 1 1 1 1 20) 2 What is the difference between Data and Information? Define Data, Information, and Data Structure. List the primitive data structure. List the
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 11: Binary Search Trees MOUNA KACEM mouna@cs.wisc.edu Fall 2018 General Overview of Data Structures 2 Introduction to trees 3 Tree: Important non-linear data structure
More informationCISC 235 Topic 3. General Trees, Binary Trees, Binary Search Trees
CISC 235 Topic 3 General Trees, Binary Trees, Binary Search Trees Outline General Trees Terminology, Representation, Properties Binary Trees Representations, Properties, Traversals Recursive Algorithms
More informationData Structure Advanced
Data Structure Advanced 1. Is it possible to find a loop in a Linked list? a. Possilbe at O(n) b. Not possible c. Possible at O(n^2) only d. Depends on the position of loop Solution: a. Possible at O(n)
More informationThe Bucharest University of Economic Studies. Data Structures. ADTs-Abstract Data Types Stacks and Queues
The Bucharest University of Economic Studies Data Structures ADTs-Abstract Data Types Stacks and Queues Agenda Definition Graphical representation Internal interpretation Characteristics Operations Implementations
More informationDEEPIKA KAMBOJ UNIT 2. What is Stack?
What is Stack? UNIT 2 Stack is an important data structure which stores its elements in an ordered manner. You must have seen a pile of plates where one plate is placed on top of another. Now, when you
More informationC Data Structures Stacks. Stack. push Adds a new node to the top of the stack
1 12 C Data Structures 12.5 Stacks 2 Stack New nodes can be added and removed only at the top Similar to a pile of dishes Last-in, first-out (LIFO) Bottom of stack indicated by a link member to NULL Constrained
More informationTopic Binary Trees (Non-Linear Data Structures)
Topic Binary Trees (Non-Linear Data Structures) CIS210 1 Linear Data Structures Arrays Linked lists Skip lists Self-organizing lists CIS210 2 Non-Linear Data Structures Hierarchical representation? Trees
More informationChapter 10: Trees. A tree is a connected simple undirected graph with no simple circuits.
Chapter 10: Trees A tree is a connected simple undirected graph with no simple circuits. Properties: o There is a unique simple path between any 2 of its vertices. o No loops. o No multiple edges. Example
More informationIntroduction to Binary Trees
Introduction to inary Trees 1 ackground ll data structures examined so far are linear data structures. Each element in a linear data structure has a clear predecessor and a clear successor. Precessors
More informationMarch 13/2003 Jayakanth Srinivasan,
Statement Effort MergeSort(A, lower_bound, upper_bound) begin T(n) if (lower_bound < upper_bound) Θ(1) mid = (lower_bound + upper_bound)/ 2 Θ(1) MergeSort(A, lower_bound, mid) T(n/2) MergeSort(A, mid+1,
More informationTrees. A tree is a directed graph with the property
2: Trees Trees A tree is a directed graph with the property There is one node (the root) from which all other nodes can be reached by exactly one path. Seen lots of examples. Parse Trees Decision Trees
More informationData Structures. 1. Each entry in a linked list is a called a (a)link (b)node (c)data structure (d)none of the above
Data Structures 1. Each entry in a linked list is a called a --------- (a)link (b)node (c)data structure (d)none of the above 2. Linked list uses type of memory allocation (a)static (b)dynamic (c)random
More information6-TREE. Tree: Directed Tree: A directed tree is an acyclic digraph which has one node called the root node
6-TREE Data Structure Management (330701) Tree: A tree is defined as a finite set of one or more nodes such that There is a special node called the root node R. The remaining nodes are divided into n 0
More informationLecture Data Structure Stack
Lecture Data Structure Stack 1.A stack :-is an abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)
WINTER 18 EXAMINATION Subject Name: Data Structure Model wer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in
More informationThere are many other applications like constructing the expression tree from the postorder expression. I leave you with an idea as how to do it.
Programming, Data Structures and Algorithms Prof. Hema Murthy Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 49 Module 09 Other applications: expression tree
More information8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))
DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES UNIT IV NONLINEAR DATA STRUCTURES Part A 1. Define Tree [N/D 08]
More informationWhy Do We Need Trees?
CSE 373 Lecture 6: Trees Today s agenda: Trees: Definition and terminology Traversing trees Binary search trees Inserting into and deleting from trees Covered in Chapter 4 of the text Why Do We Need Trees?
More informationSTACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:
STACKS A stack is a linear data structure for collection of items, with the restriction that items can be added one at a time and can only be removed in the reverse order in which they were added. The
More information