Algorithms and Data Structures

Size: px
Start display at page:

Download "Algorithms and Data Structures"

Transcription

1 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

2 Part 2: Data Structures PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

3 overview prelude linked lists stacks queues trees PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

4 Prelude fundamentals data structure way of organising data for processing by some algorithm or more general by some computer program often the choice of proper data structures is the only major decision for implementations for the same information some data structures require more or less space for storing the information for the same operations (on the data) some data structures lead to more or less efficient algorithms hence, the choice of algorithms and data structures is closely intertwined design of algorithms also means design of sufficient data structures PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

5 overview prelude linked lists stacks queues trees PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

6 Linked Lists fundamentals elementary data type, but not (yet) defined as primitive in all languages advantages compared to arrays easy growth and shrinkage in size over lifetime, hence, maximum size must not be known in advance high flexibility w.r.t. rearrangement of data items (nevertheless, this comes up with higher expenses for the access of arbitrary items) general description set of sequentially organised items, so called nodes explicit organisation of nodes via link to next node n 1 n 2 n 3 n k 1 n k linked list with nodes n i, 1 i k PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

7 Linked Lists fundamentals (cont d) each node contains one container for storing data item s value (integer, float, boolean,...) one container for storing link to next node... value i 1 value i value i 1... problem: what to specify as next node in case of last node hence, dummy node NIL to indicate end of list for reasons of convenience also dummy node HEAD at the other end HEAD n 1 n 2 n k 1 n k NIL linked list with nodes n i, 1 i k PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

8 Linked Lists fundamentals (cont d) assume, there s a primitive list with two containers value and link which can be accessed via list value and list link furthermore, a dummy node NIL should also be provided hence, the following program creates an empty list list L L link NIL which only consists of the two dummy nodes HEAD and NIL HEAD NIL for adding nodes to list L some further understanding is necessary PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

9 Linked Lists fundamentals (cont d) linked lists are dynamic structures easy rearrangement of nodes possible (just changing links instead of moving items in case of arrays) example: last node should be moved to the front (3 links to be changed) HEAD NIL HEAD NIL HEAD NIL PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

10 Linked Lists list operations typical operations on linked lists are insertion of new nodes (which makes it grow by one in length each) deletion of old nodes (which makes it shrink by one in length each) for inserting a new node only two links have to be changed 4 HEAD NIL 4 HEAD NIL PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

11 Linked Lists list operations (cont d) the following procedure appends a new node at the end of list L by recursively processing all nodes starting from HEAD procedure APPEND (L, new_node) if L link NIL then new_node link L link L link new_node else APPEND (L link, new_node) fi end changing the condition allows to insert a new node anywhere in the list PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

12 Linked Lists list operations (cont d) the following procedure inserts a new node before the one with value val procedure INSERT (L, new_node, val) case L link NIL : exit L link value val : new_node link L link L link new_node else INSERT (L link, new_node, val) esac end the first test for NIL is necessary in case there is no node with value val and the recursion reaches the end of list L PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

13 Linked Lists list operations (cont d) when deleting node n i from a list only one link has to be moved (i.e. linking from node n i 1 to node n i 1 ) this does not delete node n i itself (which still points to n i 1 ), but it is no longer accessible by following the links from HEAD HEAD NIL HEAD NIL PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

14 Linked Lists list operations (cont d) the following procedure deletes a node (with value val) from lists L procedure DELETE (L, next, val) case next NIL : exit next value val : L link next link else DELETE (L link, next link, val) esac end the temporary node next is necessary to link from n i 1 to n i 1 (again, the dummy element HEAD makes everything more convenient) for deleting some node from list L the procedure is called with parameters DELETE (L, L link, val) PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

15 Linked Lists doubly linked lists as shown, linked lists are very efficient for certain operations, but there is no direct access to single nodes hence, finding the k th item has a complexity of (n) as all nodes have to be processed successively until the k th item is reached (compared to (1) for arrays) furthermore, there is no possibility of going backwards in case a node that has already been processed is needed (such as n i 1 for deleting n i ) idea: maintain two links for each node, one to the item before and one to the item after so called doubly linked lists HEAD NIL n 1 n 2... n k 1 n k NIL doubly linked list with nodes n i, 1 i k TAIL PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

16 overview prelude linked lists stacks queues trees PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

17 Stacks fundamentals for many applications rather hard restrictions w.r.t. accessibility of data structures can be made in order to hide (often complicated and, thus, error prone) implementation details such as links or indices allow more flexibility with fewer operations famous representatives of such restricted access data structures are so called stacks or pushdown stacks, i.e. one dimensional structures with LIFO (last in, first out) ordering that support two types of basic operations push (val): inserting one element with value val at end (top) of stack source: wordpress.com pop: removing one element from end (top) of stack and returning its value PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

18 Stacks fundamentals (cont d) stacks are, for instance, used for evaluating arithmetic expressions (e.g. within pocket calculators) arithmetic expressions can be written in different notations prefix: operands appear after the operator infix: the customary way of writing arithmetic expressions (but parentheses may be required) postfix or reverse Polish: operands appear before the operator therefore, stacks require arithmetic expressions to appear in postfix notation so the operands can be on the stack when the operator is encountered (as expression are processed from left to right) and, thus, intermediate results can again be pushed to the stack PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

19 Stacks implementation of stacks stacks to be implemented, for instance, as arrays (in case the maximum size can be predicted in advance) linked lists assume, there s a primitive stack (of fixed size n) implemented as array further assumptions and requirements are necessary it s not possible to push an element on a full stack it s not possible to pop an element from an empty stack index last indicates the last used element in a stack last size n 8 hence, operations push and pop ready to be implemented 4 1 PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

20 Stacks implementation of stacks (cont d) push (here with variables n and last with global visibility ) procedure PUSH (S, val) if last n 1 then last last 1 S(last) val fi end where S indicates a stack and val the value to be pushed on the stack note: there s no error in case stack is full PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

21 Stacks implementation of stacks (cont d) pop (here with variables n and last with global visibility ) procedure POP (S) tmp false if last 0 then tmp S(last) last last 1 fi return (tmp) end where S indicates a stack PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

22 Stacks example evaluation of an arithmetic expression A B C (D E) using a stack in postfix notation: B, C, D, E,,, stack S push (S, B) push (S, C) push (S, D) push (S, E) E push (S, pop (S) pop (S)) D push (S, pop (S) pop (S)) C C push (S, pop (S) pop (S)) B B B A E D C A B note: operators and have to switch operands due to LIFO ordering PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

23 overview prelude linked lists stacks queues trees PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

24 Queues fundamentals other representatives of restricted source: callcentrehelper.com access data structures are queues one dimensional structures with FIFO (first in, first out) ordering that support two types of basic operations insert (val): inserting one element with value val at end of queue remove: removing one element from queue s front and returning its value in comparison to stacks, the order of processing reflects the order of arrival of elements (also referred to as first come, first serve) queues to be implemented, for instance, as arrays (in case the maximum size can be predicted in advance) linked lists PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

25 Queues implementation of queues assume, there s a primitive queue (of fixed size n) implemented as array further assumptions and requirements are necessary it s not possible to insert an element into a full queue it s not possible to remove an element from an empty queue variable used indicates the number of already used cells indices first and last indicate the first and the last used element in a queue ( circular array: wraparound back to 0 at end of array) used 5 array index last 1 first size n 10 hence, operations insert and remove ready to be implemented PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

26 Queues implementation of queues (cont d) insert (here with variables n, used, first, and last with global visibility ) procedure INSERT (Q, val) if used n then last last 1 if last n then last 0 fi Q(last) val used used 1 fi end where Q indicates a queue and val the value to be inserted into the queue note: there s no error in case queue is full PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

27 Queues implementation of queues (cont d) remove (here with variables n, used, first, and last with global visibility ) procedure REMOVE (Q) tmp false if used 0 then tmp Q(first) used used 1 first first 1 if first n then first 0 fi fi return (tmp) end where Q indicates a queue PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

28 overview prelude linked lists stacks queues trees PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

29 Trees fundamentals definition: a tree is a finite set of nodes such that 1) there is one specially designated node called root 2) remaining nodes are partitioned into n 0 disjoint sets T 1,, T n where each of these sets is a tree (so called subtree of the root) 3) there exists exactly one path between the root and each of the other nodes in the tree root links between nodes might point downwards (away from the root) or upwards (towards the root) depending upon the application PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

30 Trees fundamentals (cont d) further definitions each node (except the root) has exactly one node above it which is called its parent hence, the nodes directly below a node are called its children nodes with no children are called leaves or terminal nodes hence, nodes with children are called internal or non terminal nodes parent children internal nodes leaves PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

31 Trees fundamentals (cont d) further definitions children of the same parent are said to be siblings a forest is a set of n 0 disjoint trees (removing the root of a tree leads to a forest) the level of a node is defined by initially letting the root be at level one; hence, if a node is at level k, then its children are at level k 1 the height or depth of a tree is the maximum level of any node in the tree level 1 level 2 siblings level 3 height 3 PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

32 Trees representation of trees idea: using linked lists where one node in the list corresponds to one node in the tree problem: nodes can have a varying number of links difficult to write algorithms for data structures with varying sizes hence, already known list elements to be extended by one additional link as follows value siblings children PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

33 Trees representation of trees (cont d) example A B E G C D F H I J HEAD A B E G C D F H I J i.e. link pointing to NIL PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

34 Trees binary trees definition: a binary tree is a finite set of nodes which is either empty or consists of a root node and two disjoint binary trees called the left and right subtree hence, any node can have at most two children ( name binary tree ) examples of binary trees skewed binary tree binary tree full binary tree PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

35 Trees binary trees (cont d) properties a tree with n nodes has n 1 edges (i.e. links); this is true for all kind of trees and follows directly from the recursive definition max. number of nodes n in a full binary tree of depth k 0 is 2 k 1 the height of a full binary tree with n nodes is about ld(n) (i.e. log 2 (n)) for representing binary trees, linked lists can be used again (labelling one link as left and one link as right) value left right drawback: determination of node s parent due to missing upward link PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

36 Trees binary trees (cont d) example A B F HEAD C G A D E B F C G D E i.e. link pointing to NIL PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

37 Trees binary trees (cont d) adding a node to a binary tree is a quite simple task 1) find a corresponding node X with at least one free link left or right 2) link from X to the new node Y, thus, X becomes parent of Y Y X X Y PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

38 Trees binary trees (cont d) deleting a node from a binary tree is a more complex task to be distinguished a) deleting a leaf node b) deleting an internal node with one child c) deleting an internal node with two children cases a) and b) are quite easy to process, but case c) requires further understanding case a) case b) case c) PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

39 Trees binary trees (cont d) case a: deleting a leaf node 1) find the corresponding parent of the leaf node to be deleted 2) set the parent s link to NIL node to be deleted PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

40 Trees binary trees (cont d) case b: deleting an internal node with one child 1) find the corresponding parent of the node to be deleted 2) set parent s link to child of the node to be deleted node to be deleted PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

41 Trees binary trees (cont d) case c: deleting an internal node with two children 1 1) find the in order successor (IOS) of the node to be deleted 2) copy IOS to the node to be deleted 3) i. if IOS has no children, simply delete it ii. if IOS has a right child ( ), set IOS s parent ( ) to IOS s right child node to be deleted in order successor IOS 1 as suggested by T. HIBBARD in 1962, guarantying that the heights of the subject subtrees are changed by at most one PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

42 overview prelude linked lists stacks queues trees PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA 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 information

TREES. Trees - Introduction

TREES. 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 information

MID 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. 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 information

CS301 - Data Structures Glossary By

CS301 - 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 information

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

Computer 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 information

3. Fundamental Data Structures

3. Fundamental Data Structures 3. Fundamental Data Structures CH08-320201: Algorithms and Data Structures 233 Data Structures Definition (recall): A data structure is a way to store and organize data in order to facilitate access and

More information

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

8. 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 information

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

Data 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 information

Data Abstractions. National Chiao Tung University Chun-Jen Tsai 05/23/2012

Data 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 information

12 Abstract Data Types

12 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 information

Data Structure. IBPS SO (IT- Officer) Exam 2017

Data 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 information

Postfix (and prefix) notation

Postfix (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 information

Stacks, Queues and Hierarchical Collections

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 information

Chapter 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. 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 information

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

Stacks, Queues and Hierarchical Collections. 2501ICT Logan Stacks, Queues and Hierarchical Collections 2501ICT Logan Contents Linked Data Structures Revisited Stacks Queues Trees Binary Trees Generic Trees Implementations 2 Queues and Stacks Queues and Stacks

More information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

FORTH 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 information

CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial

CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial Week 7 General remarks Arrays, lists, pointers and 1 2 3 We conclude elementary data structures by discussing and implementing arrays, lists, and trees. Background information on pointers is provided (for

More information

UNIT IV -NON-LINEAR DATA STRUCTURES 4.1 Trees TREE: A tree is a finite set of one or more nodes such that there is a specially designated node called the Root, and zero or more non empty sub trees T1,

More information

Section 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. 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 information

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

MIDTERM 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 information

Data Structure - Binary Tree 1 -

Data 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 information

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Tree. 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 information

Recursive Data Structures and Grammars

Recursive 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 information

DEEPIKA KAMBOJ UNIT 2. What is Stack?

DEEPIKA 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 information

CE 221 Data Structures and Algorithms

CE 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 information

LECTURE 11 TREE TRAVERSALS

LECTURE 11 TREE TRAVERSALS DATA STRUCTURES AND ALGORITHMS LECTURE 11 TREE TRAVERSALS IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD BACKGROUND All the objects stored in an array or linked list can be accessed sequentially

More information

An Introduction to Trees

An 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 information

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

EC8393FUNDAMENTALS 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 information

Linear Data Structure

Linear Data Structure Linear Data Structure Definition A data structure is said to be linear if its elements form a sequence or a linear list. Examples: Array Linked List Stacks Queues Operations on linear Data Structures Traversal

More information

Summer Final Exam Review Session August 5, 2009

Summer Final Exam Review Session August 5, 2009 15-111 Summer 2 2009 Final Exam Review Session August 5, 2009 Exam Notes The exam is from 10:30 to 1:30 PM in Wean Hall 5419A. The exam will be primarily conceptual. The major emphasis is on understanding

More information

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:

STACKS. 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

Section Summary. Introduction to Trees Rooted Trees Trees as Models Properties of Trees

Section 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 information

CS8391-DATA STRUCTURES QUESTION BANK UNIT I

CS8391-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 information

CSE 230 Intermediate Programming in C and C++

CSE 230 Intermediate Programming in C and C++ CSE 230 Intermediate Programming in C and C++ Structures and List Processing Fall 2017 Stony Brook University Instructor: Shebuti Rayana http://www3.cs.stonybrook.edu/~cse230/ Self-referential Structure

More information

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1 Some Applications of Stack Spring Semester 2007 Programming and Data Structure 1 Arithmetic Expressions Polish Notation Spring Semester 2007 Programming and Data Structure 2 What is Polish Notation? Conventionally,

More information

6-TREE. Tree: Directed Tree: A directed tree is an acyclic digraph which has one node called the root node

6-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 information

Fundamentals of Data Structure

Fundamentals of Data Structure Fundamentals of Data Structure Set-1 1. Which if the following is/are the levels of implementation of data structure A) Abstract level B) Application level C) Implementation level D) All of the above 2.

More information

Department of Computer Science and Technology

Department 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 information

Data Structures Question Bank Multiple Choice

Data 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 information

[ DATA STRUCTURES ] Fig. (1) : A Tree

[ DATA STRUCTURES ] Fig. (1) : A Tree [ DATA STRUCTURES ] Chapter - 07 : Trees A Tree is a non-linear data structure in which items are arranged in a sorted sequence. It is used to represent hierarchical relationship existing amongst several

More information

CS8391-DATA STRUCTURES

CS8391-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 information

CS 171: Introduction to Computer Science II. Binary Search Trees

CS 171: Introduction to Computer Science II. Binary Search Trees CS 171: Introduction to Computer Science II Binary Search Trees Binary Search Trees Symbol table applications BST definitions and terminologies Search and insert Traversal Ordered operations Delete Symbol

More information

V Advanced Data Structures

V Advanced Data Structures V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,

More information

Chapter Summary. Introduction to Trees Applications of Trees Tree Traversal Spanning Trees Minimum Spanning Trees

Chapter Summary. Introduction to Trees Applications of Trees Tree Traversal Spanning Trees Minimum Spanning Trees Trees Chapter 11 Chapter Summary Introduction to Trees Applications of Trees Tree Traversal Spanning Trees Minimum Spanning Trees Introduction to Trees Section 11.1 Section Summary Introduction to Trees

More information

Stack Abstract Data Type

Stack Abstract Data Type Stacks Chapter 5 Chapter Objectives To learn about the stack data type and how to use its four methods: push, pop, peek, and empty To understand how Java implements a stack To learn how to implement a

More information

infix expressions (review)

infix expressions (review) Outline infix, prefix, and postfix expressions queues queue interface queue applications queue implementation: array queue queue implementation: linked queue application of queues and stacks: data structure

More information

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE A6-R3: DATA STRUCTURE THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered in the TEAR-OFF

More information

Algorithms and Data Structures

Algorithms 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 4: Searching source: pinterest.com

More information

First 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... 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 information

V Advanced Data Structures

V Advanced Data Structures V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,

More information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

FORTH 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 information

Binary Trees, Binary Search Trees

Binary 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 information

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang)

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang) Bioinformatics Programming EE, NCKU Tien-Hao Chang (Darby Chang) 1 Tree 2 A Tree Structure A tree structure means that the data are organized so that items of information are related by branches 3 Definition

More information

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

Revision 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 information

DATA STRUCTURE AND ALGORITHM USING PYTHON

DATA STRUCTURE AND ALGORITHM USING PYTHON DATA STRUCTURE AND ALGORITHM USING PYTHON Advanced Data Structure and File Manipulation Peter Lo Linear Structure Queue, Stack, Linked List and Tree 2 Queue A queue is a line of people or things waiting

More information

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO) Outline stacks stack ADT method signatures array stack implementation linked stack implementation stack applications infix, prefix, and postfix expressions 1 Stacks stacks of dishes or trays in a cafeteria

More information

Chapter 8: Data Abstractions

Chapter 8: Data Abstractions Chapter 8: Data Abstractions Computer Science: An Overview Eleventh Edition by J. Glenn Brookshear Copyright 2012 Pearson Education, Inc. Chapter 8: Data Abstractions 8.1 Data Structure Fundamentals 8.2

More information

Outline. Introduction Stack Operations Stack Implementation Implementation of Push and Pop operations Applications. ADT for stacks

Outline. Introduction Stack Operations Stack Implementation Implementation of Push and Pop operations Applications. ADT for stacks Stack Chapter 4 Outline Introduction Stack Operations Stack Implementation Implementation of Push and Pop operations Applications Recursive Programming Evaluation of Expressions ADT for stacks Introduction

More information

Abstract 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 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 information

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this Lecture Notes Array Review An array in C++ is a contiguous block of memory. Since a char is 1 byte, then an array of 5 chars is 5 bytes. For example, if you execute the following C++ code you will allocate

More information

CS 8391 DATA STRUCTURES

CS 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 information

Solution: The examples of stack application are reverse a string, post fix evaluation, infix to postfix conversion.

Solution: The examples of stack application are reverse a string, post fix evaluation, infix to postfix conversion. 1. What is the full form of LIFO? The full form of LIFO is Last In First Out. 2. Give some examples for stack application. The examples of stack application are reverse a string, post fix evaluation, infix

More information

Formal Languages and Automata Theory, SS Project (due Week 14)

Formal 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 information

Trees. (Trees) Data Structures and Programming Spring / 28

Trees. (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 information

Name CPTR246 Spring '17 (100 total points) Exam 3

Name 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 information

CS-301 Data Structure. Tariq Hanif

CS-301 Data Structure. Tariq Hanif 1. The tree data structure is a Linear data structure Non-linear data structure Graphical data structure Data structure like queue FINALTERM EXAMINATION Spring 2012 CS301- Data Structure 25-07-2012 2.

More information

Binary Search Tree (2A) Young Won Lim 5/17/18

Binary Search Tree (2A) Young Won Lim 5/17/18 Binary Search Tree (2A) Copyright (c) 2015-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or

More information

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures

More information

Problem with Scanning an Infix Expression

Problem with Scanning an Infix Expression Operator Notation Consider the infix expression (X Y) + (W U), with parentheses added to make the evaluation order perfectly obvious. This is an arithmetic expression written in standard form, called infix

More information

CISC

CISC CISC-235 20180115+17+19 Much of the material we covered this week was already posted in the notes for last week. These notes take up where those left off, and fill in some gaps. We have discussed the notation

More information

Linked List Implementation of Queues

Linked List Implementation of Queues Outline queue implementation: linked queue application of queues and stacks: data structure traversal double-ended queues application of queues: simulation of an airline counter random numbers recursion

More information

COMP : Trees. COMP20012 Trees 219

COMP : Trees. COMP20012 Trees 219 COMP20012 3: Trees COMP20012 Trees 219 Trees Seen lots of examples. Parse Trees Decision Trees Search Trees Family Trees Hierarchical Structures Management Directories COMP20012 Trees 220 Trees have natural

More information

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May www.jwjobs.net R10 SET - 1 II B. Tech I Semester, Supplementary Examinations, May - 2012 (Com. to CSE, IT, ECC ) Time: 3 hours Max Marks: 75 *******-****** 1. a) Which of the given options provides the

More information

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures. Trees Q: Why study trees? : Many advance DTs are implemented using tree-based data structures. Recursive Definition of (Rooted) Tree: Let T be a set with n 0 elements. (i) If n = 0, T is an empty tree,

More information

3137 Data Structures and Algorithms in C++

3137 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 information

Tree. Virendra Singh Indian Institute of Science Bangalore Lecture 11. Courtesy: Prof. Sartaj Sahni. Sep 3,2010

Tree. 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 information

Basic Data Structures (Version 7) Name:

Basic 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 information

Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College!

Trees! 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 information

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging. Priority Queue, Heap and Heap Sort In this time, we will study Priority queue, heap and heap sort. Heap is a data structure, which permits one to insert elements into a set and also to find the largest

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA 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 information

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

Tree: 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 information

Draw a diagram of an empty circular queue and describe it to the reader.

Draw a diagram of an empty circular queue and describe it to the reader. 1020_1030_testquestions.text Wed Sep 10 10:40:46 2014 1 1983/84 COSC1020/30 Tests >>> The following was given to students. >>> Students can have a good idea of test questions by examining and trying the

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2008S-19 B-Trees David Galles Department of Computer Science University of San Francisco 19-0: Indexing Operations: Add an element Remove an element Find an element,

More information

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1 Data Structure using C++ Lecture 04 Reading Material Data Structures and algorithm analysis in C++ Chapter. 3 3.1, 3.2, 3.2.1 Summary Infix to Postfix Example 1: Infix to Postfix Example 2: Postfix Evaluation

More information

Lecture 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 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 information

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302 Topics VCU, Department of Computer Science CMSC 302 Trees Vojislav Kecman Terminology Trees as Models Some Tree Theorems Applications of Trees Binary Search Tree Decision Tree Tree Traversal Spanning Trees

More information

INF2220: algorithms and data structures Series 1

INF2220: algorithms and data structures Series 1 Universitetet i Oslo Institutt for Informatikk I. Yu, D. Karabeg INF2220: algorithms and data structures Series 1 Topic Function growth & estimation of running time, trees Issued: 24. 08. 2016 Exercise

More information

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

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 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 information

Objective 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) 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 information

COMP 250 Fall binary trees Oct. 27, 2017

COMP 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 information

Introduction. Problem Solving on Computer. Data Structures (collection of data and relationships) Algorithms

Introduction. Problem Solving on Computer. Data Structures (collection of data and relationships) Algorithms Introduction Problem Solving on Computer Data Structures (collection of data and relationships) Algorithms 1 Objective of Data Structures Two Goals: 1) Identify and develop useful high-level data types

More information

Prefix/Infix/Postfix Notation

Prefix/Infix/Postfix Notation Prefix/Infix/Postfix Notation One commonly writes arithmetic expressions, such as 3 + 4 * (5-2) in infix notation which means that the operator is placed in between the two operands. In this example, the

More information

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

1. 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 information

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

E.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 information

Binary Trees. Height 1

Binary 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 information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS LECTURE 11 Babeş - Bolyai University Computer Science and Mathematics Faculty 2017-2018 In Lecture 10... Hash tables Separate chaining Coalesced chaining Open Addressing Today 1 Open addressing - review

More information

The Stack and Queue Types

The 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 information

CSI33 Data Structures

CSI33 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 information

Copyright 1998 by Addison-Wesley Publishing Company 147. Chapter 15. Stacks and Queues

Copyright 1998 by Addison-Wesley Publishing Company 147. Chapter 15. Stacks and Queues Copyright 1998 by Addison-Wesley Publishing Company 147 Chapter 15 Stacks and Queues Copyright 1998 by Addison-Wesley Publishing Company 148 tos (-1) B tos (1) A tos (0) A A tos (0) How the stack routines

More information

PA3 Design Specification

PA3 Design Specification PA3 Teaching Data Structure 1. System Description The Data Structure Web application is written in JavaScript and HTML5. It has been divided into 9 pages: Singly linked page, Stack page, Postfix expression

More information