0% found this document useful (0 votes)
7 views

Data Structure Lab Manual_CS_303

The document outlines a lab manual for the Data Structure course at Mahakal Institute of Technology, detailing various experiments related to matrix operations, linked lists, stacks, queues, sorting algorithms, and binary search. Each experiment includes a problem definition, objectives, algorithms, expected viva questions, and space for faculty signatures. The manual is structured to help students understand and implement fundamental data structure concepts.

Uploaded by

Ayush Rathore
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Data Structure Lab Manual_CS_303

The document outlines a lab manual for the Data Structure course at Mahakal Institute of Technology, detailing various experiments related to matrix operations, linked lists, stacks, queues, sorting algorithms, and binary search. Each experiment includes a problem definition, objectives, algorithms, expected viva questions, and space for faculty signatures. The manual is structured to help students understand and implement fundamental data structure concepts.

Uploaded by

Ayush Rathore
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

MAHAKAL INSTITUTE OF TECHNOLOGY, UJJAIN

Approved By: All India Council of Technical Education (New Delhi)

DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING

Name of Student: …………………..

Name of Lab : Data Structure

Subject Code : CS- 303

Branch : Computer Science and Engineering

Year/Sem : II/III

Affiliated to Rajiv Gandhi Prodyogiki Vishwavidyalaya, Bhopal (MP)


INDEX
S. No. Name of Experiment Date Sign Remark

1. Write a program to perform the following operation in Matrix:


1. Addition 2. Subtraction 3. Multiplication 4. Transpose

2. Write a program to insert an element in the beginning and end of singly


linked list.

3. Write a program to insert and delete a node at any position in doubly


linked list.

4. Write a program to insert an element at the beginning and end of


circular linked list.

5 Write a program to implement stack using array.

6 Write a program to implement queue using array.

7 Write a program to implement circular queue using array.

8 Write program for implement Insertion sort.

9 Write program for implement Selection sort.

10 Write a program to search an element in binary search.


EXPERIMENT NO. 1
Unit/Topic: 1/ Array
PROBLEM DEFINITION:
Write a program to perform the following operation in Matrix:
1. Addition 2. Subtraction 3. Multiplication 4. Transpose

OBJECTIVE:
To understand the concept of Array.

ALGORITHM:

Addition:
1. We first define three matrices A, B, C and read their respective row and column numbers in
variable r and c
2. Read matrices A and B.
3. First, start a loop for getting row elements of A and B
Secondly, inside it again start a loop for column of A and B
4. Then, we store their corresponding addition by C[i][j]=A[i][j] + B[i][j] into C[i][j]

Subtraction:
1. We first define three matrices A, B, C and read their respective row and column numbers in
variable r and c
2. Read matrices A and B.
3. First, start a loop for getting row elements of A and B
Secondly, inside it again start a loop for column of A and B
4. Then, we store their corresponding Subtraction by C[i][j]=A[i][j] - B[i][j] into C[i][j]

Multiplication:
1. We first define three matrices A, B, C and read their respective row and column numbers in
variable r and c
2. Read matrices A and B.
3. First, start a loop for getting row elements of A and B
Secondly, inside it again start a loop for column of A and B
4. Then, we store their corresponding Multiplication by C[k][i]=A[k][j] * B[j][i] into C[k][i]

Transpose:
1. C1 [i] [j] = C2 [j] [i]

INPUT SET:

OUTPUT SET:
EXPECTED VIVA QUESTIONS:
Q.1 what is array?
Q.2 explains different types of array?
Q.3 how to perform addition, subtraction, multiplication and division operation in 2-D array?

NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO. 2
Unit/Topic: 1/ Linked List

PROBLEM DEFINITION:
Write a program to insert an element in the beginning and end of singly linked list.

OBJECTIVE:
To understand the concept of linked list.

ALGORITHM:
At the Beginning:
1. Create a newNode with given value.
2. Check whether list is Empty (head == NULL)
3. If it is Empty then, set newNode→next = NULL and head = newNode.
4. If it is Not Empty then, set newNode→next = head and head= newNode.

At the End:
1. Create a newNode with given value and newNode → next as NULL.
2. Check whether list is Empty (head == NULL).
3. If it is Empty then, set head = newNode.
4. If it is Not Empty then, define a node pointer temp and initialize with head.
5. Keep moving the temp to its next node until it reaches to the last node in the list (until temp
→ next is equal to NULL).
6. Set temp → next = newNode.

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1 explain concept of linked list with its application?
Q.2 how to perform insertion and deletion operation in linear linked list?
Q.3 compares different types of linked list?

NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO. 3
Unit/Topic: 1/ Linked List
PROBLEM DEFINITION:
Write a program to insert and delete a node at any position in doubly linked list.
OBJECTIVE:
To understand insertion and deletion operation in doubly linked list.
ALGORITHM:
Insert an element at any position:
1. IF PTR = NULL
a. Write OVERFLOW
Go to Step 15
[END OF IF]
2. SET NEW_NODE = PTR
3. SET PTR = PTR -> NEXT
4. SET NEW_NODE -> DATA = VAL
5. SET TEMP = START
6. SET I = 0
7. REPEAT 8 to 10 until I<="" li="">
8. SET TEMP = TEMP -> NEXT
9. IF TEMP = NULL
10. WRITE "LESS THAN DESIRED NO. OF ELEMENTS"
a. GOTO STEP 15
[END OF IF]
[END OF LOOP]
11. SET NEW_NODE -> NEXT = TEMP -> NEXT
12. SET NEW_NODE -> PREV = TEMP
13. SET TEMP -> NEXT = NEW_NODE
14. SET TEMP -> NEXT -> PREV = NEW_NODE
15. EXIT

Delete an element at any position:


1. IF HEAD = NULL
a. Write UNDERFLOW
Go to Step 9
[END OF IF]
2. SET TEMP = HEAD
3. Repeat Step 4 while TEMP -> DATA != ITEM
4. SET TEMP = TEMP -> NEXT
a. [END OF LOOP]
5. SET PTR = TEMP -> NEXT
6. SET TEMP -> NEXT = PTR -> NEXT
7. SET PTR -> NEXT -> PREV = TEMP
8. FREE PTR
9. EXIT

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1 explain concept of doubly linked list?
Q.2 how to insert and delete a node at any position in doubly linked list?
Q.3 how many types of insertion and deletion operation in doubly linked list?

NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO. 4
Unit/Topic: 1/ Linked List
PROBLEM DEFINITION:
Write a program to insert an element at the beginning and end of circular linked list.

OBJECTIVE:
To understand the concept of circular linked list.

ALGORITHM:
At Beginning of list:
1. Create a newNode with given value.
2. Check whether list is Empty (head == NULL)
3. If it is Empty then, set head = newNode and newNode→next= head .
4. If it is Not Empty then, define a Node pointer 'temp' and initialize with 'head'
5. Keep moving the 'temp' to its next node until it reaches to the last node (until 'temp →
next == head').
6. Set 'newNode → next =head', 'head = newNode' and 'temp → next = head'.

At End of list:
1. Create a newNode with given value.
2. Check whether list is Empty (head == NULL).
3. If it is Empty then, set head = newNode and newNode → next = head.
4. If it is Not Empty then, define a node pointer temp and initialize with head.
5. Keep moving the temp to its next node until it reaches to the last node in the list (until temp
→ next == head).
6. Set temp → next = newNode and newNode → next = head.

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1 How to insert an element in circular linked list at the beginning?
Q.2 How to insert an element in circular linked list at the end?
Q.3 Operation in Circular linked list?

NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO. 5
Unit/Topic: 2/ Stack
PROBLEM DEFINITION:
Write a program to implement stack using array.

OBJECTIVE:
To understand concept of push and pop operation in stack.
ALGORITHM:
Push element
int push()
{
if(top==length-1) "stack overflow";
else
top+1;
stack[top]=data;
}

Pop element
int pop()
{
int y;
if(top==-1) "stack is underflow";
else
y=stack[top];
top-1;
}

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1What is Top of Stack?
Q.2 Explain Stack underflow and overflow condition?
Q.3 difference between stack and queue?

NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.6
Unit/Topic: 2/ Queue
PROBLEM DEFINITION:
Write a program to implement queue using array.

OBJECTIVE:
To understand Enqueue and De-queue in queue.

ALGORITHM:
Insert element
enqueue(data)

if queue is full
return overflow
endif

rear ← rear + 1
queue[rear] ← data
return true

Delete element
if queue is empty
return underflow
end if

data = queue[front]
front ← front + 1
return true

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1 explains the condition of overflow and underflow in queue?
Q.2 How to perform Enqueue and Dequeue operation in queue?
Q.3 explains difference types of queue?

NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.7
Unit/Topic: 2/ Circular Queue
PROBLEM DEFINITION:
Write a program to implement circular queue using array.

OBJECTIVE:
To understand working of circular queue.
ALGORITHM:
Insert Circular ( ):
1.If (FRONT == 1 and REAR == N) or (FRONT == REAR + 1) Then
2. Print: Overflow
3. Else
4. If (REAR == 0) Then [Check if QUEUE is empty] (a) Set FRONT = 1 (b) Set REAR = 1
5. Else If (REAR == N) Then [If REAR reaches end if QUEUE]
6. Set REAR = 1
7. Else
8. Set REAR = REAR + 1 [Increment REAR by 1] [End of Step 4 If]
9. Set QUEUE[REAR] = ITEM
10. Print: ITEM inserted [End of Step 1 If]
11. Exit
Delete Circular ( ):
1.If (FRONT == 0) Then [Check for Underflow]
2. Print: Underflow
3. Else
4. ITEM = QUEUE[FRONT]
5. If (FRONT == REAR) Then [If only element is left] (a) Set FRONT = 0 (b) Set REAR = 0
6. Else If (FRONT == N) Then [If FRONT reaches end if QUEUE]
7. Set FRONT = 1
8. Else
9. Set FRONT = FRONT + 1 [Increment FRONT by 1] [End of Step 5 If]
10. Print: ITEM deleted [End of Step 1 If]
11. Exit
INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1 How to insert an element in circular linked list?
Q.2 How to delete an element in circular linked list?
Q.3 Application of Circular Queue?

NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.8
Unit/Topic: 5/ Sorting
PROBLEM DEFINITION:
Write program for implement Insertion sort.

OBJECTIVE:
To implement Insertion Sort.

ALGORITHM:
1. insertionSort(array)
2. mark first element as sorted
3. for each unsorted element X
4. 'extract' the element X
5. for j <- lastSortedIndex down to 0
6. if current element j > X
7. move sorted element to the right by 1
8. break loop and insert X here
9. end insertionSort

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1 which of the following sorting algorithm is best suited if the elements are already sorted?
Q.2 Insertion sort is an example of an incremental algorithm?
Q.3 which of the following is good for sorting arrays having less than 100 elements?

NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.9
Unit/Topic: 5/ Sorting
PROBLEM DEFINITION:
Write program for implement Selection sort.

OBJECTIVE:
To implement Selection Sort.

ALGORITHM:
1. selectionSort(array, size)
2. repeat (size - 1) times
3. set the first unsorted element as the minimum
4. for each of the unsorted elements
5. if element < currentMinimum
6. set element as new minimum
7. swap minimum with first unsorted position
8. end selectionSort

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1 what is the worst case complexity of selection sort?
Q.2 what is the advantage of selection sort over other sorting techniques?
Q.3 what is the disadvantage of selection sort?

NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT NO.10
Unit/Topic: 3/ Tree
PROBLEM DEFINITION:
Write a program to search an element in binary search.

OBJECTIVE:
To implement Binary search.

ALGORITHM:
1. Compare x with the middle element.
2. If x matches with middle element, we return the mid index.
3. Else if x is greater than the mid element, then x can only lie in right half sub array after the
mid element. So we recur for right half.
4. Else (x is smaller) recur for the left half.

INPUT SET:

OUTPUT SET:

EXPECTED VIVA QUESTIONS:


Q.1 what is time complexity of Binary Search?
Q.2 Can Binary Search is used for linked lists?
Q.3 Can you implement a Binary search Algorithm without recursion?

NAME OF FACULTY:
SIGNATURE:
DATE:

You might also like