Types of Data Structures


 Jared Mosley
 1 years ago
 Views:
Transcription
1 DATA STRUCTURES material prepared by: MUKESH BOHRA Follow me on FB : The logical or mathematical model of data is called a data structure. In other words, a data structure is a way to store and organize data in a computer system so that it can be used efficiently. Data structures are the building blocks of a program. The selection of a particular data structure will help the programmer to design more efficient programs. A data structure has a welldefined operations, behaviour & properties. Common operations on a Data Structure: Traversal Read / Write Insertion Deletion Searching Sorting Reversing Merging Copying Concatenation Counting/length etc. Types of Data Structures Linear Data structures elements form a sequence Array Linked List Stack (LIFO List) Queue (FIFO List) Non Linear Data Structures represent hierarchical relationships Trees Graphs ARRAYS An array is a finite collection of similar elements stored in contiguous memory locations. Arrays are useful when the number of elements to be stored is fixed. An array always needs to be declared with fixed dimension/size prior to its use. Array elements can be accessed using index (subscript) value. In C++, indexing begins with 0 always. The address of the first element of an array (i.e. element at 0 th index) is called its base address. In C++, array indexing begins with 0 (lower bound) & goes till N1 (upper bound), where N is the total number of elements (or the size of the array). Cost of accessing an element: Irrespective of the size of the array, it takes constant time to access any element in the array. If the base address (B) of the array & size of its data type (W) is known, then the address of any element (say A[i]) can be calculated using the simple formula. Address of A[i] = B + W * i An array of characters is often known as a string D arrays: A 2D array is a collection of elements placed in N rows & M columns. It s sometimes also called a matrix. In other words, a 2D array is just a collection of a number of 1D arrays placed one after another. The syntax used to declare a 2D array includes two indices, of which one specifies the no. of rows and the other specifies the no. of columns. Page 1
2 In memory, 2D arrays are also stored in a linear contiguous chain. This leads to two possible arrangements of elements in memory row major arrangement & column major arrangement. C++ permits 2D arrays to be stored in row major arrangement only. The address of the first element of a 2D array (i.e. address of A[0][0]) is called its base address. Cost of accessing an element: Irrespective of the size/dimensions of the array, it takes constant time to access any element in the array. If the base address (B) of an array, its dimensions (number of rows & columns) & the wordsize (W) are known, then the address of any element can be calculated using the simple formula. Formula for address calculation in 2D arrays In Row Major Arrangement (row wise) Address of a[i][j] = B + W ( i *col + j ) OR Address of a[i][j] = B + W [( i Lr)* col + ( jlc)] Page 2 In Column Major Arrangement (column wise) Address of a[i][j] = B + W ( j *row + i ) OR Address of a[i][j] = B + W [( j Lc)* row + (i Lr)] Here, Lr = Lower Bound of Row (i.e. first row number) and Lc = Lower Bound of Column (i.e. first column number) //Note: In case of Lr & Lc, don t forget to calculate the total no of rows & columns PROBLEMS Problem 1: An array S[40][30] is stored in the memory along the row with each of the element occupying 2 bytes, find out the memory location for the element S[20][10], if the base address of the array is Solution: Here, Base Address, B = 5000 Word Size, W = 2 bytes Array S[40][30] is stored along the row ROW = 40, COL = 30. add. of (S[20][10]) =? Formula for address calculation (rowwise arrangement) add (S[i][j]) = B + W (i * COL + j) add (S[20][10])= *(20* ) = *(600+10) = = 6220 Problem 2: An array S[1.40][10.30] is stored in the memory along the row with each of the element occupying 2 bytes, find out the memory location for the element S[20][10], if the base address of the array is Solution: Here, Base Address, B = 5000 Word Size, W = 2 bytes Array S[1 40][10 30] is stored along the row Total no. of ROW = =40 Total no. of COL = =21 Lr = 1, Lc= 10 add. of (S[20][10]) =? Formula for address calculation (rowwise arrangement) add.of (S[i][j]) = B + W [(ilr) * COL + (jlc)]
3 add. Of (S[20][10]) = [(201)*21 + (1010)] = [ ] = = 5798 Problem 3: An array A[50][60] is stored in the memory along the column with each of the element occupying 4 bytes, find out the memory location for the element S[20][10], if the address of A[15][30] is Solution: Here, Base Address, B =? Word Size, W = 4 bytes Array A[50][60] is stored along the column ROW = 50, COL = 60. add. of (A[15][30]) = 1000 add. of (A[20][10]) =?? Formula for address calculation (Colwise arrangement) add (A[i][j]) = B + W (j * ROW + i) add (A[15][30])= B + 4*(30 * ) = *( ) = *(1515) = SEARCHING AND SORTING: Searching Techniques LINEAR SEARCH (on sorted as well as unsorted list) BINARY SEARCH (only on sorted list) Linear Search Sorting Techniques INSERTION SORT SELECTION SORT BUBBLE SORT Binary Search void Lsearch( int A[], int n) int x, i, found=0; cout<<"enter the element to be searched for: "; cin>>x; for(i=0; i< n; i++) if(x==a[i]) found=1; cout<<"search SUCCESSFUL! ; cout<<"\n Element Found at <<(i+1)<< position ; break; if(found==0) cout<<"\nelement NOT FOUND!!"; void Bsearch( int A[], int n) int x, i=0, j= n1, mid, found=0; cout<<"enter the element to be searched for: "; cin>>x; while(i<= j) // till i & j are crossing each other mid=(i+j)/2; if(x==a[mid]) found=1; cout<<"search SUCCESSFUL! ; cout<<"\n Element Found at <<(mid+1)<< position ; break; else if(x<a[mid]) // if x lies in left half j = mid1; else if(x>a[mid]) // if x lies in right half i = mid+1; if(found==0) cout<<"\nelement NOT FOUND!!"; Page 3
4 Selection Sort (ASC order) void selsort ( int A[], int n) int i, j, temp, p; for(i=0; i<n; i++) // i<n1 will also have the effect. for (j=i+1; j<n; j++ ) // note j=i+1; if ( A[j] < A[i]) // OR... if ( A[i] > A[j] ) temp=a[i]; A[i]=A[j]; A[j]=temp; cout<<"\nelements after iteration "<<(i+1)<<" are:"<<endl; for(p=0; p<n; p++) // loop to print the array elements after each iteration cout<<a[p]<<'\t'; cout<<"\n\nthe SORTED LIST IN ASCENDING ORDER is:"<<endl; for(p=0; p<n; p++) // loop to display the sorted list cout<<a[p]<<"\t"; Bubble Sort (ASC order) void bsort ( int A[], int n) int i, j, temp, p; for(i=0; i<n; i++) // i< n1 will also have the same effect. for (j=0; j<n1  i; j++ ) //Note: j< n1  i if( A[j] > A[j+1] ) // Note: jindex is used in the comparison. temp=a[j]; A[j]=A[j+1]; A[j+1]=temp; cout<<"\nelements after iteration "<<(i+1)<<" are:"<<endl; for(p=0; p<n; p++) // loop to print the array elements after each iteration cout<<a[p]<<"\t"; cout<<"\n\nthe SORTED LIST IN ASCENDING ORDER is:"<<endl; for(p=0; p<n; p++) // loop to display the sorted list cout<<a[p]<<"\t"; Page 4
5 Insertion Sort (ASC order) void isort ( int A[], int n) int i, j, k, temp, p; for(i=1; i<n; i++) for (j=0; j<i; j++ ) // Note i=1; // every time the i th element will be compared to // all elements appearing before the i th index if ( A[i] < A[j] ) // A[j] left end, A[i] right end temp=a[i]; // smaller ele. copied to temp for(k=i; k>j; k) // loop to shift other ele. b/w A[j] & A[i] one place rightside. A[k]=A[k1]; A[k]=temp; // value stored in temp is inserted at the free place // created after shifting elements. cout<<"\nelements after iteration "<<i<<" are:"<<endl; for(p=0; p<n; p++) // loop to print the array elements after each iteration cout<<a[p]<< "\t"; cout<<"\n\nthe SORTED LIST IN ASCENDING ORDER is:"<<endl; for(p=0; p<n; p++) // loop to display the sorted list cout<<a[p]<<"\t"; Page 5
6 LINKED LIST Need of Linked List: We need to know the size of the array before its creation because array is created as one contiguous block of memory. i.e. arrays have a fixed size. Once the size of an array is decided it cannot be increased or decreased during execution. Arrays are always stored in contiguous memory locations. At times it may happen that enough contiguous locations might not be available for the array. Operations like insertion / deletion in array are tedious. (requires shifting of elements) A linked list overcomes all these disadvantages. A linked list is a linear collection of specially designed elements called nodes; each of which stores two items of information  an element of the list (data part) and a link (pointer) to the next node. head NULL A linked list can grow as well as shrink in size during its lifetime. Linked lists are used preferably when the quantity of data is not known prior to execution. Defining each node of a linked list: In linked lists, data is stored in the form of nodes (selfreferential structure) and at runtime, memory is allocated for creating nodes using new operator. The data can be accessed using the head/start pointer of the list. struct node int data; node *link; // data part // link part *head; Page 6
7 STACK A stack is a linear data structure in which addition of new element or deletion of an existing element takes place at the same end. This end is often known as the top of the stack. The stack is sometimes also called as LIFO List (LastInFirstOut), because the last element pushed into the stack is the first one to be popped out. Operations on a stack Operation PUSH POP DESCRIPTION To insert an element at the top of the stack To remove an existing element from the top of the stack STACK IMPLEMENTATION Static implementation (using arrays) Dynamic implementation (using pointers) PUSH() and POP() function definitions (using arrays) void stack :: push ( ) if ( top == MAX  1 ) cout << "Stack is full" ; exit(1); top= top+ 1 ; cout<< Enter the data item: ; cin>>arr[top] ; void stack :: pop( ) if ( top == 1 ) cout << "Stack is empty" ; exit(1) ; int d = arr[top] ; top = top  1 ; cout<< Popped item is: <<d; PUSH() and POP() function definitions (using pointers) void stack :: push ( ) node *temp ; temp = new node ; // dynamic allocation if (temp == NULL) cout<< Node can t be created : exit(1); cout<< Enter the data item: ; cin>>temp > data ; temp > link = top ; //making temp point to the top top = temp ; //top pointer is made to point to temp // means temp is the new top now. void stack :: pop( ) if ( top == NULL ) cout<< "Stack is empty" ; exit(1) ; node *temp ; temp = top ; cout<< Popped item is: << top > data; top = top > link ; //resetting the top pointer by // making it point to second last node delete temp ; //freeing the popped node Page 7
8 QUEUE Queue is linear data structure that permits insertion of new element at one end (called rear of the queue) and deletion of an existing element at the other end (called front of the queue). Queues are sometimes also called FIFO List (FirstInFirstOut). Operations on a queue Operation Insertion DESCRIPTION To add a new element at the rear Deletion To remove an element from the front QUEUE IMPLEMENTATION Static implementation (using arrays) INSERT and DELETE function definitions (using arrays) void queue :: insertq ( ) if ( rear == MAX  1 ) cout << "Queue is full" ; exit(1); if ( rear == 1 ) // or front == 1 //when the node to be inserted is the very 1 st node. rear =front = 0 ; else rear = rear + 1 ; cout<< Enter the data item: ; cin>>arr[rear] ; void queue :: deleteq( ) if ( front == 1 ) cout << "Queue is Empty" ; exit(1) ; int d = arr[front] ; arr[front] = 0 ; if ( front == rear ) //when the node to be deleted is the ONLY node. front = rear = 1 ; else front = front + 1; ; cout<< deleted item is: <<d; Dynamic implementation (using pointers) INSERT and DELETE function definitions (using pointers) void queue :: insertq ( ) node *temp ; temp = new node ; // dynamic allocation if (temp == NULL) cout<< Node can t be created : exit(1); cout<< Enter the data item: ; cin>>temp > data ; temp>link = NULL; // temp is going to be the last node. if ( rear == NULL ) //or front ==NULL //when the node to be inserted is the very 1 st node. rear = front = temp ; else rear > link = temp ; //rear s link part gets //address of temp node rear = temp ; // temp will be the new rear now void queue :: deleteq( ) if ( front == NULL ) cout << "Queue is empty" ; exit(1) ; node *temp ; temp = front ; cout<< deleted item is: << front > data ; if ( front == rear) //when the node to be deleted is the ONLY node. front = rear = NULL; else front = front > link ; // front is now made to //point to the node whose address is in its link part. // means new front is the second element now. delete temp; //freeing up the deleted node Page 8
9 APPLICATIONS OF STACKS The place where stacks are frequently used is in evaluation of arithmetic expression. Arithmetic expressions: An arithmetic expression consists of operands (data values or variables) & operators. The operators used in an arithmetic expression represent the operations like addition, subtraction, multiplication, division, and exponentiation. Types of Expressions: Infix expression: These are the general mathematical expressions in which the operator is written between the operands. e.g. A + B, A* B, 2+3, etc. In complex expressions, an operand may be an expression as well. e.g. (A+B) * C, one of the operands of * operation is an expression itself. While evaluating a complex infix expression an ambiguity generally occurs, this can be resolved by using certain operator precedence rules. e.g. consider the following expression, * 5, it can be evaluated in two ways: 2+ 3 * 5 = 5 * 5 = *5 = = 17 This ambiguity can be resolved using the operator precedence rules. Operator Precedence: 1 Exponent (^) Right to Left associativity 2 Multiplication, Division Left to Right associativity 3 Addition, Subtraction Left to Right associativity The priorities can be overridden by using a pair of parenthesis. e.g. the following expression * 5 can be solved as per operator precedence as: * 5 = = 17 (as multiplication has higher priority than Addition) But if we put within a pair of parenthesis, then addition needs to be performed first. (2 + 3) * 5 = 5 * 5 = 25 (Brackets evaluated first). Prefix expression (Polish Notation): Operator comes before the operands. e.g. A+B can be represented in prefix notation as : + A B 2+3 *5 can be represented in prefix notation as : + 2 * 3 5 (2+3)*5 can be represented in prefix notation as : * Postfix expression (Reverse Polish Notation): Operator comes after the operands. e.g. A+B can be represented in prefix notation as : A B *5 can be represented in prefix notation as : * + (2+3)*5 can be represented in prefix notation as : * Features of Prefix & Postfix expressions: The operands maintain the same order as in the equivalent infix expression. While evaluating the expression the priority of the operators is irrelevant. Parenthesis are not needed to designate the expression unambiguously. Page 9
10 INFIX TO POSTFIX CONVERSION Algorithm: i) The original infix expression is first stored in a string (infixexp). ii) A char pointer (char *s = infixexp) is made to point to the first character of the input string. iii) Every character of the input string is parsed /scanned with the help of a loop (while(*s) ) till its end is reached. iv) In each iteration, the following steps are performed depending upon the type of character scanned: (a) If the character scanned happens to be a space then that character is skipped. (b) If character scanned is a digit or an alphabet, it is appended to the target string (meant to store the postfix exp). (c) If the character scanned is a closing parenthesis, then it is pushed into the stack. (d) If character scanned happens to be an operator, then firstly, the topmost element of the stack is popped out. The priorities of the character scanned & the character popped are compared. Then, the following steps are performed as per the precedence rule: If the character scanned has the higher priority than the popped character, then the popped character is pushed back into the stack followed by the scanned character on its top. e.g. suppose the stack contents are as follows: char scanned: * Priority of * & + are compared (high) & are pushed back to stack (as shown below) If the character scanned has the same & lower priority than the popped character, then the popped character is appended to the target string whereas the scanned character is pushed into the stack. e.g. suppose the stack char scanned:  contents are as follows: Priority of  & + are compared (same) & then + is appended to the target string &  is pushed into the stack. e.g. suppose the stack contents are as follows: char scanned:  Priority of  & * are compared (low) & then * is appended to the target string &  is pushed into the stack. Page 10
11 (e) If character scanned happens to be an opening parenthesis, then the operators present in the stack are popped out & appended to the target string, till a closing parenthesis is encountered. v) Repeat step (iv) until the end of the input string is reached. vi) Finally, the target string obtained is the equivalent postfix notation of the input expression EVALUATION OF POSTFIX EXPRESSION The postfix notation enables easy evaluation of expressions. Firstly, the need of parenthesis is eliminated. Secondly, the priority of the operators is no longer relevant. Also the evaluation can be done by parsing the expression from left to right. (A prefix exp. to be parsed from right to left). Function to Evaluate the Postfix Expression void postfix :: calculate( ) int n1, n2, n3 ; while ( *s ) // s is pointer to character scanned if ( *s == ' ' *s == '\t' ) // skip whitespace, if any s++ ; continue ; if ( isdigit ( *s ) ) // if digit is encountered nn = *s  '0' ; // char int conversion push ( nn ) ; else // if operator is encountered n1 = pop( ) ; n2 = pop( ) ; switch ( *s ) case '+' : n3 = n2 + n1 ; break ; case '' : n3 = n2  n1 ; break ; case '/' : n3 = n2 / n1 ; break ; case '*' : n3 = n2 * n1 ; break ; case '%' : n3 = n2 % n1 ; break ; case '$' : n3 = pow ( n2, n1 ) ; break ; default : cout << "Unknown operator" ; exit ( 1 ) ; // end of switch push ( n3 ) ; // end of else s++ ; // end of while ********************* Page 11
12 Problem 1: PROBLEMS Convert the following infix expression into postfix form: A + ( B * C ( D / E ^ F ) * G ) * H Char scanned Stack contents Target String A EMPTY A + + top A ( +( top A B +( top AB * +(* top AB C +(* top ABC  +( top ABC* ( +( ( top ABC* D +( ( top ABC*D / +( ( / top ABC*D E +( ( / top ABC*DE ^ +( ( / ^ top ABC*DE F +( ( / ^ top ABC*DEF ) +( top ABC*DEF^/ * +(* top ABC*DEF^/ G +(* top ABC*DEF^/G ) + top ABC*DEF^/G* * +* top ABC*DEF^/G* H +* top ABC*DEF^/G*H ABC*DEF^/G*H*+ Note: At the end, when all the characters gets scanned, pop out the left over operators from the stack & append them in the target string. Hence, the postfix notation of the given infix expression is: A B C * D E F ^ / G *  H * + Problem 2: Evaluate the following postfix expression (Show the status of stack after execution of each operation): 15, 3, 2, +, /, 7, +, 2, * Operand Operation Stack Contents 15 Push(15) 15 top 3 Push(3) 15, 3 top 2 Push(2) 15, 3, 2 top + n1=pop() 15, 5 top n2=pop() n2+n1=3+2=5 Push(5); / p1=pop() 3 top p2=pop() n2/n1=15/5=3 Push(3); 7 Push(7) 3, 7 top + n1=pop() 10 top n2=pop() n2+n1=3+7=10 Push(10); 2 Push(2) 10, 2 top * n1=pop() 20 top n2=pop() n2*n1=10*2=20 Push(20); Hence, the value of the given expression is: 20. Page 12
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 informationChapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning.
Chapter4: s Data: It is a collection of raw facts that has implicit meaning. Data may be single valued like ID, or multi valued like address. Information: It is the processed data having explicit meaning.
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 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 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 informationContent: Learning Objectives
1 BLOOM PUBLIC CHOOL Vasant Kunj, New Delhi Lesson Plan Class: XII ubject: Computer cience Month : July No of s: 21 Chapter:Data structure: Linked List TTT: 8 WT: 12 Content: Learning Objectives At the
More informationData 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 Stack Operations on a stack Representing stacks Converting an expression
More informationInfix to Postfix Conversion
Infix to Postfix Conversion Infix to Postfix Conversion Stacks are widely used in the design and implementation of compilers. For example, they are used to convert arithmetic expressions from infix notation
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 informationSolution: 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 informationFORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY OCTOBER, 2012 DATA STRUCTURE
TED (10)3071 Reg. No.. (REVISION2010) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY OCTOBER, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours (Maximum marks: 100)
More informationStacks, Queues (cont d)
Stacks, Queues (cont d) CSE 2011 Winter 2007 February 1, 2007 1 The Adapter Pattern Using methods of one class to implement methods of another class Example: using List to implement Stack and Queue 2 1
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.. (REVISION2010) (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 informationIntroduction. 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 highlevel data types
More informationDEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I 2 MARKS
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I 2 MARKS 1. Define global declaration? The variables that are used in more
More informationIntroduction to Arrays
Introduction to Arrays One Dimensional Array. Two Dimensional Array. Inserting Elements in Array. Reading Elements from an Array. Searching in Array. Sorting of an Array. Merging of 2 Arrays. What is an
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 informationStacks, 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 informationStacks, 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 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 informationSTACKS 3.1 INTRODUCTION 3.2 DEFINITION
STACKS 3 3.1 INTRODUCTION A stack is a linear data structure. It is very useful in many applications of computer science. It is a list in which all insertions and deletions are made at one end, called
More informationStacks (Section 2) By: Pramod Parajuli, Department of Computer Science, St. Xavier s College, Nepal.
(Section 2) Linked list implementation of stack Typical Application of stacks Evaluation of expressions (infix, postfix, prefix) References and further details By: Pramod Parajuli, Department of Computer
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 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 informationINSTITUTE OF AERONAUTICAL ENGINEERING
INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad  500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech
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 wordtoword as given in
More informationCS8391DATA STRUCTURES QUESTION BANK UNIT I
CS8391DATA 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 informationThe Stack ADT. Stacks. The Stack ADT. The Stack ADT. Set of objects in which the location an item is inserted and deleted is prespecified.
The Stack ADT Stacks Set of objects in which the location an item is inserted and deleted is prespecified Stacks! Insert in order! Delete most recent item inserted! LIFO  last in, first out Stacks 2 The
More informationCSE 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/ Selfreferential Structure
More informationWhere does the insert method place the new entry in the array? Assume array indexing starts from 0(zero).
Suppose we have a circular array implementation of the queue,with ten items in the queue stored at data[2] through data[11]. The current capacity of an array is 12. Where does the insert method place the
More informationDHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES
DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES UNIT III LINEAR DATA STRUCTURES PART A 1. What is meant by data
More informationData 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 informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Important Instructions to examiners: 1) The answers should be examined by key words and not as wordtoword as given in themodel answer scheme. 2) The model answer and the answer written by candidate may
More informationLecture No.04. Data Structures
Lecture No.04 Data Structures Josephus Problem #include "CList.cpp" void main(int argc, char *argv[]) { CList list; int i, N=10, M=3; for(i=1; i
More informationDATA STRUCTURE UNIT I
DATA STRUCTURE UNIT I 1. What is Data Structure? A data structure is a mathematical or logical way of organizing data in the memory that consider not only the items stored but also the relationship to
More informationRevision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,
[1] BigO 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 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 informationTop of the Stack. Stack ADT
Module 3: Stack ADT Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 Email: natarajan.meghanathan@jsums.edu Stack ADT Features (Logical View) A List that
More informationLinked List. April 2, 2007 Programming and Data Structure 1
Linked List April 2, 2007 Programming and Data Structure 1 Introduction head A linked list is a data structure which can change during execution. Successive elements are connected by pointers. Last element
More informationCS 171: Introduction to Computer Science II. Stacks. Li Xiong
CS 171: Introduction to Computer Science II Stacks Li Xiong Today Stacks operations and implementations Applications using stacks Application 1: Reverse a list of integers Application 2: Delimiter matching
More informationThere are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:
Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1123 +456 2. Long integers, of unlimited
More informationStacks. CONTENTS 3.1 Introduction 1. Stack as an abstract data type 2. Representation of a Stack as an array 3.2Applications of Stack.
Stacks CONTENTS 3.1 Introduction 1. Stack as an abstract data type 2. Representation of a Stack as an array 3.2Applications of Stack Hours: 12 Marks: 18 3.1 Introduction to Stacks 1. Stack as Abstract
More informationThe time and space are the two measure for efficiency of an algorithm.
There are basically six operations: 5. Sorting: Arranging the elements of list in an order (either ascending or descending). 6. Merging: combining the two list into one list. Algorithm: The time and space
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 realworld stack, for example a deck of cards
More informationTop of the Stack. Stack ADT
Module 3: Stack ADT Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 Email: natarajan.meghanathan@jsums.edu Stack ADT Features (Logical View) A List that
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 informationDS ata Structures Aptitude
DS ata Structures Aptitude 1. What is data structure? A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge
More informationStack. 4. In Stack all Operations such as Insertion and Deletion are permitted at only one end. Size of the Stack 6. Maximum Value of Stack Top 5
What is Stack? Stack 1. Stack is LIFO Structure [ Last in First Out ] 2. Stack is Ordered List of Elements of Same Type. 3. Stack is Linear List 4. In Stack all Operations such as Insertion and Deletion
More informationStack 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 informationColumns A[0] A[0][0] = 20 A[0][1] = 30
UNIT Arrays and Strings Part A (mark questions). What is an array? (or) Define array. An array is a collection of same data type elements All elements are stored in continuous locations Array index always
More informationData Structure. Chapter 3 Stacks and Queues. Department of Communication Engineering National Central University Jhongli, Taiwan.
Data Structure Chapter 3 Stacks and Queues Instructor: Angela ChihWei Tang Department of Communication Engineering National Central University Jhongli, Taiwan 29 Spring Outline Stack Queue A Mazing Problem
More informationLinear 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 informationS.Y. B.Sc. (IT) : Sem. III. Data Structures
S.Y. B.Sc. (IT) : Sem. III Data Structures Time : 2½ Hrs.] Prelim Question Paper Solution [Marks : 75 Q.1Attempt the following (any THREE) [15] Q.1(a) What is an algorithm? Write down characteristics of
More informationObjective Questions for Online Practical Exams under CBCS Scheme Subject: Data StructureI (CS113)
Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data StructureI (CS113) 1. The number of interchanges required to sort 5, 1, 6, 2 4 in ascending order using Bubble Sort (A)
More informationSTACKS AND QUEUES. Problem Solving with ComputersII
STACKS AND QUEUES Problem Solving with ComputersII 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 informationStacks. 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 informationProgramming and Data Structure Solved. MCQs Part 2
Programming and Data Structure Solved MCQs Part 2 Programming and Data Structure Solved MCQs Part 2 Unsigned integers occupies Two bytes Four bytes One byte Eight byte A weather forecasting computation
More informationAshish Gupta, Data JUET, Guna
Categories of data structures Data structures are categories in two classes 1. Linear data structure:  organized into sequential fashion  elements are attached one after another  easy to implement because
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äshavech notation) Infix notation is: operand operator
More informationData Types and Variables in C language
Data Types and Variables in C language Disclaimer The slides are prepared from various sources. The purpose of the slides is for academic use only Operators in C C supports a rich set of operators. Operators
More informationVisit ::: Original Website For Placement Papers. ::: Data Structure
Data Structure 1. What is data structure? A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge about the relationship
More informationData Structures. Chapter 06. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU
Data Structures Chapter 06 1 Stacks A stack is a list of elements in which an element may be inserted or deleted only at one end, called the top of the stack. This means that elements are removed from
More informationData Structures Week #3. Stacks
Data Structures Week #3 Stacks Outline Stacks Operations on Stacks Array Implementation of Stacks Linked List Implementation of Stacks Stack Applications October 5, 2015 Borahan Tümer, Ph.D. 2 Stacks (Yığınlar)
More informationCS8391DATA STRUCTURES
ST.JOSEPH COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERI NG CS8391DATA STRUCTURES QUESTION BANK UNIT I 2MARKS 1.Explain the term data structure. The data structure can be defined
More informationR10 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 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 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 informationLab 7 1 Due Thu., 6 Apr. 2017
Lab 7 1 Due Thu., 6 Apr. 2017 CMPSC 112 Introduction to Computer Science II (Spring 2017) Prof. John Wenskovitch http://cs.allegheny.edu/~jwenskovitch/teaching/cmpsc112 Lab 7  Using Stacks to Create a
More informationDATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.
DATA STRUCUTRES A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. An algorithm, which is a finite sequence of instructions, each of which
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 Through C. Student Workbook
Data Structures Through C Student Workbook Contents Lecture 1: C Revision I 01 Importance of data structures Data types in C Instructions and its types The decision control instruction Working of logical
More informationAnswers. 1. (A) Attempt any five : 20 Marks
Important Instructions to examiners: 1) The answers should be examined by key words and not as wordtoword as given in the model answer scheme. 2) The model answer and the answer written by candidate
More informationKENDRIYA VIDYALYA CLRI CHENNAI AUTUMN BREAK HOLIDAY HW MARKS QUESTIONS : DATA STRUCTURE
KENDRIYA VIDYALYA CLRI CHENNAI AUTUMN BREAK HOLIDAY HW 8 MARKS QUESTIONS : DATA STRUCTURE. Write a function in C++ which accepts an integer array and its size as arguments and change all the even number
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 DSEWEF2/13 25 MAY 2015 9.00 AM
More informationDATA STRUCTURES AND ALGORITHMS
LECTURE 8 Babeş  Bolyai University Computer Science and Mathematics Faculty 20172018 In Lecture 7... ADT Queue ADT Matrix ADT List ADT Stack Today ADT Queue 1 ADT Queue 2 3 4 Note ADT Queue We will not
More informationa) State the need of data structure. Write the operations performed using data structures.
Important Instructions to examiners: 1) The answers should be examined by key words and not as wordtoword as given in the model answer scheme. 2) The model answer and the answer written by candidate
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 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 informationCode No: R Set No. 1
Code No: R05010106 Set No. 1 1. (a) Draw a Flowchart for the following The average score for 3 tests has to be greater than 80 for a candidate to qualify for the interview. Representing the conditional
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 informationSample Question Paper
Scheme  I Sample Question Paper Marks : 70 Time: 3 Hrs. Q.1) Attempt any FIVE of the following. 10 Marks a. Write any four applications of data structure. b. Sketch the diagram of circular queue. c. State
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)
WINTER 18 EXAMINATION Subject Name: Data Structure using C Model wer Subject Code: 22317 Important Instructions to examiners: 1) The answers should be examined by key words and not as wordtoword as given
More informationData Structures and Algorithms
Data Structures and Algorithms Alice E. Fischer Lecture 6: Stacks 2018 Alice E. Fischer Data Structures L5, Stacks... 1/29 Lecture 6: Stacks 2018 1 / 29 Outline 1 Stacks C++ Template Class Functions 2
More informationMAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)
Subject Code: 17330 Model Answer Page 1/ 22 Important Instructions to examiners: 1) The answers should be examined by key words and not as wordtoword as given in the model answer scheme. 2) The model
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 informationList of Practical for Class XII Computer Science
List of Practical for Class XII Computer Science P.01. Write a complete C++ program to define class Garment with following description: Private members: Code  type string Type  type string Size  type
More informationDEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT1
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : I / II Section : CSE  1 & 2 Subject Code : CS6202 Subject Name : Programming and Data StructuresI Degree & Branch : B.E C.S.E. 2 MARK
More informationData Structure  Stack and Queue
Data Structure  Stack and Queue Hanyang University JongIl Park STACK Stack ADT List that insertions and deletions can be performed at the end of the list Operations Push(X, S): insert X in the list
More informationADVANCED DATA STRUCTURES USING C++ ( MTCSE110 )
ADVANCED DATA STRUCTURES USING C++ ( MTCSE110 ) Unit  2 By: Gurpreet Singh Dean Academics & H.O.D. (C.S.E. / I.T.) Yamuna Institute of Engineering & Technology, Gadholi What is a Stack? A stack is a
More information// array initialization. void main() { cout<<b[4]<<endl; cout<<b[5]<<endl; } Output is 9
UNIT2 DATA STRUCTURES A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. The data structure can be classified into following two types:
More informationUNITI Fundamental Notations
UNITI Fundamental Notations Introduction to Data Structure We know that data are simply values or set of values and information is the processed data. And actually the concept of data structure is much
More informationCpt S 122 Data Structures. Data Structures
Cpt S 122 Data Structures Data Structures Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Introduction Self Referential Structures Dynamic Memory Allocation
More informationA Simple SyntaxDirected Translator
Chapter 2 A Simple SyntaxDirected Translator 11 Introduction The analysis phase of a compiler breaks up a source program into constituent pieces and produces an internal representation for it, called
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 informationEndTerm Examination Second Semester [MCA] MAYJUNE 2006
(Please write your Roll No. immediately) Roll No. Paper Code: MCA102 EndTerm Examination Second Semester [MCA] MAYJUNE 2006 Subject: Data Structure Time: 3 Hours Maximum Marks: 60 Note: Question 1.
More informationLists, Stacks, and Queues. (Lists, Stacks, and Queues ) Data Structures and Programming Spring / 50
Lists, Stacks, and Queues (Lists, Stacks, and Queues ) Data Structures and Programming Spring 2016 1 / 50 Abstract Data Types (ADT) Data type a set of objects + a set of operations Example: integer set
More informationThe Bucharest University of Economic Studies. Data Structures. ADTsAbstract Data Types Stacks and Queues
The Bucharest University of Economic Studies Data Structures ADTsAbstract Data Types Stacks and Queues Agenda Definition Graphical representation Internal interpretation Characteristics Operations Implementations
More informationPrepared By: Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon
Data Structures &Al Algorithms Prepared By: Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon What is Data Structure Data Structure is a logical relationship existing between individual elements
More informationDownloaded from
UnitII Data Structure Arrays, Stacks, Queues And Linked List Chapter: 06 In Computer Science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.
More information[ DATA STRUCTURES] to Data Structures
[ DATA STRUCTURES] Chapter  01 : Introduction to Data Structures INTRODUCTION TO DATA STRUCTURES A Data type refers to a named group of data which share similar properties or characteristics and which
More information