Content: Learning Objectives


 Justin Roland Craig
 2 years ago
 Views:
Transcription
1 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 end of this chapter the students will be able to: a) Define Linked List b) Analyse the need for Linked List c) Represent ingly Linked List d) Perform Basic Operations on ingly Linked List e) Apply the Linked List / Array concepts as tacks, Queues. Resources : a) A Computer with specifically C++ compiler installed b) umita arora (Text book) c) Herbert cheldt fundamentals of c++ Assessment Class test
2 2 wise plan 1 What is a Linked List? What is its need? The teacher emphasises the need to store information as data elements pointing to the next in the sequence. The teacher then defines the linked list as A Linear Collection of data elements, called nodes pointing to the next node by means of pointers. Each Node is divided into two parts: the first part containing the information of the element, and the second part called the link or the next pointer containing the address of the next node in the list. In arrays the memory is reserved before processing. For this reason, arrays are called dense lists or static data structures. Linked lists overcome the drawbacks of arrays as in linked lists number of elements need not be predetermined, more memory can be allocated or released during the processing as and when required, making insertions and deletions much easier and simpler. 2
3 3 Each data element stored in the memory is given some memory. This process of giving main memory is called memory allocation. This can be done in two manners: Dynamically and tatically.tatic Memory Allocation This reserves fixed amount of memory before actual processing takes place, therefore, number of elements stored must be predetermined. uch a type of memory allocation is called static memory allocation. Arrays are allocated memory using this technique only. 2 and 3 Dynamic Memory Allocation This memory technique facilitates allocation of memory during the program execution itself, as and when required. This technique also facilitates release of memory if memory is not required any more. Data tructures like linked lists and trees use this technique for their memory allocation. What are ingly Linked Lists? tart Info Link Info Link Info Link Info This represents a singly linked list where tart is a special pointer, which stores the address of first node in the linked list. The link pointer of the last node stores, which means this node is not pointing to any other node, i.e., it is the last node in the list A B 7865 C 5678 D Representation of a Linked List in Memory Trying to implement in memory in the simplest form, using two linear arrays one called INFO array for INFO storage and the other known as LINK array for next pointer storage such ass INFO [I] and LINK [I] contain INFO part and next pointer of K h node. Also a separate variable TART is required to store the beginning location of the list. ince the subscripts of the array INFO and LINK will usually INFO be positive, LINK we choose NULL=o, unless otherwise stated. TART 7 1 L 2 3 R 4 5 J 6 7 E 8 V tart = INFO [7] = E LINK [7] = 5 INFO [5] = J LINK [5] = 1 INFO [1] = L LINK [1] = 3 3
4 INFO [3] = R LINK [3] = 4 INFO [4] = LINK [4] = 8 INFO [8] = V LINK [8] = 0 i.e. 4 To incorporate these features, together with the linked lists in memory, a special list is maintained consisting of unused memory cells. This list (called AVAIL list) has its own pointer pointing to the next free node and is called freestorage list or freepool. With every insertion, number of free nodes in AVAIL is reduced and with every deletion this number is increased. INFO [9] is the first available free node, then INFO[2], INFO[10], and INFO[6[ are the following available nodes. With every insertion, AVAIL points to its next node, and with every deletion AVAIL points to the freed node and next pointer of the freed node points to the previous first AVAIL node. This method of adding free nodes in AVAIL list, is called garbage collection, 4 and 5 Freetore Allocation in C++ In C++, every program is provided with a pool of unallocated memory that it may utilize during execution. This memory is known as free store memory. In C++, one aspect of this free store memory is that it is unnamed. Objects allocated on the free store do not possess any name; rather, they are manipulated indirectly through pointers. Free store memory is allocated by applying operator new to a type specifier and which returns a pointer pointing to the allocated memory. To allocate memory for a node of a linked list the following statements are given: struct Node char info [15]; Node *next; ; Node *ptr; ptr = new Node; //declare variable forming info part //pointer that will point to the next node //pointer that will point to the newly allocated memory //allocate memory to hold a Node and make ptr point to it Now to refer to the info part, we may write To refer to the next pointer, we may write ptr > info ptr > next When the node is to be deleted, it is done as delete ptr; where ptr is pointer pointing to the Node to be deleted. Basic Operations on ingly Linked List Various operations that can be performed on singly linked list are: Insertion, Deletion, Traversal, Reversal, plitting and Concatenation. Picking up Insertion in the beginning and in the end), Deletion( from the beginning) and traversal in details. Insertion To add an ITEM in the beginning of the list, TART is modified to the point to the new node of ITEM and the next pointer of the new node points to the previous first node. 4
5 5 start B C D E E A The status before insertion To add an ITEM in the end of the list, next pointer of the last node is made to point to the new ITEM s node and the next pointer of the new ITEM s node is made NULL. Inserting in the beginning of a List a) Allocate memory for the new node which will be done as follows : NEWPTR = new Node; Where Node specifies the type of the node for which memory is to be allocated and NEWPTR is the pointer pointing to the newly allocated memory. a) Check whether memory has actually been allocated. If not then display appropriate message. NEWPTR = NULL b) If the sufficient memory has been allocated, copy ITEM to INFO part of the NEWPTR, NEWPTR > INFO = ITEM 6 ALGORITHM  Inserting in the beginning of a List 1. ptr = TART 2. NEWPTR = new Node 3. if NEWPTR = NULL 4. print No pace Available! Aborting!! 5. else 6. NEWPTR  > INFO = ITEM 7. NEWPTR  > LINK = NULL 8. if TART = NULL then 9. TART = NEWPTR 10. else 11. ave = TART 12. TART = NEWPTR 13. NEWPTR  > LINK = ave 14. END DEMO CW Write a function that implements insertion of a node in the beginning of a List 7 ALGORITHM  Inserting in the end of a List 1. Declare pointers TART, PTR, NEWPTR, REAR 2. ptr = TART 3. NEWPTR = new Node 5
6 4. if NEWPTR = NULL 5. print No space Available! Aborting!! 6. Exit 7. else 8. NEWPTR > LINK = NULL 9. if TART = NULL then 10. TART = NEWPTR 11. REAR = NEWPTR 12. REAR > LINK = NEWPTR 13. REAR = NEWPTR 14. END 6 8 DEMO CW Write a function that implements insertion of a node in the end of a List Deletion Deletion of ITEM from a linked list involves a) earch for ITEM in the list for availability b) If available, make its previous node point to its next node start Previously NULL A B C D E E ALGORITHM  Deletion from the beginning of a List 1. If TART = NULL then 2. Print UNDERFLOW 3. else 4. ptr = TART 5. TART = ptr  > LINK 6. delete ptr 7. END DEMO CW Write a function that implements deletion of a node from the List ALGORITHM  Traversal 1. ptr = TART 2. Repeat steps 3 and 4 until ptr = NULL 3. print ptr  > INFO 4. ptr = ptr  > LINK 5. END F 6
7 DEMO 7 CW Write a function that implements traversal of the List 9 and 10 What is a TACK? A tack is a linear dynamic structure implemented in LIFO (Last In First Out), i.e. insertions and deletions happen at the TOP. An insertion in a stack is called Pushing and deletion in a stack is called Popping. Physically it can be implemented as an array or as a linked list. Implementation of tack as an Array As arrays are static data structures, space required for them must be predetermined i.e. how many total elements will be existing together at any point of time must be known beforehand. Therefore, creation of a stack as array involves determining the number of elements beforehand. Insertion in a tack as an Array ( Pushing ) Pushing an element in the stack involves shifting of elements as the new element will be inserted at the top only. If at any point of time we have stack like shown : X PUH P 2 Z 1 Y 0 N P 3 X 2 Z 1 Y 0 N PUH L 6 5 L 4 P 3 X 2 Z 1 Y 0 N In case the array is full and no new element can be accommodated, it is called TACKFULL condition. This condition is also called an OVERFLOW. ALGORITHM  Inserting in a stack as an Array  Pushing //Assuming that array stack can hold maximum N elements 1. top = Read Item 3. If ( top == N1 ) then 4. print Overflow 5. else 6. top=top+1 7. stack[top] = Item 8. END DEMO CW Write a function that implements Pushing an element in a TACK Deletion in a tack as an Array ( Popping ) Popping an element from the stack involves removes the element at the top most position. If at any 7
8 point of time we have stack like shown below : P POP 3 X P 2 Z 1 Y 0 N X 2 Z 1 Y 0 N In case the last element is popped, the stack becomes empty. If one tries to delete an element from an empty stack, this is called UNDERFLOW. ALGORITHM  Deletion from a tack as an Array  Popping //Firstly check for underflow condition 1. if top == 1 then print Underflow 4. Exit from Program else print stack [top] 9. top = top END DEMO CW Write a function that implements Popping an element from a TACK 11 Implementation of tack as a Linked List tack implemented as linked list is a dynamic data structure and inherits all properties of linked lists. Insertion in a Linked tack ( Pushing ) A push can occur only at the Top, Top gets modified every time. If we have a stack as shown below, after pushing, it becomes as shown. After pushing another element P, it becomes as the next shown stack. Top Top H M H M Top P H M 8
9 9 ALGORITHM  Insertion in a linked list ( Pushing ) //get new node for the ITEM to be pushed 1. NEWPTR = new ptr 2. NEWPTR  > INFO = ITEM 3. NEWPTR  > LINK = NULL //Add new node at the top 4. If Top = then 5. Top = NEWPTR 6. else 7. NEWPTR  > LINK = TOP 8. TOP = NEWPTR 9. END DEMO CW Write a function that implements Pushing an element in a TACK 12 Deletion from a Linked tack ( Popping ) Popping of elements also requires modification of TOP, i.e. TOP is made to point to the next mode in the sequence. If the stack is as shown below, after popping P, it will appear as shown. After popping, it becomes as shown in the next figure: Top P H M Top Top H M H M ALGORITHM  Deletion from a linked list ( Pushing ) 1. If Top = NULL then 2. Print tack Empty, Underflow 3. Else 4. Print Top  > INFO 5. Top = Top > LINK 6. END DEMO 9
10 10 CW Write a function that implements Popping an element from a TACK 13 and 14 Application of tacks There are several applications and uses of stacks. The stacks are basically applied where LIFO (Last in First Out) scheme is required. a) Reversing a Line :This can be accomplished by pushing each character on to a stack as it is read. When the characters are finished, they are then popped off the stack. They will come off in the reverse order as shown: If the given line is : tack I Push in Empty tack VII Pop k c k a II Push t t t VIII Pop c III Push a a t a t c IX Pop a IV Push c c a t X Pop t t a XI Pop t V Push k k c a t VI End of line b) Poilish trings : This is conversion of arithmetic expressions in high level language to the language that computers understand, binary language. Complex arithmetic expressions 10
11 11 can be converted into polish strings using stacks which can be executed in two operands and an operator form. There are two forms : Prefix & Postfix Forms Infix Notation Prefix Notation Postfix Notation A + B + AB AB + (A C) X C X ACB AC B X A + ( B X C ) + A X BC ABC X + (A + B) / (C D)  / + A B CD AB + CD  / Conversion of infix to Postfix Notation The evaluation order followed while evaluating an infix expression according to which I Brackets or Parenthesis II Exponentiation III Multiplication or Division IV Addition or ubtraction take place according to the above specified order. The operators with the same priority are evaluated from left to right. tep to convert infix expression into postfix manually a) Determine the actual evaluation order by inserting braces b) Convert the expression in the innermost braces into braces into postfix notation by putting the operator after the operands c) Repeat step (b) until entire expression is converted into postfix notation Examples 1. ((A + B) X C) / D a) =((A + B) X C) /D b) =((AB+) X C) / D c) =(AB + C X) / D d) AB + C X D / 2. (( A + B ) * C/D + E F))/G a) =(((A + B) * C)/D)+(E F))/G b) =(((AB+C*)/D) +EF )/G c) =((AB+C*D/EF + G/ 3. Not A ) Or Not B Not C a) =((Not A) Or ((Not B) And (Not C))) b) =((A Not) Or ((B Not) And (C Not))) c) =((A Not) Or ((B Not C Not And)) d) =A Not B Not C Not And Or ALGORITHM  Conversion of Infix Expression to Postfix Form uppose X is an arithmetic expression written in infix notation. 1. Push ( onto TACK, and add ) to the end of X 2. can X from left to right and REPEAT steps 3 to 6 for each element of X UNTIL the TACK is empty 3. if an operand is encountered, add it to Y 4. if a left parenthesis is encountered, push it onto TACK 5. if an operator is encountered then : a) Repeatedly pop from TACK and add to Y each operator which has same precedence as or higher precedence than operator b) Add operator to TACK 6. if a right parenthesis is encountered then a) Repeatedly pop from TACK and add to Y each operator until a left parenthesis is 11
12 encountered b) Remove the left parenthesis. [Do not add the left parenthesis to Y] 7. END 12 Examples 1. Convert X : A + (B*C (D / E F) * G) * H into postfix form showing stack status after every step in tabular form. No ymbol tack Expression Y canned 1 A ( A 2 + ( + A 3 ( ( + ( A 4 B ( + ( A B 5 * ( + ( * A B 6 C ( + ( * A B C 7  ( + (  A B C * 8 ( ( + (  ( A B C * 9 D ( + (  ( A B C * D 10 / ( + (  ( / A B C * D 11 E ( + (  ( / A B C * D E 12 ( + (  ( / A B C * D E 13 F ( + (  ( / A B C * D E F 14 ) ( + (  A B C * D E F / 15 * ( + (  * A B C * D E F / 16 G ( + (  * A B C * D E F / G 17 ) ( + A B C * D E F / G *  18 * ( + * A B C * D E F / G *  19 H ( + * A B C * D E F / G *  H 20 ) A B C * D E F / G *  H * + Advantage of postfix over infix expression : A postfix expression determines the precedence of operators. Otherwise it is difficult for the machine to know and keep track of precedence operators.. Therefore, it gets easier for the machine to carry out postfix expression than an infix expression. Evaluation of postfix expression A postfix expression is without parenthesis and can be evaluated as two operands and an operator at a time; this becomes easier for the compiler and the computer to handle. Evaluation rule of postfix expression states: While reading the expression from left to right, push the element in the stack if it is an operand; pop the two operands from the stack, if the element is an operator( except NOT operator ) In case of NOT operator, pop one operand from the stack and then evaluate it ( two operands and an operators ). Push back the result of the evaluation. Repeat till the end of the expression. For a binary operator, two operands one popped from stack and for a unary operator, one operand is popped. Then, the result is calculated using operand(s) and the operator, and pushed back into the stack. ALGORITHM  Evaluation of Postfix Expression //Reading of expression takes place from left to right 1. Read the next element // first element for the first time 12
13 2. If element is operand then Push the element in the stack 3. If element is operator then 4. Pop two operands from the stack 5. Evaluate the expression formed by the two operands and the operator 6. Push the result of the expression in the stack end 7. If no more elements then 8. POP the result 9. Else 10. Go to step END Example Evaluate the postfix expression AB + C X D / if A = 2, B = 3, C = 4 and D = 5. tarting from left to right I. First element is operand A, push A into the stack II. econd element is also operand B, push B also into the stack III. Third element + is an operand, pop 2 operands from the stack, i.e., A and B and evaluate the expression i.e. A + B = = 5 IV. Push the result (5) into the stack A tack I tack IV 5 20 tack VII tack II B A tack V C 5 D 20 tack VIII 4 tack III tack VI tack IX tack X V. Next element C is operand; pushed into the tack VI. Next X is an operator, pop 2 operands from the stack i.e., 5 and C and evaluate 5 X C = 5 X 4 = 20 VII. Push the result (20) into stack VIII. Next D is operand, pushed into stack IX. Next / is operator; two operands popped D and 20. Expression evaluated as follows : 20 = 20 = 4 X. End of the expression, Pop from stack. Thus the result is 4 D 5 2. Evaluate the postfix expression True NOT OR NOT AND OR AND tarting from left to right I. is operand, pushed into stack II. is operand, pushed into stack III. is operand, pushed into stack IV. NOT is a unary operator. Thus only one operand is popped. Evaluating NOT = ; Pushing the result into the stack. V. is an operand; pushed into stack VI. is an operand, pushed 13
14 14 VII. OR is operator, Pop two operands,,. Evaluating the expression, we get OR =. Pushing the result into the stack. VIII. NOT is operator; One operand is popped, i.e.. Evaluating NOT = IX. AND is operator; Pop two operands, i.e.,,. Evaluating AND =. Pushing the result, into the stack X. OR is operator; Pop two operands i.e.,. Evaluating OR = ; Push the result XI. AND is operator; Pop two operands, i.e.,,. Evaluate and Push back : AND = XII. No more elements, Pop from stack therefore the result is. tack I tack II tack III tack IV tack V tack VI tack VII tack VIII tack IX tack X tack XI 16 Deletion in a Queue as an Array As deletions occur at the front end only, with every deletion, the front gets modified. Whenever an element is deleted from the queue, the value of front is increased by 1( if only, elements remaining in the queue are not to be shifted ) front = 0 rear = 5 front front = 2 = 1 rear rear = 5 = 5 front = 3 rear = N 2 N N 2 N N 2 N N 2 N
15 ALGORITHM  Deletion in a Queue as an Array If rear = NULL then Print Queue Empty else ITEM = QUEUE [front] If front = rear then Front = rear = NULL else front = front + 1 END Implementation of Queue as a Linked List Linked queues are the queue having links among its elements. Two pointers are maintained to store the frot position and the rear position front rear 17 and 18 Implementation of Queue as a Linked List Linked queues are the queue having links among its elements. Two pointers are maintained to store the frot position and the rear position front rear Insertion in a Linked Queue Insertions in a linked list take place only at the rear i.e. the rear gets modified with every insert Rear new Link front Old Link ALGORITHM  Insertion in Linked Queue NEWPTR = new Node NEWPTR  > INFO = ITEM; NEWPTR  > LINK = NULL If rear = NULL then front = NEWPTR rear = NEWPTR 15
16 else END Rear>LINK=NEWPTR Rear = NEWPTR 16 Old Link Deletion in a Linked Queue Insertions in a linked list take place only from the front i.e. the front gets modified with every delete front New Link rear 19 and 20 ALGORITHM  Deletion from a Linked Queue If front = NULL then Print Queue Empty else ITEM = front> INFO If front=rear then front=rear=null else front=front>link END Variations in Queue Queues can be used in several forms: Circular Queues and Dequeues (double ended queues) Circular Queues are the queues implemented in circular form rather than a straight line. They overcome the problem of unutilised space in linear queues implemented as arrays front = 3 rear = N  2 front = 3 rear = N N 2 N N 2 N front = 4 rear = N N 2 N front = 4 rear = N 2 N
17 17 Deque are refined in which elements can be added or removed at either end but not in the middle. The two variations of deque: input restricted deque and an output restricted deque. An input restricted deque is deque which allows insertions only at one end but allows deletions at both ends of the list. An output restricted deque is a deque which allows deletions only at one end of the list but allows insertions at both the ends of the list. ALGORITHM  Insertion in a Circular Queue //Assuming that the Circular Queue is stored in QU with size N If front=0 and rear=n1 or front=rear+1 Write Overflow! else If front=null then et front=0 Rear=0 Else if rear=n1 then et rear=0 Else et rear=rear+1 et QU[rear] = ITEM END ALGORITHM  Deletion from a Circular Queue Assuming that the queue is stored in as array QU with size N. If front=null then Write Underflow Return Else et D_ITEM = QU[front] If front=rear then Front=NULL Rear=NULL Else if Front=N 1 then Front = 0 Else Front=front+1 END 21 Class Test 17
18 18 18
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 informationSome 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 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 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 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 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 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 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 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 informationTypes of Data Structures
DATA STRUCTURES material prepared by: MUKESH BOHRA Follow me on FB : http://www.facebook.com/mukesh.sirji4u The logical or mathematical model of data is called a data structure. In other words, a data
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 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 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 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 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 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 information17CS33:Data Structures Using C QUESTION BANK
17CS33:Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C Learn : Usage of structures, unions  a conventional tool for handling a group of logically
More informationPreface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS
Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...
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 informationPA3 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 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 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 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 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 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 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 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 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 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 informationQueue. Data Structure
Queue Data Structure Introduction It is linear data structure It is collection of items List Queue means line of items waiting for their turn Queue has two ends Elements are added at one end. Elements
More informationCpt S 122 Data Structures. Course Review Midterm Exam # 1
Cpt S 122 Data Structures Course Review Midterm Exam # 1 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 1 When: Friday (09/28) 12:101pm Where:
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 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 informationData Structures & Algorithm Analysis. Lecturer: Souad Alonazi
Data Structures & Algorithm Analysis Lec(3) Stacks Lecturer: Souad Alonazi What is a stack? Stores a set of elements in a particular order Stack principle: LAST IN FIRST OUT = LIFO It means: the last element
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 informationMonth: April No. of Periods: 14
BLOOM PUBLIC SCHOOL Vasant Kunj, New Delhi Lesson Plan Subject: MATHEMATICS Class: VII Month: April No. of Periods: 14 Chapter: 1 Integers TTT: 6 WT: 8 CHAPTER Integers Learning Objectives Resources The
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 informationinfix 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 informationDC54 DATA STRUCTURES DEC 2014
Q.2 a. Write a function that computes x^y using Recursion. The property that x^y is simply a product of x and x^(y1 ). For example, 5^4= 5 * 5^3. The recursive definition of x^y can be represented as
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 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 informationStack Applications. Lecture 27 Sections Robb T. Koether. HampdenSydney College. Wed, Mar 29, 2017
Stack Applications Lecture 27 Sections 18.718.8 Robb T. Koether HampdenSydney College Wed, Mar 29, 2017 Robb T. Koether HampdenSydney College) Stack Applications Wed, Mar 29, 2017 1 / 27 1 Function
More informationCS6202  PROGRAMMING & DATA STRUCTURES I Unit IV Part  A 1. Define Stack. A stack is an ordered list in which all insertions and deletions are made at one end, called the top. It is an abstract data type
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 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 informationPESIT Bangalore South Campus Department of MCA Course Information for
1. GENERAL INFORMATION: PESIT Bangalore South Campus Department of MCA Course Information for Data Structures Using C(13MCA21) Academic Year: 2015 Semester: II Title Code Duration (hrs) Lectures 48 Hrs
More information1 P age DS & OOPS / UNIT II
UNIT II Stacks: Definition operations  applications of stack. Queues: Definition  operations Priority queues  De que Applications of queue. Linked List: Singly Linked List, Doubly Linked List, Circular
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 informationCSE 214 Computer Science II Stack
CSE 214 Computer Science II Stack Spring 2018 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Random and Sequential Access Random
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 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 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 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 informationPrepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1
QUESTION BANK ON COURSE: 304: PRELIMINARIES: 1. What is array of pointer, explain with appropriate example? 2 2. Differentiate between call by value and call by reference, give example. 3. Explain pointer
More informationGuide for The C Programming Language Chapter 5
1. Differentiate between primitive data type and nonprimitive data type. Primitive data types are the basic data types. These data types are used to represent single values. For example: Character, Integer,
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 informationPrepared by Mrs.D.Maladhy (AP/IT/RGCET) Page 1
Basics : Abstract Data Type(ADT) introduction to data structures representation  implementation Stack and list: representing stack implementation application balancing symbols conversion of infix to postfix
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 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 informationAdapted By Manik Hosen
Adapted By Manik Hosen Question: What is Data Structure? Ans: The logical or mathematical model of particular organization of data is called Data Structure. Question: What are the difference between linear
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 informationCOMPUTER ARCHITECTURE AND PARALEL PROCESSING STUDY NOTES
COMPUTER ARCHITECTURE AND PARALEL PROCESSING STUDY NOTES UNIT 1 INTRODUCTION Central Processing unit (CPU): Alternately referred to as a processor, central processor, or microprocessor, the CPU is the
More informationBBM 201 DATA STRUCTURES
BBM 201 DATA STRUCTURES Lecture 6: EVALUATION of EXPRESSIONS 20182019 Fall Evaluation of Expressions Compilers use stacks for the arithmetic and logical expressions. Example: x=a/bc+d*ea*c If a=4, b=c=2,
More informationBBM 201 DATA STRUCTURES
BBM 201 DATA STRUCTURES Lecture 6: EVALUATION of EXPRESSIONS 2017 Fall Evaluation of Expressions Compilers use stacks for the arithmetic and logical expressions. Example: x=a/bc+d*ea*c If a=4, b=c=2,
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 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 informationMCA SEMII Data Structure
MCA SEMII Data Structure Timings: 30 Minutes] Objective Questions Keys [ Marks  40 1. The memory address of the first element of an array is called a. Floor address b. Foundation address c. First address
More informationList, Stack, and Queues
List, Stack, and Queues R. J. Renka Department of Computer Science & Engineering University of North Texas 02/24/2010 3.1 Abstract Data Type An Abstract Data Type (ADT) is a set of objects with a set of
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 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 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 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 informationLecture 4 Stack and Queue
Lecture 4 Stack and Queue Bo Tang @ SUSTech, Spring 2018 Our Roadmap Stack Queue Stack vs. Queue 2 Stack A stack is a sequence in which: Items can be added and removed only at one end (the top) You can
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 informationIntroduction to Computer and Program Design 2. Lesson 6. Stacks. James C.C. Cheng Department of Computer Science National Chiao Tung University
Introduction to Computer and Program Design 2 Lesson 6 Stacks James C.C. Cheng Department of Computer Science National Chiao Tung University Introduction Stack A data collection, a grouping of data items
More informationDraw 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 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 informationChapter 4 Trees. Theorem A graph G has a spanning tree if and only if G is connected.
Chapter 4 Trees 41 Trees and Spanning Trees Trees, T: A simple, cyclefree, loopfree graph satisfies: If v and w are vertices in T, there is a unique simple path from v to w. Eg. Trees. Spanning trees:
More informationA linearlist Data Structure where  addition of elements to and  removal of elements from are restricted to the first element of the list.
A linearlist Data Structure where  addition of elements to and  removal of elements from are restricted to the first element of the list. the first element of the list a new element to (the Top of)
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 informationCHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar
CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US02CBCA01 (Advanced C Programming and Introduction to Data Structures) *UNIT 3 (Introduction to Data
More informationASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n))
ASSIGNMENTS Chapter Q. No. Questions Course Outcom e (CO) Progra m Outcom e I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n)) 2 3. What is the time complexity of the algorithm? 4
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 informationUNITII. Part2: CENTRAL PROCESSING UNIT
Page1 UNITII Part2: CENTRAL PROCESSING UNIT Stack Organization Instruction Formats Addressing Modes Data Transfer And Manipulation Program Control Reduced Instruction Set Computer (RISC) Introduction:
More informationCS 8391 DATA STRUCTURES
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK CS 8391 DATA STRUCTURES UNIT I PART A 1. Define: data structure. A data structure is a way of storing and organizing data in the memory for
More informationStacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved
Stacks Chapter 5 Contents Specifications of the ADT Stack Using a Stack to Process Algebraic Expressions A Problem Solved: Checking for Balanced Delimiters in an Infix Algebraic Expression A Problem Solved:
More information