0% found this document useful (0 votes)
109 views43 pages

BE03000081 DS Unit 2 Part1

Unit 2 of the Data Structures course covers Linear Data Structures, focusing on arrays, stacks, queues, and linked lists. It includes detailed explanations of array types, access methods, initialization, and representation, as well as applications of arrays in various data structures. Additionally, it discusses sparse matrices and their representation, emphasizing the importance of understanding memory allocation and address calculation for efficient data management.

Uploaded by

jefovo4114
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views43 pages

BE03000081 DS Unit 2 Part1

Unit 2 of the Data Structures course covers Linear Data Structures, focusing on arrays, stacks, queues, and linked lists. It includes detailed explanations of array types, access methods, initialization, and representation, as well as applications of arrays in various data structures. Additionally, it discusses sparse matrices and their representation, emphasizing the importance of understanding memory allocation and address calculation for efficient data management.

Uploaded by

jefovo4114
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

New L.

J Institute of Engineering and Technology


Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

Unit 2 LINEAR DATA STRUCTURE

Syllabus Array: Representation of arrays, Applications of arrays, sparse matrix and its
representation
Stack: Stack-Definitions & Concepts, Operations On Stacks, Applications of Stacks,
Polish Expression, Reverse Polish Expression And Their Compilation, Recursion,
Tower of Hanoi
Queue: Representation Of Queue, Operations On Queue, Circular Queue, Priority
Queue, Array representation of Priority Queue, Double Ended Queue, Applications of
Queue
Linked List: Singly Linked List, Doubly Linked list, Circular linked list, Linked
implementation of Stack, Linked implementation of Queue, Applications of linked list.

Array

 What is an Array?

 An array is a data structure that contains a group of elements.


 Typically these elements are all of the same data type, such as an integer or
string.
 Arrays are commonly used in computer programs to organize data so that a
related set of values can be easily sorted or searched.

 An array is a collection of data items, all of the same type, accessed using a
common name.

 Types of Array:

1. One Dimensional
2. Two Dimensional
3. Multi Dimensional

 One Dimensional Array:


o An array which store its elements into a single row is called one
dimensional array.

o Syntax for Declare an Array

datatype ArrayName[Arraysize];

For Example: Float Mark[5];

NLJIET Page | 1
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

o Here, we declared an array, mark, of floating-point type. And its size is


5. Meaning, it can hold 5 floating-point values.

 How to Access Array Elements?

o You can access elements of an array by indices.


o Suppose you declared an array mark as above. The first element is
mark[0], the second element is mark[1] and so on.
o Arrays have 0 as the first index, not 1. In our example, mark[0] is the
first element.
o If the size of an array is n, to access the last element, the n-1 index is
used. In this example, mark[4].
o Suppose the starting address of mark[0] is 2120. Then, the address of the
mark[1] will be 2124. Similarly, the address of mark[2] will be 2128 and
so on. This is because the size of a float is 4 bytes.

 How to Initialize an Array?


o It is possible to initialize an array during declaration. For example,
int mark[5] = {19, 10, 8, 17, 9};

o Input and Output Array Element


o Here's how you can take input from the user and store it in an array
element.
scanf("%d", &mark[2]); // take input and store it in the 3rd element
scanf("%d", &mark[i-1]); // take input and store it in the ith element

o Here's how you can print an individual element of an array.


printf("%d", mark[0]); // print the first element of the array
printf("%d", mark[2]); // print the third element of the array
printf("%d", mark[i-1]); // print ith element of the array

o Example: Array Input/output


#include<stdio.h>
void main()
{
int a[4];
int i, j;

NLJIET Page | 2
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

printf("Enter array element:");


for(i = 0; i < 4; i++)
{
scanf("%d", &a[i]); //Run
time array initialization
}
printf(“Array elements are:");
for(j = 0; j < 4; j++)
{
printf("%d\n", a[j]);
}
}

 Two Dimensional Array:


o C language supports multidimensional arrays also.
o The simplest form of a multidimensional array is the two-dimensional
array.
o An array of arrays is known as 2D array.
o The two dimensional (2D) array in C programming is also known as
matrix.
o A matrix can be represented as a table of rows and columns.
o Two-dimensional arrays are declared as follows,

data-type array-name[row-size][column-size] ;
For Example, float x[3][4];

o Here, x is a two-dimensional (2d) array. The array can hold 12 elements.


You can think the array as a table with 3 rows and each row has 4
columns.

o Similarly, you can declare a three-dimensional (3d) array.


o For example, float y[2][4][3];
o Here, the array y can hold 24 elements.

NLJIET Page | 3
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

 How to initialize 2D Array?


o Different ways to initialize two-dimensional
array:
int c[2][3] = {{1, 3, 0}, {-1, 5, 9}};
int c[][3] = {{1, 3, 0}, {-1, 5, 9}};
int c[2][3] = {1, 3, 0, -1, 5, 9};

o Runtime initialization of a two dimensional


Array
o Suppose array size is a[3][4]
for(i = 0; i < 3;i++)
{
for(j = 0; j < 4; j++)
{
scanf("%d", &a[i][j]);
}
}

 Example: 2D Array Input/output


#include<stdio.h>
void main()
{
int arr[3][4];
int i, j, k;
printf("Enter array element");
for(i = 0; i < 3;i++)
{
for(j = 0; j < 4; j++)
{
scanf("%d", &arr[i][j]);
}
}
for(i = 0; i < 3; i++)
{
for(j = 0; j < 4; j++)
{
printf("%d", arr[i][j]);
}
}
}

NLJIET Page | 4
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

Array Representation

 Array Representation
 The elements of a Two dimensional array can be arranged in two ways.
1. Row major Representation
2. Column major Representation

 Row major Representation:


o If the elements are stored in row wise manner then it is called row major
representation.
o If we want to store element 10,20,30,40,50,60,70,80 and if size of array
is a[3][4] then,

 Column major Representation:


o If the elements are stored in column wise manner then it is called Column
major representation.
o If we want to store element 10,20,30,40,50,60,70,80 and if size of array
is a[3][4] then,

 Address calculation of Array Elements


 You can calculate the address of any element which is stored in an array.
 To calculate the address of any element you must know,
1. Base Address (Address of first element (which is at index 0).
2. Data Types of Array (int(2bytes),Float(4 bytes)).
3. Size of Array.
4. Representation of array (Row major or Column Major)
5. index of element for which you want to find address.
NLJIET Page | 5
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

6. Formula.

 Formula for Calculating Address


o Row Major System:
The address of a location in Row Major System is calculated using the
following formula:
Address of A [ I ][ J ] = B + W * [ N * ( I – Lr ) + ( J – Lc ) ]
o Column Major System:
The address of a location in Column Major System is calculated using
the following formula:
Address of A [ I ][ J ] Column Major Wise = B + W * [( I – Lr ) + M
* ( J – Lc )]

Where,
B = Base address(Address of First Element)
I = Row subscript of element whose address is to be found
J = Column subscript of element whose address is to be found
W = Storage Size of one element stored in the array (in byte) (Int=2
byte,Float=4 byte)
Lr = Lower limit of row/start row index of matrix, if not given assume 0
(zero)
Lc = Lower limit of column/start column index of matrix, if not given
assume 0 (zero)
M = Number of row of the given matrix
N = Number of column of the given matrix

 Example 1: Consider an integer array int a[3][4].if the base address is


1050,find the address of the element a[2][2] with row major and column
major representation of array.

o Row Major System:


The address of a location in Row Major System is calculated using the
following formula:
Address of A [ I ][ J ] = B + W * [ N * ( I – Lr ) + ( J – Lc ) ]

B = Base address(Address of First Element)=1050


I = Row subscript of element whose address is to be found=2
J = Column subscript of element whose address is to be found=2
W = Storage Size of one element stored in the array =2 bytes(because
datatype is int).
Lr = Lower limit of row/start row index of matrix, if not given assume 0
(zero)=0

NLJIET Page | 6
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

Lc = Lower limit of column/start column index of matrix, if not given


assume 0 (zero)=0
M = Number of row of the given matrix=3
N = Number of column of the given matrix=4

Address of A [ I ][ J ] = B + W * [ N * ( I – Lr ) + ( J – Lc ) ]
A [ 2 ][ 2 ] = 1050 + 2 * [ 4 * ( 2 – 0 ) + ( 2 – 0) ]
= 1070

o Column Major System:


The address of a location in Column Major System is calculated using
the following formula:
Address of A [ I ][ J ] Column Major Wise = B + W * [( I – Lr ) + M
* ( J – Lc )]

A [ 2 ][ 2 ] = 1050 + 2 * [ ( 2 – 0 ) + 3*( 2 – 0) ] = 1050+16 = 1066

 Example 2: Example 2:A 2-D array defined as A[r, c] where 1 ≤ r ≤ 4, 5≤


c ≤ 8, requires 2 bytes of memory for each element. If the array is stored
in Row-major order form and Column-major order form, calculate the
address of A[3,7] given the Base address as 2000

Size of Array A[1:4][5:8]


B=2000, W=2 byte, I=3, J=7, Lr=1, Lc=5, M=4, N= 4

o Row Major System:


The address of a location in Row Major System is calculated using the
following formula:
Address of A [ I ][ J ] = B + W * [ N * ( I – Lr ) + ( J – Lc ) ]

NLJIET Page | 7
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

=2000 + 2[ 4*(3-1) +( 7-5)


=2000 + 2*10
=2000+20
=2020

o Column Major System:


The address of a location in Column Major System is calculated using
the following formula:
Address of A [ I ][ J ] Column Major Wise = B + W * [( I – Lr ) + M * (
J – Lc )]
=2000 + 2[ (3-1) +4*( 7-5)
=2000 + 2*10
=2000+20
=2020

 Example 3:Given a two dimensional array Z1(2:9, 9:18) stored in


column-major order with base address 100 and size of each element is 4
bytes, find address of the element Z1(4, 12).

Size of Array A[2:9][9:18]


B=100, W=4 byte, I=4, J=12, Lr=2, Lc=9, M=8(9-2+1), N= 10(18-9+1)

o Column Major System:


The address of a location in Column Major System is calculated using
the following formula:

NLJIET Page | 8
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

Address of A [ I ][ J ] Column Major Wise = B + W * [( I – Lr ) + M *


(J – Lc )]
=100 + 4[ (4-2) +8*( 12-9)
=100 + 4[2+8*3]
=100+4*26
=100+104
=204

o Row Major System:


The address of a location in Row Major System is calculated using the
following formula:
Address of A [ I ][ J ] = B + W * [ N * ( I – Lr ) + ( J – Lc ) ]
=100 + 4[ 10(4-2) +( 12-9)
=100 + 4[20+3]
=100+4*23
=100+92
=192

NLJIET Page | 9
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

Applications of Array

 Applications

 Array are used for representing some sequential data structures such as stack
and queues.
 Array are used to represent sparse matrices.
 Array are widely used to implement mathematical vector, matrices and other
kind of tables.
 Array can be used for sorting elements in ascending or descending order.
 It is used in every possible situation where you need to gather similar objects
at one place.
 Arrays are used to implement Search Algorithms.
 Arrays are also used to implement CPU Scheduling Algorithms.

Sparse Matrix and its Representation

 Sparse Matrix

 Sparse matrix is a matrix which contains very few non-zero elements.


 A matrix that is not sparse is called dense matrix.
 Normally matrices are represent in a two dimensional array.
 In a matrix if there are m rows and n columns then the space required to store
the numbers will be m*n*s where s is the number of bytes required to store
the value.
 Suppose, there are 10 rows and 10 columns and we have to store the integer
values then space complexity will be 10*10*2 =200 bytes.
 For example, if the matrix is of size 10*10 and only 10 elements are nonzero.
Then for accessing 10 elements one has to make 100 times scan.
 Also only 10 spaces will be with non-zero elements, remaining spaces of
matrix will be filled with zeros only.
 The concept of sparse matrix has therefore came forward to
investigate that representation will store only non-zero elements of the matrix
and still carry out the operations quite efficiently.

 Sparse Matrix Representation

 Representation of sparse matrix will be a triplet only.


 Sparse matrix means very few non-zero elements having in it.
 Rest of the spaces are having the values zero which are basically useless
values.

NLJIET Page | 10
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

 So in this efficient representation we will consider all the non-zero values


along with their positions.
 For example –Suppose a matrix is 6 * 7 and the number of non-zero values
are say 8.

 In normal representation of the matrix this will take 6 * 7 *2 =84 bytes.


 In row wise representation of sparse matrix the 0th rows will store total rows
of the matrix, total column of the matrix, and the total non-zero values.

 In normal representation of the matrix this will take 6 * 7 *2 =84 bytes.


 In sparse matrix representation (total no of non-zero values +1) * 3 * 2 bytes.
 So it will be (8 + 1) * 3 * 2 = 54 Bytes.
 Clearly in normal representation 30 bytes is unused space, which are saving
in the sparse matrix representation.
Stack Definition and Concept

 Stack Definition and Concept

 A linear list which allow insertion and deletion of an element at one end only
is called Stack.
 A Stack is a data structure which is used to store data in a particular order.
 It follows Last In First Out (LIFO) Order.
NLJIET Page | 11
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

 The element which is inserted last, that will be come out first.
 There are many real-life examples of a stack.
 Consider an example of plates stacked over one another in the canteen.

Operations on Stack
There are four operations which we can perform on stack.

 Push (Insert): Which insert an element at TOP of the stack.


 Pop(Delete): Which Remove the most recently added elements from the
TOP of the stack.
 Peep (Search): To find ith element from TOP of the stack.
 Change (Update): Changes the value of the ith element from the TOP of the
stack.

 TOP is a pointer that points to the top element of stack.


 Initially when the Stack is Empty, TOP has a value of “Zero”.
 Each time a new element is inserted in the stack, the pointer is Incremented
by “one”.
 The pointer is decremented by “one” each time a deletion is made from the
stack.

NLJIET Page | 12
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

 Procedure: PUSH(S,TOP,X)
 This procedure insert an element X to the top of a stack.
 Stack is represented by a vector S Containing N Elements.
 A pointer TOP represents the top element of the stack.

1. [Check for Stack overflow]


If Top ≥ N
then Write (‘Stack Overflow’)
Return

2. [Increment Top]
Top ← Top + 1

3. [Insert Element]
S[Top] ← X

4. [Finished]
Return

 Procedure: POP(S,TOP)
 This procedure remove and returns the top element from a stack.
 Stack is represented by a vector S Containing N Elements.
 A pointer TOP represents the top element of the stack.

1. [Check for underflow on Stack]


If Top = 0
then Write (‘Stack Underflow on Pop’)
Exit

2. [Decrement Pointer]
Top ← Top-1

3. [Return former top element of Stack]


Return (S[Top+1])

NLJIET Page | 13
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

 Procedure: PEEP(S,TOP,I)
 This procedure returns the value of ith element from top of the stack.
 The element is not deleted by this function.
 Stack is represented by a vector S Containing N Elements.
 A pointer TOP represents the top element of the stack.

1. [Check for Stack Underflow]


If (Top - I + 1) ≤ 0
then Write (‘Stack Underflow on Peep’)
Exit

2. [Return Ith element from top of the stack]


Return (S[Top-I+1])

 Procedure: CHANGE(S,TOP,X,I)
 This procedure changes the value of ith element from the top of the stack to
the value contained in X.
 Stack is represented by a vector S Containing N Elements.
 A pointer TOP represents the top element of the stack

1. [Check for stack underflow]


If (Top - I + 1) ≤ 0
then Write (‘Stack Underflow on
Change’)
Exit

2. [Change the Ith element from top of stack]


S[Top - I + 1] ← X

3. [Finished]
Return

Application of Stack

 Expression Conversion: An expression is a collection of operators and


operands that represents a specific value.
 In above definition, operator is a symbol which performs a particular task like
arithmetic operation.
 Operands are the values on which the operators can perform the task.
 For Example, A + B * C

NLJIET Page | 14
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

 An arithmetic expression can be written in three different but equivalent


notations, i.e., without changing the essence or output of an expression.
 These notations are –
1. Infix Notation
2. Prefix (Polish) Notation
3. Postfix (Reverse-Polish) Notation

 Infix Notation: We write expression in infix notation, e.g. a + b, where


operators are used in-between operands.

 Prefix Notation: In this notation, operator is prefixed to operands, i.e.


operator is written ahead of operands. For example, +ab. This is equivalent to
its infix notation a + b. Prefix notation is also known as Polish Notation.

 Postfix Notation: This notation style is known as Reversed Polish Notation


(RPN). In this notation style, the operator is post fixed to the operands i.e., the
operator is written after the operands. For example, ab+. This is equivalent to
its infix notation a + b.

Infix = a + b
Prefix = +ab
Postfix = ab+

 Precedence and Associativity:


o When an operand is in between two different operators, which operator
will take the operand first, is decided by the precedence of an operator
over others. For example –

o As multiplication operation has precedence over addition, b * c will be


evaluated first.
o Associativity describes the rule where operators with the same
precedence appear in an expression.
o For example, in expression a + b − c, both + and – have the same
precedence, then which part of the expression will be evaluated first, is
determined by associativity of those operators.
o Here, both + and − are left associative, so the expression will be
evaluated as (a + b) − c.
o Precedence and associativity determines the order of evaluation of an
expression. Following is an operator precedence and associativity table
(highest to lowest) –

NLJIET Page | 15
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

o Infix to postfix conversion: There are two algorithms for that.

1. UNPARENTHESIZED_SUFFIX(Without Bracket).
e.g. a + b * c - d / e

2. REVPOL(With Bracket)
e.g. a * (b + c) – d

o Algorithm UNPARENTHESIZED_SUFFIX

This algorithm converts the string INFIX to its reverse Polish string
equivalent.
INFIX: Input string INFIX representing an infix expression whose single
character symbols have precedence values and ranks as given in Table.
S: vector S representing a stack.
NEXTCHAR: String function NEXTCHAR which, when invoked,
returns the next character of the input string.
RANK: RANK contains the value of each head of the reverse Polish
string.
NEXT: NEXT contains the symbol being examined.
TEMP:TEMP is a temporary variable which contains the unstacked
element.
POLISH: which contain final output string(postfix form)
We assume that the given input string is padded on the right with the
special symbol “#”.

NLJIET Page | 16
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

Algorithm UNPARENTHESIZED_SUFFIX:

1. [Initialize the stack]


Top ← 1
S[Top] ← ‘#’

2. [Initialize output string and rank count]


POLISH ← ‘’
RANK ← 0

3. [Get first input symbol]


NEXT ← NEXTCHAR(INFIX)

4. [Translate the infix expression]


Repeat thru step 6 while NEXT ≠ ‘#’

5. [Remove symbols with greater or equal precedence from stack]


Repeat while f(NEXT) ≤ f(S[Top])
TEMP ← Pop(S, Top) (this copies the stack contents into TEMP)
POLISH ← POLISH O TEMP
RANK ← RANK + r(TEMP)
If RANK < 1
then Write (‘INVALID’)
Exit

6. [Push current symbol onto stack and obtain next input symbol]
Call Push (S, Top, NEXT)
NEXT ← NEXTCHAR (INFIX)

7. [Remove remaining elements from stack]


Repeat while S[Top] ≠ ‘#’
TEMP ← Pop (S, Top)
POLISH ← POLISH O TEMP
RANK ← RANK + r(TEMP)
If RANK < 1
then Write (‘INVALID’)
Exit

8. [Is the expression valid?]


If RANK = 1
then Write (‘VALID’)
else Write (‘INVALID’)
Exit

NLJIET Page | 17
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

o Example: A + B * C –D

INFIX: A + B * C –D #

o Algorithm REVPOL:

o This algorithm converts INFIX into reverse polish and places the result
into POLISH.
o Given an input string INFIX containing an infix expression which has
been padded on the right with ‘)’.
o All Symbol have precedence value given in table.
o Stack is represented by vector S, TOP denotes the top of the stack,
Algorithm PUSH and POP are used for stack manipulation.
o Function NEXTCHAR returns the next symbol from given input string.
o The integer variable RANK contains the rank of Expression.
o The string variable TEMP is used for temporary storage purpose.

1. [Initialize stack]
Top ← 1
S[Top] ← ‘(‘

NLJIET Page | 18
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

2. [Initialize output string and rank count]


POLISH ← ‘’
RANK ← 0

3. [Get first input symbol]


NEXT ← NEXTCHAR (INFIX)

4. [Translate the infix expression]


Repeat thru step 7 while NEXT ≠ ‘’

5. [Remove symbols with greater precedence from stack]


If Top < 1
then Write (‘INVALID’)
Exit
Repeat while f(NEXT) < g(S[TOP])
TEMP ← Pop (S, Top)
POLISH ← POLISH O TEMP
RANK ← RANK + r(TEMP)
If RANK < 1
then Write (‘INVALID’)
Exit

6. [Are there matching parentheses?]


If f(NEXT) ≠ g(S[Top])
then Call Push (S, Top, NEXT)
else Pop (S, Top)

7. [Get next input symbol]


NEXT ← NEXTCHAR (INFIX)

8. [Is the expression valid?]


If Top ≠ 0 or RANK ≠ 1
then Write (‘INVALID’)
else Write (‘VALID’)
Exit

o Example: A *(B + C ) –D
INFIX: (A *(B + C) –D)

NLJIET Page | 19
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

o Algorithm Evaluate_Postfix

o Given an input string POSTFIX represent postfix expression.


o This algorithm evaluates postfix expression and put the result into
variable Answer.
o Stack is represent by vector S, TOP denotes the top of the stack,
Algorithm PUSH and POP are used for stack manipulation.
o Function NEXTCHAR returns the next symbol from given input string.
o OP1, OP2 and TEMP are used for temporary storage purpose.
o PERFORM_OPERATION is a function which perform required
operation on OP1 and OP2.

1. [Initialize Stack]
Top ← 0
Answer← 0

2. [Evaluate the postfix expression ]


Repeat until last character
TEMP← NEXTCHAR (POSTFIX)
If TEMP is OPERAND
Then PUSH(S,TOP,TEMP)
Else
OP2 ← POP(S,TOP)
OP1 ← POP(S,TOP)
NLJIET Page | 20
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

Answer ← PERFORM_OPERATION(OP1,OP2,TEMP)
PUSH(S, TOP, Answer)

3. [Return Answer from Stack]


Return (POP(S,TOP))

o Algorithm Evaluate_Postfix Example

POSTFIX: 9 3 4 * 8 + 4 / -

POSTFIX: 5 4 6 + * 4 9 3 / + *

o Algorithm Evaluate_Prefix

o Given an input string PREFIX represent prefix expression.


o This algorithm evaluates prefix expression and put the result into
variable Answer.
o Stack is represent by vector S, TOP denotes the top of the stack,
Algorithm PUSH and POP are used for stack manipulation.
o Function NEXTCHAR returns the next symbol from given input string.
o OP1,OP2and TEMPare used for temporary storage purpose.
o PERFORM_OPERATION is a function which perform required
operation on OP1 and OP2.

NLJIET Page | 21
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

1. [Initialize Stack]
Top ← 0
Answer← 0

2. [Evaluate the prefix expression]


Repeat from last character up to First
TEMP← NEXTCHAR (PREFIX)
If TEMP is OPERAND
Then PUSH(S,TOP,TEMP)
Else
OP1 ← POP(S,TOP)
OP2← POP(S,TOP)
Answer ← PERFORM_OPERATION(OP1,OP2,TEMP)
PUSH(S, TOP, Answer)

3.[Return Answer from Stack]


Return (POP(S,TOP))

o Example 1:Prefix Evaluation

PREFIX: -9 / + * 3 4 8 4

o Example 2: Prefix Evaluation

PREFIX: + * A B –C + C * B A (A= 4, B=8, C=12)

+ * 48 –12+ 12* 8 4

NLJIET Page | 22
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

o Example: infix to postfix

A + B * C –D Infix

o Example: Infix to postfix


A *(B + C ) –D Infix

NLJIET Page | 23
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

o Example: postfix to infix


ABC*+D- Postfix

o Example: infix to prefix


A + B * C –D Infix

o Example: prefix to infix


-+A*BCD Prefix

o Example: Transform the following expression to postfix (reverse


polish) and evaluate postfix expression by assuming A=1, B=2,C=3,
D=4, E=6, F=6, G=1, I=3 and J=3

NLJIET Page | 24
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

A + B -C *D / E +F $ G / (I+J) Infix

Recursion

 What is Recursion?

 The process in which a function calls itself directly or indirectly is called


recursion and the corresponding function is called a recursive function.
 A recursive algorithm takes one step toward solution and then recursively call
itself to further move.
 The algorithm stops once we reach the solution.
 Since called function may further call itself, this process might continue
forever.
 So it is essential to provide a base case to terminate this recursion process.

 Steps to Implement Recursion

 Recursion, in programming, involves a function calling itself to solve a


problem.
 The process can be broken down into distinct steps:

 Base Case Definition:

o Identify the simplest instance of the problem that can be solved directly
without further recursive calls.
o This is the stopping condition for the recursion.

NLJIET Page | 25
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

o Without a base case, the function would call itself infinitely, leading to a
stack overflow.

 Recursive Case Definition:

o Express the larger problem in terms of one or more smaller, similar


subproblems.
o The function calls itself with these smaller inputs, effectively breaking
down the original problem into manageable parts.

 Work Towards the Base Case:

o Each recursive call must bring the problem closer to the base case.
o This means the input to the recursive call should be a smaller or simpler
version of the original input.

 Combining Subproblem Solutions:

o After the recursive calls return their solutions for the sub problems,
combine these results to construct the solution for the original, larger
problem.
o This step is particularly relevant in problems like tree traversals or
sorting algorithms.

 Example : Sum of Natural Numbers

o Let us consider a problem to find the sum of natural numbers, there are
several ways of doing that but the simplest approach is simply to add the
numbers starting from 0 to n.

 Need of Recursion?

o Recursion helps in logic building.

NLJIET Page | 26
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

o Recursive thinking helps in solving complex problems by breaking them


into smaller sub problems.
o Recursive solutions work as a basis for Dynamic Programming and
Divide and Conquer algorithms.
o Certain problems can be solved quite easily using recursion like Towers
of Hanoi (TOH), Inorder/Preorder/Postorder Tree Traversals, DFS of
Graph, etc.

Tower of Hanoi

 Tower of Hanoi

 The Tower of Hanoi is a mathematical game or Puzzle.


 It consists of three rods and a number of disks of different sizes, which can
slide onto any rod.
 The puzzle starts with the disks in a neat stack in ascending order of size on
one rod, the smallest at the top, thus making a conical shape.
 The objective of the puzzle is to move the entire stack to another rod, obeying
the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and
placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
 With 3 disks, the puzzle can be solved in 7 moves. The minimal number of
moves required to solve a Tower of Hanoi puzzle is 2n − 1, where n is the
number of disks.
 The idea is to use the helper node to reach the destination using recursion.
Below is the pattern for this problem:

1. Shift 'N-1' disks from 'A' to 'B', using C.


2. Shift last disk from 'A' to 'C'.
3. Shift 'N-1' disks from 'B' to 'C', using A.

NLJIET Page | 27
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

Queue

 Queue Definition and Concept

 A linear list which permits deletion to be performed at one end of the list and
insertion at the other end is called queue.
 The information in such a list is processed FIFO (first in first out) or FCFS
(first come first served) manner.
 Front is the end of queue from that deletion is to be performed.
 Rear is the end of queue at which new element is to be inserted.
 Insertion operation is called Enqueue & deletion operation is called Dequeue.

Representation of Queue

 Array Representation of Queues

 Linked Representation of Queue

 Types of Queue

o Simple Queue.
o Circular Queue
o Priority Queue
o Double Ended Queue

NLJIET Page | 28
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

Operations on Simple Queue

 What is a Simple Queue?

 Insert: Insert an element at Rear End.

QINSERT (Q, F, R, N, Y)
o This procedure inserts Y at rear end of Queue.
o Queue is represented by a vector Q containing N elements.
o F is pointer to the front element of a queue.
o R is pointer to the rear element of a queue.

1. [Overflow?]
If R ≥ N
Then Write (‘Overflow’)
Return

2. [Increment rear pointer]


R←R+1

3. [Insert element]
Q[R] ← Y

4. [Is front pointer properly set?]


If F = 0
then F ← 1
Return

 Delete: Delete an Element from Front End.

QDELETE (Q, F, R)

o This function deletes & returns an element from front end of the Queue.
o Queue is represented by a vector Q containing N elements.

NLJIET Page | 29
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

o F is pointer to the front element of a queue.


o R is pointer to the rear element of a queue.

1. [Underflow?]
If F = 0
then Write (‘Underflow’)
Return (0) (‘0’ denotes an empty queue)

2. [Delete element]
Y ← Q[F]

3. [Queue empty?]
If F = R
then F ← R ← 0
else F ← F + 1 (Increment front pointer)

4. [Return element]
Return (Y)

Example of Queue Insert / Delete

NLJIET Page | 30
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

Circular Queue

 What is Circular Queue?

 Circular queue is a linear data structure.


 It follows FIFO principle.
 A more suitable method of representing simple queue which prevents an
excessive use of memory is to arrange the elements Q[1], Q[2]….,Q[n] in a
circular fashion with Q[0] following Q[n], this is called circular queue.
 In circular queue the last node is connected back to the first node to make a
circle.

CQINSERT (F, R, Q, N, Y)
o This procedure inserts Y at rear end of the Circular Queue.
o Queue is represented by a vector Q containing N elements.
o F is pointer to the front element of a queue.
o R is pointer to the rear element of a queue.

1. [Reset rear pointer?]


If R = N
then R ← 1
else R ← R + 1

2. [Overflow?]
If F = R
then Write (‘Overflow’)
Return

NLJIET Page | 31
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

3. [Insert element]
Q[R] ← Y

4. [Is front pointer properly set?]


If F = 0
then F ← 1
Return

CQDELETE (F, R, Q, N)

o This function deletes & returns an element from front end of the Circular
Queue.
o Queue is represented by a vector Q containing N elements.
o F is pointer to the front element of a queue.
o R is pointer to the rear element of a queue.

1. [Underflow?]

If F = 0
then Write (‘Underflow’)
Return (0)

2. [Delete element]
Y ← Q[F]

3. [Queue empty?]
If F = R
then F ← R ← 0
Return (Y)

4. [Increment front pointer]


If F = N
then F ← 1
else F ← F + 1
Return (Y)

Example of Circular Queue Insert / Delete

NLJIET Page | 32
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

 Algorithm: DISPLAY_CircularQueue

Input: A circular queue CQ[], front index FRONT, rear index REAR, and size
SIZE
Output: Elements of the circular queue in order from front to rear

1. IF FRONT == -1
PRINT "Queue is empty"
RETURN

2. SET i = FRONT

3. REPEAT
a. PRINT CQ[i]
b. SET i = (i + 1) % SIZE
UNTIL i == (REAR + 1) % SIZE

Priority Queue

 What is a Priority Queue?

 A priority queue is a data structure in which each element is assigned a


priority.

NLJIET Page | 33
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

 The priority of the element will be used to determine the order in which the
elements will be processed
 The general rules of processing the elements of a priority queue are
o An element with higher priority is processed before an element with a
lower priority.
o Two elements with the same priority are processed on a first-come-first-
served (FCFS) basis.
 Priority queue can be thought of as a modified queue in which when an
element has to be removed from the queue, the one with the highest-priority
is retrieved first.
 The priority of the element can be set based on various factors.
 Priority queues are widely used in operating systems to execute the highest
priority process first.
 The priority of the process may be set based on the CPU time it requires to
get executed completely.
 For example, if there are three processes, where the first process needs 5 ns to
complete, the second process needs 4 ns, and the third process needs 7 ns, then
the second process will have the highest priority and will thus be the first to
be executed.
 However, CPU time is not the only factor that determines the priority, rather
it is just one among several factors.
 Another factor is the importance of one process over another.
 In case we have to run two processes at the same time, where one process is
concerned with online order booking and the second with printing of stock
details, then obviously the online booking is more important and must be
executed first.

Representation of Priority Queue

 For example, consider the priority queue shown in Fig.

 Lower priority number means higher priority. For example, if there are two
elements A and B, where A has a priority number 1 and B has a priority
number 5, then A will be processed before B as it has higher priority than B.

 Insertion: When a new element has to be inserted in a priority queue, we have


to traverse the entire list until we find a node that has a priority lower than
that of the new element.
 The new node is inserted before the node with the lower priority.

NLJIET Page | 34
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

 However, if there exists an element that has the same priority as the new
element, the new element is inserted after that element.
 For example, consider the priority queue shown in Fig.

 If we have to insert a new element with data = F and priority number = 4, then
the element will be inserted before D that has priority number 5, which is
lower priority than that of the new element.
 So, the priority queue now becomes as shown in Fig.

 However, if we have a new element with data = F and priority number = 2,


then the element will be inserted after B, as both these elements have the same
priority but the insertions are done on FCFS basis as shown in Fig.

 Deletion: Deletion is a very simple process in this case.


 The first node of the list will be deleted and the data of that node will be
processed first.

Double Ended Queue

 What is Double Ended Queue?

 A deque (pronounced as ‘deck’ or ‘dequeue’) is a linear list in which insertion


and deletion are performed from the either end of the Queue.
 It is also known as double ended queue.

 There are two variations of Dequeue.


 Input restricted dequeue- In this dequeue,insertions can be done only at one
of the ends, while deletions can be done from both ends.

NLJIET Page | 35
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

 Output restricted dequeue: In this dequeue, deletions can be done only at one
of the ends, while insertions can be done on both ends.

 In a dequeue, two pointers are maintained, LEFT and RIGHT, which point to
either end of the dequeue.

o Example Deque: Consider a dequeue given below which has


LEFT=1, RIGHT=5
_ A B C D E _ _ _ _.
Now perform the following operations on the dequeue
1. Add F on the left.
2. Add G on the right.
3. Add H on the right.
4. Delete two alphabets from left
5. Add I on the right

1. Add F on the left.

2. Add G on the right.

3. Add H on the right.

4. Delete two alphabets from left

NLJIET Page | 36
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

5. Add I on the right

Applications of Queue
 Queue of people at any service point such as ticketing etc.
 Queue of air planes waiting for landing instructions.
 Queue of processes in OS.
 Queue is also used by Operating systems for Job Scheduling.
 When a resource is shared among multiple consumers. E.g., in case of printers
the first one to be entered is the first to be processed.
 When data is transferred asynchronously (data not necessarily received at
same rate as sent) between two processes. Examples include IO Buffers, pipes,
file IO, etc.
 Queue is used in BFS (Breadth First Search) algorithm. It helps in traversing
a tree or graph.
 Queue is used in networking to handle congestion.

 Difference Between Stack and Queue

Parameter Stack Data Structure Queue Data Structure


It is a linear data It is also a linear data structure.
structure. The objects The objects are removed and
Basics
are removed or inserted inserted from two different
at the same end. ends.
It follows the Last In,
It follows the First In, First Out
First Out (LIFO)
(FIFO) principle. It means that
Working Principle principle. It means that
the first added element gets
the last inserted element
removed first from the list.
gets deleted at first.
It uses two pointers (in a
It has only one pointer- simple queue) for reading and
the top. This pointer writing data from both the
indicates the address of ends- the front and the rear.
Pointers
the topmost element or The rear one indicates the
the last inserted one of address of the last inserted
the stack. element, whereas the front
pointer indicates the address of

NLJIET Page | 37
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

the first inserted element in a


queue.
Stack uses push and pop
Queue uses enqueue and
as two of its operations.
dequeue as two of its
The pop operation
operations. The dequeue
functions to remove the
Operations operation deletes the elements
element from the list,
from the queue, and the
while the push operation
enqueue operation inserts the
functions to insert the
elements in a queue.
element in a list.
Insertion and deletion of
It uses two ends- front and rear.
elements take place from
Structure Insertion uses the rear end, and
one end only. It is called
deletion uses the front end.
the top.
When top== max-1, it
Full Condition When rear==max-1, it means
means that the stack is
Examination that the queue is full.
full.
When top==-1, it
When front = rear+1 or front==
Empty Condition
indicates that the stack is
-1, it indicates that the queue is
Examination
empty. empty.
A Queue data structure has
A Stack data structure three types- circular queue,
Variants
does not have any types. priority queue, and double-
ended queue.
You can visualize the
You can visualize a Queue as a
Visualization Stack as a vertical
horizontal collection.
collection.
The implementation is
The implementation is
Implementation comparatively more complex
simpler in a Stack.
in a Queue than a stack.

NLJIET Page | 38
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

GTU Questions from Unit 2

Sr.
Questions CO Answer Marks
No
What is Sparse matrix? Write efficient vector
representation of following Sparse matrix.
[NLJIET]
Pg
1 2 3
10,11

What is Sparse Matrix? [NLJIET]


What is stack? Why do we use multiple stacks? Pg
2 2 3
[NLJIET] 11,12
Illustrate how stack is used in the recursion. Pg
3 2 3
[NLJIET] 11,12
Write applications of stack and queue data
Pg
structures. [NLJIET]
4 2 14,15, 3
Enlist and explain any 3 applications of stack in
35
computer science. [NLJIET]
Write an algorithm for infix to postfix conversion. Pg
5 2 3
[NLJIET] 16,17
Evaluate the following postfix expression using
6 stack. 2 Pg 21 3
(i) 53+62/*35*+ [NLJIET]
Explain Tower of Hanoi with suitable example.
[NLJIET] Pg
7 2 3
Write a recursive solution for Tower of Hanoi 25,26
problem.
Pg
8 Distinguish between stack and queue. [NLJIET] 2 3
35,36
Explain advantages of circular queue over Simple
9 2 Pg 29 3
queue. [NLJIET]
Explain the working of priority queue with Pg
10 2 3
suitable example. [NLJIET] 32,33
What is priority queue? Is simple queue is
anyhow priority queue? Explain your answer. Pg
11 2 3
[NLJIET] 32,33
What is priority queue? [NLJIET]
How to prove array is sequential and contiguous?
12 2 Pg 2 4
[NLJIET]
13 Explain row-major order and column-major order 2 Pg 5 4

NLJIET Page | 39
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

representation of 2-D array. [NLJIET]


State at least one efficient representation of a Pg
14 2 4
sparse matrix. [NLJIET] 10,11
Derive basic operation of stack and write C Pg
15 2 4
function to implement it. [NLJIET] 12,13,14
What is top of stack? Why stack is called LIFO
16 2 Pg 12 4
list? [NLJIET]
Write an algorithm to evaluate postfix expression.
Pg
17 Explain working of the algorithm using 2 4
20,21
appropriate example. [NLJIET]
Convert the following infix expressions to their
prefix and postfix equivalents.
(i) (A*B)+(C/D)-(D+E) [NLJIET]
Convert the following infix expression into
postfix expression using stack.
(i) (A-B)/C*D^(E/F)^(G+H) [NLJIET]
18 2 Pg 18 4
Convert the following infix expressions to their
prefix.
(i) (A^B*C-D+E/F/(G+H)) [NLJIET]
Translate infix expression into its equivalent post
fix expression:
A*(B+D)/E-F*(G+H/K) [NLJIET]
Write C program to find the Fibonacci sequence Extra
19 2 4
of n terms using recursion. [NLJIET] Programs
Explain Tower Of Hanoi with example. [NLJIET]
Write recursive solution for tower of Hanoi. How Pg
20 2 4
many moves require for transferring three discs? 25,26
[NLJIET]
State disadvantages of simple queue. How to
overcome it? [NLJIET]
Pg
21 Write algorithm to insert into simple queue and 2 4
26,27,28
mention the limitation of simple queue?
[NLJIET]
Design an algorithm to perform insert operation Pg
22 2 4
in circular queue. [NLJIET] 29, 30
Write algorithm to delete from circular queue and
Pg
23 mention the advantage of circular queue over 2 4
29,30,31
simple queue? [NLJIET]
Pg
Explain Dequeue and Priority queue in detail.
24 2 32,33, 4
[NLJIET]
34,35
25 Explain Row Major and Column Major with 2 Pg 7

NLJIET Page | 40
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

Example. [NLJIET] 5,6,7


Write and explain algorithms for PUSH and POP
operations on stack data structure. [NLJIET] Pg
26 2 7
Define stack. Write algorithms for PUSH, POP 12,13,14
and PEEP operations of stack. [NLJIET]
Write a recursive function to compute factorial of
Extra
27 a number. Show usage of STACK in recursion for 2 7
Programs
this function. [NLJIET]
Pg
What is stack? Explain operations on stack in
28 2 11,12, 7
detail. [NLJIET]
13,14
Write an algorithm for the following stack Pg
29 operations. 1) PUSH 2) POP 3) DISPLAY 2 11,12, 7
[NLJIET] 13,14
Evaluate the following postfix expression in
tabular form:
(i) 5 * 6 2 / + [NLJIET]
(ii) 8 2 / 6 7 * + [NLJIET]
Pg
(iii) 2 5 3 - * 8 / 4 + [NLJIET]
30 2 21,25, 7
Evaluate the prefix expression in tabular forms:
26,10,11
(i) / - 8 2 3 4 [NLJIET]
(ii) / 7 * 1 + 4 – 6 3 [NLJIET]
Explain Tower Of Hanoi with example [NLJIET]
Explain Sparse matrix with example. [NLJIET]
Convert following Infix expression into Postfix
and Prefix expression.
(i) (A*B)+(C/D)-(D+E) [NLJIET]
31 Convert the following infix expressions to prefix 2 Pg 18 7
expressions and show the stack trace.
(i) A*(B+C)/D-E*F^G (ii) A+B*(C-D/E$F)*G
[NLJIET]
Convert following infix expression into postfix
expression using stack.
(i) (A-B)/C*D^(E/F)^(G+H) [NLJIET]
Convert following infix expressions to the postfix
expressions. Shows stack trace.
32 (i) ((A/(B-C+D))*(E-F)*G) [NLJIET] 2 Pg 18 7
Convert the following infix expressions to their
prefix.
(i) (A^B*C-D+E/F/(G+H)) [NLJIET]
Convert the following infix expression into a
postfix expression using stack.

NLJIET Page | 41
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

(i) (a+b)^((c*d)/(e-f)) [NLJIET]


Write an algorithm to convert infix expression
into postfix expression. [NLJIET]
Evaluation the following expression showing
every status of stack in tabular form.
(i) 3 5 * 6 2 / + [NLJIET]
Evaluate the following postfix expression using a
stack. Show the stack contents.
(i) 53+62/*35*+ [NLJIET]
33 2 Pg 21 7
Write an algorithm to evaluate postfix expression.
Explain working of the algorithm using
appropriate example. [NLJIET]
Evaluate the following postfix expression and
show the stack trace.
6 5 1 – 4 * 2 3 ^ / + [NLJIET]
Explain the concept of Reverse Polish Notation
(RPN) and describe the process for evaluating an
Pg
34 RPN expression using a stack. Provide a detailed 2 7
16,17,21
example of evaluating the following RPN
expression: 5 1 2 + 4 * + 3 - [NLJIET]
Write a ‘C’ program to reverse a string using Extra
35 2 7
stack. [NLJIET] Programs
What is queue? Explain operations on queue in Pg
36 2 7
detail. [NLJIET] 26,27,28
What is problem with simple queue? Explain its Pg
37 2 7
solution with example and algorithms. [NLJIET] 26,27,28
Write an algorithm to perform insert and delete Pg
38 2 7
operations on simple queue. [NLJIET] 27,28
Write algorithms to insert, and delete elements in Pg
39 2 7
queue. [NLJIET] 27,28
Define queue. Write algorithms for INSERT,
DELETE and DISPLAY operations of queue.
[NLJIET]
Write algorithm to (i) insert, and (ii) delete Pg
40 2 7
elements in circular queue. [NLJIET] 26,27,28
Write an algorithm for the following queue
operations. 1) INSERT 2) DELETE 3) DISPLAY
[NLJIET]
Write a C program to implement simple queue Lab
41 2 7
and check for boundary conditions. [NLJIET] Manual
Discuss and write a program to implement queue Lab
42 2 7
functions using arrays. [NLJIET] Manual

NLJIET Page | 42
New L.J Institute of Engineering and Technology
Semester: III Subject: Data Structures (BE03000081)
Unit 2: Linear Data Structure

What is a circular queue? How do you check the


Pg
43 queue full condition? Write an algorithm to count 2 7
29,30
the nodes in a circular queue. [NLJIET]
Write a program to implement Circular queue Pg 29,
44 and show how it differ from normal queue? 2 Lab 7
[NLJIET] Manual
Write an algorithm for INSERT, DELETE and
Pg
DISPLAY function of Circular Queue. [NLJIET]
29,30,31,
45 Write a C program for the following operations on 2 7
Lab
a circular queue.
Manual
1. Insert 2. Delete 3. Display [NLJIET]
Write a C program to implement circular queue Lab
46 2 7
with insertion and deletion operations. [NLJIET] Manual
What is priority queue? Discuss its applications Pg
47 2 7
and implementation details. [NLJIET] 32,33

NLJIET Page | 43

You might also like