DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.

Size: px
Start display at page:

Download "DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently."

Transcription

1 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 has a clear meaning and can be performed with a finite amount of effort in a finite length of time. 1

2 Types of data structures Primitive data structures. (int, float, integer, pointer) Non Primitive data structures. (1) Linear data structures. (Array, Stack, Linked list, Queue) (2) Non linear data structures. (trees, graph) 2

3 Primitive data structures The integers, reals, logical data, character data, pointer and reference are primitive data structures. Data structures that normally are directly operated upon by machine-level instructions are known as primitive data structures. 3

4 Non Primitive data structures These are more complex data structures. These data structures are derived from the primitive data structures. They stress on formation of sets of homogeneous and heterogeneous data elements. 4

5 Stack- Works in first in last out order. The element inserted first in stack is removed last. Queue- First in First out order. The element inserted first is removed first. Linked list- Stored data in a linear fashion. Trees- Stores data in a non linear fashion with one root node and sub nodes. 5

6 ARRAY Array means collection. An array is used to store elements of the same type. It is a very popular and useful data structure and stores data elements in contiguous locations. 6

7 IMPLEMENTATION OF LIST Array implementation of list Linked list implementation of list Cursor implementation of list 7

8 Types of Linked list Singly linked list Doubly linked list Circular linked list (1) Circular singly linked list (2) Circular doubly linked list 8

9 Singly Linked List A singly linked list is a linked list in which each node contains Data and only one link field pointing to the next node in the list. 9

10 Doubly Linked List A Doubly linked list is a linked list in which each node has three fields namely data field, forward link (FLINK) or Next and Backward Link (BLINK) or previous. FLINK points to the successor node in the list whereas BLINK points to the predecessor node. 10

11 Circular Linked List It is a doubly linked list In circular linked list, the pointer of the last node points to the first node and first node pointing to last node. Circular linked list can be implemented as Singly linked list and Doubly linked list with or without headers. 11

12 Advantages of Circular Linked List It allows to traverse the list starting at any point. It allows quick access to the first and last records. 12

13 Advantages of doubly linked list * Deletion operation is easier. * Finding the predecessor & Successor of a node is easier. Disadvantage * More Memory Space is required since it has two pointers. 13

14 Chapter 3: Lists, Stacks and Queues Concept of Abstract Data Type (ADT) How to efficiently perform operations on list Stack ADT and its applications Queue ADT and its applications Cursor implementation of Linked list 14

15 3.1 Abstract Data Type Modular program Advantages: (1) debugging (2) team work (3) easy to modify 15

16 3.1 Abstract Data Type Abstract Data Type Some data, associated with a set of operations mathematical abstractions just as integer, boolean Basic idea write once, use many Any changes are transparent to the other modules 16

17 3.2 List ADT A general list of elements: A 1, A 2,, A N, associated with a set of operations: Insert: add an element Delete: remove an element Find: find the position of an element (search) FindKth: find the kth element 17

18 3.2 List ADT Different implementations: Array Linked list Doubly linked list Circularly linked list (or, Circular list) 18

19 3.2 List ADT Array Insert: O(N) Delete: O(N) Find: O(N) FindKth: O(1) The array size is usually unknown 19

20 3.2 List ADT Linked list Insert: O(1) Delete: O(1) Find: O(N) FindKth: O(N) Linked list with a header A 1 A 2 A 3 header A 1 A 2 A 3 20

21 3.2 List ADT Common errors memory allocation segmentation violation check for NULL pointer free memory 21

22 Doubly linked list struct node { int Number; struct node *left; struct node *right; } 3.2 List ADT A 1 A 2 A 3 22

23 Applications of Linked List 1. Polynomial ADT 2. Radix Sort 3. Multilist 23

24 3.2.1 List ADT: Example1 Single-variable Polynomials N F ( X ) i 0 A i X i typedef struct { int CoeffArray[MaxDegree+1]; int HighPower; } *polynomial; 24

25 3.2.1 List ADT: Example 1 Initialize a polynomial void ZeroPolynomial(Polynomial Poly) { int j; for (j = 0; j < MaxDegree; j++) poly->coeffarray[j] = 0; Poly->HighPower = 0; } 25

26 3.2.1 List ADT: Example 1 Add two polynomials void AddPolynomial(const Polynomial Poly1, const Polynomial Poly2, Polynomial PolySum) { int j; } ZeroPolynomial(PolySum); PolySum->HighPower = Max(Poly1-> HighPower, Poly2 -> HighPower); for (j=polysum->highpower; j>=0; j--) PolySum->CoeffArray[j] = Poly1-> CoeffArray [j] + Poly2-> CoeffArray[j]; 26

27 3.2.1 List ADT: Example 1 Multiply two polynomials void MultPolynomial(const Polynomial Poly1, const Polynomial Poly2, Polynomial PolyProd) { int j,k; } ZeroPolynomial(PolyProd); PolyProd->HighPower = Poly1-> HighPower+ Poly2 -> HighPower; for (j=0; j<=poly1->highpower; j++) for (k=0; k<=poly2->highpower; k++) PolyProd->CoeffArray[j+k] += Poly1-> CoeffArray [j]* Poly2-> CoeffArray[k]; 27

28 3.2.1 List ADT: Example 1 Multiply two polynomials: limitation Consider the following situation P 1 (X) = 10 X X P 2 (X) = 3X X X +5 Most of the time is spent multiplying zeros 28

29 3.2.1 List ADT: Example 1 Multiply two polynomials: better structure struct node { int Coefficient; int Exponent; struct node *Next; }; 29

30 Radix Sort Radix sort is sometimes known as card sort Buckets after first step of radix sort Buckets after the second pass of radix sort 30

31 Buckets after the last pass of radix sort OUTPUT:

32 3.2.1 List ADT: Example 1 Linked list representation of the previous structure 32

33 3.2.2 List ADT: Example 2 Multilists A university with 40,000 students and 2,500 subjects needs to generate 2 reports: 1. Lists of registration for each class 2. Classes that each student registered. Implementation: construct 2D array (40Kx2.5K) = 100M entries if each student takes 3 subjects => only 120K entries (~0.1% of 100M) => waste of resources. 33

34 3.2.2 List ADT: Example 2 Multilists 34

35 The Stack ADT A stack is a list with the restriction that inserts and deletes can be performed in only one position, namely the end of the list called the top. The fundamental operations on a stack are push, which is equivalent to an insert, and pop,which deletes the most recently inserted element. 35

36 Stack ADT Stacks are sometimes known as LIFO (last in, first out) lists. 36

37 3.3 Stack ADT Stack model 37

38 3.3 Stack ADT LIFO structure Access from the top Basic Operations empty (s) pop (s) push (s, i) top (s) 38

39 Stack implementation Array implementation of stack Linked list implementation of stack 39

40 3.3.1Implementation of stack using Linked List struct Node; typedef struct Node *PtrToNode; typedef PtrToNode Stack; struct Node { ElementType Element; PtrToNode Next; }; 40

41 3.3.1Implementation of stack using Linked List int IsEmpty(Stack S); Stack CreatStack(void); void DisposeStack(Stack S); void MakeEmpty(Stack S); void Push(ElementType X, Stack S); void Pop(Stack S); ElementType Top(Stack S); 41

42 3.3.1Implementation of stack using Linked List Test for an empty stack int Isempty(Stack S) { return (S Next == NULL); } 42

43 3.3.1Implementation of stack using Linked List Create an empty stack stack CreatStack(void) { Stack S; S=malloc(sizeof(struct Node)); if (S==NULL) FatalError( Out of space!!! ); S->Next = NULL; return(s); } void MakeEmpty(Stack S) { if (S==NULL) printf( Error message! ); else } while (!IsEmpty(S)) pop(s); 43

44 3.3.1Implementation of stack using Linked List Push onto a stack void Push(ElementType X, Stack S) { PtrtoNode TmpCell; TmpCell = malloc(sizeof(struct Node)); } if (TmpCell == NULL) fatalerror( message ); else { TmpCell Element = X; TmpCell Next = S Next; S } Next = TmpCell; 44

45 3.3.1Implementation of stack using Linked List Return top element in a stack ElementType Top(Stack S) { if (!IsEmpty(S)) return (S Next Element); Error( Empty stack ); return 0; } 45

46 3.3.1Implementation of stack using Linked List Pop from a stack void Pop(Stack S) { PtrToNode FirstCell; if (ISEmpty(S); Error ( Empty stack ); else { FirstCell = S Next; S Next =S Next Next; free(firstcell); } } 46

47 3.3.2 Implementation of stack using Array struct StackRecord { int Capacity; int TopOfStack; ElementType *Array; }; typedef struct StackRecord *Stack; 47

48 3.3.2 Implementation of stack using Array Stack creation Stack (CreateStack( int MaxElements ) { Stack S; if (MaxElements < MinStackSize) Error( Stack size is too small ); S = malloc(sizeof(struc StackRecord ) ); if ( S == Null) FatalError( Out ofspace!!! ); S Array = malloc(sizeof(elementtype) * MaxElements); 48

49 3.3.2 Implementation of stack using Array If (S Array == Null) FatalError( Out of space!!! ); S Capacity = MaxElements; MakeEmpty(S); return S; } 49

50 3.3.2 Implementation of stack using Array Test for empty stack Int Isempty (stack S) { return S TopOfStack == EmptyTOS; } 50

51 3.3.2 Implementation of stack using Array Create an empty stack void MakeEmpty (stack S) { S TopOfStack = EmptyTOS; } 51

52 3.3.2 Implementation using Array Push an element onto the stack void Push (ElementType X, Stack S) { if (IsFull(S) ) Error( Full Stack ); else S Array[ ++S TopOfStack] = X ; } 52

53 3.3.2 Implementation using Array Return top of stack ElementType Top( Stack S) { if (!IsEmpty(S)) return S Array[S TopOfStack]; Error( Empty stack ); return 0 ; } 53

54 3.3.2 Implementation using Array Pop element from stack void Pop (Stack S) { if (Isempty (S)) Error( Empty stack ); else } S TopOfStack--; 54

55 3.3.2 Implementation using Array Top element and pop a stack ElementType TopAndPop( Stack S) { if (!IsEmpty(S)) return S Array[S TopOfStack--]; Error( Empty stack ); return 0; } 55

56 Exception Conditions in stack Overflow : Attempt to insert an element, when the queue is full is said to be overflow condition. Underflow : Attempt to delete an element from the queue, when the queue is empty is said to be underflow. 56

57 Types of notations to represent arithmetic expression Infix notation Postfix notation or (Reverse polish notation) Prefix notation 57

58 INFIX In Infix notation, The arithmetic operator appears between the two operands to which it is being applied. POSTFIX The arithmetic operator appears directly after the two operands to which it applies. Also called reverse polish notation. 58

59 PREFIX The arithmetic operator is placed before the two operands to which it applies. Also called as polish notation. 59

60 Applications of Stack Balancing Symbols Postfix Expressions Infix to Postfix Conversion Function Calls(Example: Factorial) Towers of Hanoi 8 Queen Problem. 60

61 Balancing Symbols Applications Make an empty stack. Read characters until end of file. If the character is an opening symbol, push it onto stack. If it is a closing symbol, then if the stack is empty, report an error. Otherwise, pop the stack. If the symbol popped is not the corresponding opening symbol, then report an error. At the end of file, if the stack is not empty, report an error. 61

62 3.3.4 Applications Postfix Expressions *1.06 = or postfix notation of (4.99* *1.06) is * * + Why do we need postfix notation? 62

63 Evaluating Postfix Expression Read the postfix expression one character at a time until it encounters the delimiter `#'. Step 1 : - If the character is an operand, push its associated value onto the stack. Step 2 : - If the character is an operator, POP two values from the stack, apply the operator to them and push the result onto the stack. 63

64 3.3.4 Application: Postfix How does postfix work? e.g * * 64

65 3.3.4 Application : Postfix 65

66 3.3.4 Application : Postfix 66

67 3.3.4 Applications Expression: Operands: numbers Operators: +, -, *, / Parenthesis: ( ) Precedence: '(' and ')' have the highest precedence '*' and '/ 'have lower precedence than '(' and ')' '+' and '-' have lower precedence than '*' and '/' Converting infix expressions into postfix Infix A * B + C * D Postfix A B * C D * + 67

68 3.3.4 Application: infix postfix Stack -> Input Postfix String A A * * A * B A B + + A B * + C A B * C + * * A B * C + * D A B * C D pop stack A B * C D * + 68

69 3.3.4 Application: infix postfix (1) Initialize a stack to empty. (2) Read a symbol (2.1) If it is an operand, place onto the output. (2.2) If it is an operator (a) If it is a right parenthesis, then pop the stack, write symbols, until a left parenthesis is encountered. Remark: The '(' is popped, but not written as output. (b) If it is any other symbol, such as '+', '*', '(', pop entries from the stack until an entry of lower priority is found, or '(' is found. When the popping is done, push the operator onto the stack. Remark: If '(' is found, don t pop it. (3) Goto step (2). (4) If read the end of input, pop the stack until it is empty, writing symbols onto the output. 69

70 a + b * c + ( d * e + f ) * g Infix to Postfix Conversion 70

71 71

72 3.3.4 Application: infix postfix With parentheses: (A+B)*C output: AB+C* Stack -> Input Postfix String ( ( ( A A ( + + A ( + B A B ) A B + * * A B + * C A B + C pop stack A B + C * 72

73 Function Calls When a call is made to a new function all the variables local to the calling routine need to be saved, otherwise the new function will overwrite the calling routine variables. Similarly the current location address in the routine must be saved so that the new function knows where to go after it is completed. 73

74 Function call RECURSIVE FUNCTION TO FIND FACTORIAL : - int fact (int n) { int s; if (n = = 1) return (1); else s = n * fact (n - 1); return (s); } 74

75 Queue ADT The basic operations on a queue are enqueue, which inserts an element at the end of the list (called the rear), and dequeue, which deletes (and returns) the element at the start of the list (known as the front). 75

76 Queue ADT Model of a queue 76

77 3.4 Queue ADT Ordered collections of data items Delete item at front of the queue Insert item at rear of the queue A FIFO structure A B C D E front rear 77

78 3.4 Queue ADT Basic operations (1) Enqueue (ElementType X, Queue Q) (2) Dequeue(Queue Q) 78

79 Array Implementation of Queue In this implementation queue Q is associated with two pointers namely rear pointer and front pointer. To insert an element X onto the Queue Q, the rear pointer is incremented by 1 and then set Queue [Rear] = X To delete an element, the Queue [Front] is returned and the Front Pointer is incremented by 1. 79

80 3.4 Queue ADT Array implementation struct QueueRecord { int Capacity; int Front, Rear, Size; ElementType *Array; }; typedef struct QueueRecord *Queue; 80

81 3.4 Queue ADT Problem: May run out of rooms (1) Keep front always at 0 by shifting the contents up the queue, but the computer solution is inefficient (2) Use a circular queue (wrap around & use a length variable to keep track of the queue length) 81

82 3.4 Queue ADT static int Succ( int Value, Queue Q) { if (++Value == Q Capacity) Value = 0; return Value; } 82

83 3.4 Queue ADT void Enqueue (ElementType X, Queue Q ) { if (IsFull(Q) ) Error( Full queue ); else { Q Size++; Q Rear = Succ(Q Rear, Q); Q Array[Q Rear] = x; } } 83

84 3.4 Queue ADT void Dequeue( Queue Q ) { if( IsEmpty( Q ) ) Error( "Empty queue" ); else { Q->Size--; Q->Front = Succ( Q->Front, Q ); } } 84

85 Routine to test whether a queue is empty-array implementation int is_empty( QUEUE Q ) { return( Q->q_size == 0 ); } 85

86 Routine to make an empty queue-array implementation void make_null ( QUEUE Q ) { Q->q_size = 0; Q->q_front = 1; Q->q_rear = 0; } 86

87 DECLARATION FOR LINKED LIST IMPLEMENTATION OF QUEUE ADT Struct Node { int Element; Struct Node *Next; }* Front = NULL, *Rear = NULL; 87

88 DECLARATION FOR LINKED LIST IMPLEMENTATION OF QUEUE ADT Struct Node; typedef Struct Node * Queue; int IsEmpty (Queue Q); Queue CreateQueue (void); void MakeEmpty (Queue Q); void Enqueue (int X, Queue Q); void Dequeue (Queue Q); 88

89 ROUTINE TO CHECK WHETHER THE QUEUE IS EMPTY int IsEmpty (Queue Q) // returns boolean value / { // if Q is empty if (Q Next = = NULL) // else returns 0 return (1); } 89

90 ROUTINE TO CHECK AN EMPTY QUEUE Struct CreateQueue ( ) { Queue Q; Q = Malloc (Sizeof (Struct Node)); if (Q = = NULL) Error ("Out of Space"); MakeEmpty (Q); return Q; } 90

91 ROUTINE TO MAKE AN EMPTY QUEUE void MakeEmpty (Queue Q) { if (Q = = NULL) Error ("Create Queue First"); else while (! IsEmpty (Q) Dequeue (Q); } 91

92 ROUTINE TO ENQUEUE AN void Enqueue (int X) { Struct node *newnode; newnode = ELEMENT IN QUEUE Malloc (sizeof (Struct node)); if (Rear = = NULL) { newnode data = X; newnode Next = NULL; Front = newnode; Rear = newnode; } else { newnode data = X; newnode Next = NULL; Rear next = newnode; Rear = newnode; } } 92

93 ROUTINE TO DEQUEUE AN ELEMENT FROM THE QUEUE void Dequeue ( ) { Struct node *temp; if (Front = = NULL) Error("Queue is underflow"); else { 93

94 temp = Front; if (Front = = Rear) { Front = NULL; Rear = NULL; } else Front = Front Next; Print (temp data); free (temp); } } 94

95 3.4 Applications of Queues Print jobs Computer networks Batch processing in an operating system(os) Real-life waiting lines 95

96 Double Ended Queue (DEQUE) In Double Ended Queue, insertion and deletion operations are performed at both the ends. 96

97 Circular Queue In Circular Queue, the insertion of a new element is performed at the very first location of the queue if the last location of the queue is full, in which the first element comes just after the last element. 97

98 Advantages of Circular Queue It overcomes the problem of unutilized space in linear queues, when it is implemented as arrays. To perform the insertion of an element to the queue, the position of the element is calculated by the relation as Rear = (Rear + 1) % Maxsize. and then set Queue [Rear] = value. 98

99 ROUTINE TO INSERT AN ELEMENT IN CIRCULAR QUEUE void CEnqueue (int X) { if (Front = = (rear + 1) % Maxsize) print ("Queue is overflow"); else { if (front = = -1) front = rear = 0; else rear = (rear + 1)% Maxsize; CQueue [rear] = X; } } 99

100 To perform the deletion, the position of the Front printer is calculated by the relation Value = CQueue [Front] Front = (Front + 1) % maxsize. 100

101 ROUTINE TO DELETE AN ELEMENT FROM CIRCULAR QUEUE int CDequeue ( ) { if (front = = -1) print ("Queue is underflow"); else { X = CQueue [Front]; if (Front = = Rear) Front = Rear = -1; else Front = (Front + 1)% maxsize; } return (X); } 101

102 Cursor Implementation of Linked Lists The two important items present in a pointer implementation of linked lists are 1. The data is stored in a collection of structures. Each structure contains the data and a pointer to the next structure. 2. A new structure can be obtained from the system's global memory by a call to malloc and released by a call to free. 102

103 struct node { element_type element; node_ptr next; }; typedef node_ptr LIST; typedef node_ptr position; struct node CURSOR_SPACE[ SPACE_SIZE ]; Declarations for cursor implementation of linked lists 103

104 Consider if the value of L is 5 and the value of M is 3, then L represents the list a, b, e, and M represents the list c, d, f. L= header 104

105 Slot Element Next An initialized CURSOR_SPACE 105

106 Slot Element Next L=5(a,b,e), M=3(c,d,f) b 9 2 f 0 3 header(m) header(l) c 8 8 d 2 9 e 0 10 a 1 Example of a cursor implementation of linked lists 106

107 int is_empty( LIST L ) /* using a header node */ { return( CURSOR_SPACE[L].next == 0 } Function to test whether a linked list is empty--cursor implementation int is_last( position p, LIST L) /* using a header node */ { return( CURSOR_SPACE[p].next == 0 } Function to test whether p is last in a linked list-- cursor implementation 107

108 position find( element_type x, LIST L) /* using a header node */ { position p; /*1*/ p = CURSOR_SPACE[L].next; /*2*/ while( p && CURSOR_SPACE[p].element!= x ) /*3*/ p = CURSOR_SPACE[p].next; /*4*/ return p; } Find routine--cursor implementation 108

109 void delete( element_type x, LIST L ) { position p, tmp_cell; p = find_previous( x, L ); if(!is_last( p, L) ) { tmp_cell = CURSOR_SPACE[p].next; CURSOR_SPACE[p].next = CURSOR_SPACE[tmp_cell].next; cursor_free( tmp_cell ); } } Deletion routine for linked lists--cursor implementation 109

110 void insert( element_type x, LIST L, position p ) { position tmp_cell; /*1*/ tmp_cell = cursor_alloc( ) /*2*/ if( tmp_cell ==0 ) /*3*/ fatal_error("out of space!!!"); else { /*4*/ CURSOR_SPACE[tmp_cell].element = x; /*5*/ CURSOR_SPACE[tmp_cell].next = CURSOR_SPACE[p].next; /*6*/ CURSOR_SPACE[p].next = tmp_cell; } } Insertion routine for linked lists--cursor implementation 110

111 Exercises (1) Write a program to print out the elements of a singly linked list. (2) Given two sorted lists, L1 and L2, write a procedure to compute L1 n L2 using only the basic list operations. (3) Given two sorted lists, L1 and L2, write a procedure to compute L1u L2 using only the basic list operations. (4) Write the routines to implement queues using a. linked lists b. arrays 111

112 (4) A deque is a data structure consisting of a list of items, on which the following operations are possible: push(x,d): Insert item x on the front end of deque d. pop(d): Remove the front item from deque d and return it. inject(x,d): Insert item x on the rear end of deque d. eject(d): Remove the rear item from deque d and return it. Write routines to support the deque that take O(1) time per operation. 112

Data Structure - Stack and Queue-

Data Structure - Stack and Queue- Data Structure - Stack and Queue- Hanyang University Jong-Il 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 information

DATA STRUCTURES AND ALGORITHMS UNIT I LINEAR STRUCTURES

DATA STRUCTURES AND ALGORITHMS UNIT I LINEAR STRUCTURES DATA STRUCTURES AND ALGORITHMS UNIT I LINEAR STRUCTURES Highlights of the chapter Introduce the concept of Abstract Data Types (ADTs). Show how to efficiently perform operations on lists. Introduce the

More information

UNIT - I LISTS, STACKS AND QUEUES

UNIT - I LISTS, STACKS AND QUEUES UNIT - I LISTS, STACKS AND QUEUES Abstract data types- List ADT-Stack ADT-recursion-Queue ADT A data structure is an arrangement of data in a computer's memory or even disk storage. An example of several

More information

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3 UNIT 3 LINEAR DATA STRUCTURES 1. Define Data Structures Data Structures is defined as the way of organizing all data items that consider not only the elements stored but also stores the relationship between

More information

1 P age DS & OOPS / UNIT II

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

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

Stacks and Queues. CSE Data Structures April 12, 2002

Stacks and Queues. CSE Data Structures April 12, 2002 Stacks and Queues CSE 373 - Data Structures April 12, 2002 Readings and References Reading Section 3.3 and 3.4, Data Structures and Algorithm Analysis in C, Weiss Other References 12-Apr-02 CSE 373 - Data

More information

DATA STRUCTURE UNIT I

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

p Write a program to evaluate a postfix expression. #ifndef _Stack_H #define _Stack_H #define ElementType double

p Write a program to evaluate a postfix expression. #ifndef _Stack_H #define _Stack_H #define ElementType double p.81 3.19 Write a program to evaluate a postfix expression. #ifndef _Stack_H #define _Stack_H #define ElementType double struct Node; typedef struct Node *PtrToNode; typedef PtrToNode Stack; int IsEmpty(Stack

More information

Lists, 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 / 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 information

Linked List. April 2, 2007 Programming and Data Structure 1

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

Prepared by Mrs.D.Maladhy (AP/IT/RGCET) Page 1

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

DEEPIKA KAMBOJ UNIT 2. What is Stack?

DEEPIKA KAMBOJ UNIT 2. What is Stack? What is Stack? UNIT 2 Stack is an important data structure which stores its elements in an ordered manner. You must have seen a pile of plates where one plate is placed on top of another. Now, when you

More information

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 )

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 ) ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 ) 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

List, Stack, and Queues

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

STACKS AND QUEUES. Problem Solving with Computers-II

STACKS AND QUEUES. Problem Solving with Computers-II STACKS AND QUEUES Problem Solving with Computers-II 2 Stacks container class available in the C++ STL Container class that uses the Last In First Out (LIFO) principle Methods i. push() ii. iii. iv. pop()

More information

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

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

More information

Lecture Data Structure Stack

Lecture Data Structure Stack Lecture Data Structure Stack 1.A stack :-is an abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards

More information

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

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours TED (10)-3071 Reg. No.. (REVISION-2010) (Maximum marks: 100) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours PART

More information

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

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

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

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows: STACKS A stack is a linear data structure for collection of items, with the restriction that items can be added one at a time and can only be removed in the reverse order in which they were added. The

More information

CS 8391 DATA STRUCTURES

CS 8391 DATA STRUCTURES DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK CS 8391 DATA STRUCTURES UNIT- I PART A 1. Define: data structure. A data structure is a way of storing and organizing data in the memory for

More information

CS8391-DATA STRUCTURES QUESTION BANK UNIT I

CS8391-DATA STRUCTURES QUESTION BANK UNIT I CS8391-DATA STRUCTURES QUESTION BANK UNIT I 2MARKS 1.Define data structure. The data structure can be defined as the collection of elements and all the possible operations which are required for those

More information

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

Stack. Data structure with Last-In First-Out (LIFO) behavior. Out

Stack. Data structure with Last-In First-Out (LIFO) behavior. Out Stack and Queue 1 Stack Data structure with Last-In First-Out (LIFO) behavior In Out C B A B C 2 Typical Operations Pop on Stack Push isempty: determines if the stack has no elements isfull: determines

More information

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

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

Ashish Gupta, Data JUET, Guna

Ashish Gupta, Data JUET, Guna Introduction In general, Queue is line of person waiting for their turn at some service counter like ticket window at cinema hall, at bus stand or at railway station etc. The person who come first, he/she

More information

Data Structures & Algorithm Analysis. Lecturer: Souad Alonazi

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

Postfix (and prefix) notation

Postfix (and prefix) notation Postfix (and prefix) notation Also called reverse Polish reversed form of notation devised by mathematician named Jan Łukasiewicz (so really lü-kä-sha-vech notation) Infix notation is: operand operator

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

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

CS 206 Introduction to Computer Science II

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

CS 206 Introduction to Computer Science II

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

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS LECTURE 8 Babeş - Bolyai University Computer Science and Mathematics Faculty 2017-2018 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 information

SNS COLLEGE OF TECHNOLOGY

SNS COLLEGE OF TECHNOLOGY SNS COLLEGE OF TECHNOLOGY COIMBATORE 5 DEPARTMENT OF COMPUTER SIENCE AND ENGINEERING (UG & PG) Second Year Computer Science and Engineering, rd Semester 2 Marks Question and Answer Subject Code & Name:

More information

17CS33:Data Structures Using C QUESTION BANK

17CS33: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 information

Class / Sem: I CSE / II Semester Subject Code: CS 6202 Subject: Programming and Data Structures I Prepared by T. Vithya Unit IV - LINEAR DATA STRUCTURES STACKS AND QUEUES Stack ADT Evaluating arithmetic

More information

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

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE TED (10)-3071 Reg. No.. (REVISION-2010) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours (Maximum marks: 100)

More information

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

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

More information

12 Abstract Data Types

12 Abstract Data Types 12 Abstract Data Types 12.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT). Define

More information

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

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

More information

infix expressions (review)

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

More information

S.SAKTHI, LECTURER/IT

S.SAKTHI, LECTURER/IT NH 67, Karur Trichy Highways, Puliyur C.F, 639 114 Karur District DATA STRUCTURES AND ALGORITHMS QUESTION BANK PREPARED BY: S.SAKTHI-LECTURER/IT BRANCH/YEAR: EEE/II UNIT-I (LINEAR STRUCTURES) 1. What is

More information

Lecture 4 Stack and Queue

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

LIFO : Last In First Out

LIFO : Last In First Out Introduction Stack is an ordered list in which all insertions and deletions are made at one end, called the top. Stack is a data structure that is particularly useful in applications involving reversing.

More information

The time and space are the two measure for efficiency of an algorithm.

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

CS8391-DATA STRUCTURES

CS8391-DATA STRUCTURES ST.JOSEPH COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERI NG CS8391-DATA STRUCTURES QUESTION BANK UNIT I 2MARKS 1.Explain the term data structure. The data structure can be defined

More information

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions

More information

PA3 Design Specification

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

More information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures MIDTERM EXAMINATION Spring 2010 CS301- Data Structures Question No: 1 Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the

More information

Stacks, Queues and Hierarchical Collections

Stacks, Queues and Hierarchical Collections Programming III Stacks, Queues and Hierarchical Collections 2501ICT Nathan Contents Linked Data Structures Revisited Stacks Queues Trees Binary Trees Generic Trees Implementations 2 Copyright 2002- by

More information

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) An interesting definition for stack element The stack element could be of any data type struct stackelement int etype; union int ival;

More information

The Bucharest University of Economic Studies. Data Structures. ADTs-Abstract Data Types Stacks and Queues

The Bucharest University of Economic Studies. Data Structures. ADTs-Abstract Data Types Stacks and Queues The Bucharest University of Economic Studies Data Structures ADTs-Abstract Data Types Stacks and Queues Agenda Definition Graphical representation Internal interpretation Characteristics Operations Implementations

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS DATA STRUCTURES AND ALGORITHMS UNIT 1 - LINEAR DATASTRUCTURES 1. Write down the definition of data structures? A data structure is a mathematical or logical way of organizing data in the memory that consider

More information

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

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

More information

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

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 18 EXAMINATION Subject Name: Data Structure Model wer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in

More information

Data Structures. Chapter 06. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU

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

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

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

Lists, Stacks and Queues in C. CHAN Hou Pong, Ken CSCI2100A Data Structures Tutorial 4

Lists, Stacks and Queues in C. CHAN Hou Pong, Ken CSCI2100A Data Structures Tutorial 4 Lists, Stacks and Queues in C CHAN Hou Pong, Ken CSCI2100A Data Structures Tutorial 4 Outline Structure Linked List Overview Implementation Stack Overview Implementation Queue Overview Implementation 2

More information

CSE 230 Intermediate Programming in C and C++

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

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : I / II Section : CSE - 1 & 2 Subject Code : CS6202 Subject Name : Programming and Data Structures-I Degree & Branch : B.E C.S.E. 2 MARK

More information

Stacks and Queues. CSE 373 Data Structures Lecture 6

Stacks and Queues. CSE 373 Data Structures Lecture 6 Stacks and Queues CSE 373 Data Structures Lecture 6 Readings and References Reading Sections 3.3 and 3.4 10/11/02 Stacks and Queues - Lecture 6 2 Stacks A list for which Insert and Delete are allowed only

More information

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

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

More information

15. Stacks and Queues

15. Stacks and Queues COMP1917 15s2 15. Stacks and Queues 1 COMP1917: Computing 1 15. Stacks and Queues Reading: Moffat, Section 10.1-10.2 Overview Stacks Queues Adding to the Tail of a List Efficiency Issues Queue Structure

More information

Stack ADT. ! push(x) puts the element x on top of the stack! pop removes the topmost element from the stack.

Stack ADT. ! push(x) puts the element x on top of the stack! pop removes the topmost element from the stack. STACK Stack ADT 2 A stack is an abstract data type based on the list data model All operations are performed at one end of the list called the top of the stack (TOS) LIFO (for last-in first-out) list is

More information

List, Stack and Queue Implementation

List, Stack and Queue Implementation Roy Chan CSC2100B Data Structures Tutorial 2 (Version 2) January 21, 2009 1 / 39 1 CSC2100B Online Judge Score 2 Structure 3 Linked List Overview Implementation 4 Stack Overview Implementation 5 Queue

More information

Lists (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues

Lists (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues By: Pramod Parajuli, Department of Computer Science, St. Xavier

More information

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

Cpt S 122 Data Structures. Course Review Midterm Exam # 1 Cpt S 122 Data Structures Course Review Midterm Exam # 1 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 1 When: Friday (09/28) 12:10-1pm Where:

More information

Linear Data Structure

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

More information

Top of the Stack. Stack ADT

Top of the Stack. Stack ADT Module 3: Stack ADT Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Stack ADT Features (Logical View) A List that

More information

CH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES

CH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES CH4.2-4.3. ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305 Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n

More information

Department of Computer Science and Technology

Department of Computer Science and Technology UNIT : Stack & Queue Short Questions 1 1 1 1 1 1 1 1 20) 2 What is the difference between Data and Information? Define Data, Information, and Data Structure. List the primitive data structure. List the

More information

Lecture No.04. Data Structures

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

Table of Contents. Chapter 1: Introduction to Data Structures... 1

Table of Contents. Chapter 1: Introduction to Data Structures... 1 Table of Contents Chapter 1: Introduction to Data Structures... 1 1.1 Data Types in C++... 2 Integer Types... 2 Character Types... 3 Floating-point Types... 3 Variables Names... 4 1.2 Arrays... 4 Extraction

More information

Queues. October 20, 2017 Hassan Khosravi / Geoffrey Tien 1

Queues. October 20, 2017 Hassan Khosravi / Geoffrey Tien 1 Queues October 20, 2017 Hassan Khosravi / Geoffrey Tien 1 Queue ADT Queue ADT should support at least the first two operations: enqueue insert an item to the back of the queue dequeue remove an item from

More information

Content: Learning Objectives

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

Introduction to Data Structure

Introduction to Data Structure Introduction to Data Structure Introduction to Data Structure Computer is an electronic machine which is used for data processing and manipulation. When programmer collects such type of data for processing,

More information

Arrays and Linked Lists

Arrays and Linked Lists Arrays and Linked Lists Abstract Data Types Stacks Queues Priority Queues and Deques John Edgar 2 And Stacks Reverse Polish Notation (RPN) Also known as postfix notation A mathematical notation Where every

More information

Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)

Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113) Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113) 1. The number of interchanges required to sort 5, 1, 6, 2 4 in ascending order using Bubble Sort (A)

More information

DS Assignment II. Full Sized Image

DS Assignment II. Full Sized Image DS Assignment II 1. A) For the Towers of Hanoi problem, show the call tree during the recursive call Towers(3, A, C, B). In the tree, label the root node as Towers (3, A, C, B) while marking all the intermediate

More information

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

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

More information

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved Stacks Chapter 5 Copyright 2012 by Pearson Education, Inc. All rights reserved Contents Specifications of the ADT Stack Using a Stack to Process Algebraic Expressions A Problem Solved: Checking for Balanced

More information

Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis

Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis p. 5 Statement Constructs p. 5 Pseudocode Example p.

More information

Types of Data Structures

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

Stacks, Queues (cont d)

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

Information Science 2

Information Science 2 Information Science 2 - Basic Data Structures- Week 02 College of Information Science and Engineering Ritsumeikan University Today s class outline l Basic data structures: Definitions and implementation

More information

Top of the Stack. Stack ADT

Top of the Stack. Stack ADT Module 3: Stack ADT Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Stack ADT Features (Logical View) A List that

More information

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #13

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #13 Department of Computer Science & Engineering Indian Institute of Technology Kharagpur Topic: Stack and Queue Practice Sheet #13 Date: 04-04-2017 1. Consider the following sequence of push and pop operations

More information

Definition of Stack. 5 Linked Structures. Stack ADT Operations. ADT Stack Operations. A stack is a LIFO last in, first out structure.

Definition of Stack. 5 Linked Structures. Stack ADT Operations. ADT Stack Operations. A stack is a LIFO last in, first out structure. 5 Linked Structures Definition of Stack Logical (or ADT) level: A stack is an ordered group of homogeneous items (elements), in which the removal and addition of stack items can take place only at the

More information

Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Introduction to Data Structures and Algorithms Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective way. Data Structures

More information

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use? Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use? The heterogeneous linked list contains different data types in its nodes and we need a link

More information

PESIT Bangalore South Campus Department of MCA Course Information for

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

UNIT 2. What is stack? How would you perform the operations on stack? How the stack is useful to evaluate the expression? (11 Marks Nov 2010)

UNIT 2. What is stack? How would you perform the operations on stack? How the stack is useful to evaluate the expression? (11 Marks Nov 2010) 1 UNIT 2 Stacks: Definition operations - applications of stack. Queues: Definition - operations - Priority queues - De queues Applications of queue. Linked List: Singly Linked List, Doubly Linked List,

More information

CS 216 Exam 1 Fall SOLUTION

CS 216 Exam 1 Fall SOLUTION CS 216 Exam 1 Fall 2004 - SOLUTION Name: Lab Section: Email Address: Student ID # This exam is closed note, closed book. You will have an hour and fifty minutes total to complete the exam. You may NOT

More information

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

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

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model answer and the answer written by candidate may

More information

(b) Give as accurate (Big-Oh) an analysis as you can of the expected running time of each algorithm.

(b) Give as accurate (Big-Oh) an analysis as you can of the expected running time of each algorithm. Problem DS-02-07 (b) (e) Suppose you need to generate a random permutation of the first N integers. For example, 4, 3,, 5, 2 and 3,, 4, 2, 5 are legal permutation, but 5, 4,, 2, is not, because one number

More information

Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass Marks: 24

Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass Marks: 24 Prepared By ASCOL CSIT 2070 Batch Institute of Science and Technology 2065 Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass

More information