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

DS_Lab_manual R23

The document is a lab manual for the Data Structures Laboratory course at Easwari Engineering College for the academic year 2024-2025. It outlines the course objectives, program outcomes, and a list of experiments that students will perform, including implementations of various data structures and algorithms using the C programming language. Additionally, it emphasizes the importance of quality education and the holistic development of students in the field of Information Technology.

Uploaded by

yogidhayogidha
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)
12 views

DS_Lab_manual R23

The document is a lab manual for the Data Structures Laboratory course at Easwari Engineering College for the academic year 2024-2025. It outlines the course objectives, program outcomes, and a list of experiments that students will perform, including implementations of various data structures and algorithms using the C programming language. Additionally, it emphasizes the importance of quality education and the holistic development of students in the field of Information Technology.

Uploaded by

yogidhayogidha
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/ 67

EASWARI ENGINEERING COLLEGE

(Autonomous)
RAMAPURAM, CHENNAI-89

DEPARTMENT OF INFORMATION TECHNOLOGY

LAB MANUAL

REGULATIONS R23

231ITC311L- DATA STRUCTURES LABORATORY

ACADEMIC YEAR:2024-2025

B. TECH IT II YEAR/ III SEMESTER

Prepared By :
M.Sowmiya
P.Deepika
T.Saraswathi Approved By

HOD/IT
Vision
To impart Quality Education towards the holistic development of students and be a

strategic partner in the Industrial Advancement arena and emerge as a ‘Center of

Excellence for Higher Studies’ in the specialization of Information Technology.

Mission
To offer doctoral programmes in the field of Information Technology to enhance
M1
research activities.

To awaken the young minds and lay solid Engineering foundation among the
M2 graduates through the design of experiments, analysis and interpretation of data.

To produce graduates with ethical principles and commit to professional ethics to


M3
cater to the norms of engineering practice.
To create graduates to work individually and as a member of a team to function
M4 effectively in multi-disciplinary areas for solving complex engineering problems.

To use modern Information Technology tools and appropriate teaching techniques


M5 for predicting and modeling the real world problems.

To provide contextual knowledge among graduates to assess societal, health,


M6 safety, legal and cultural issues through innovative professional engineering
practice.

To prepare and build the ability to recognise the need for independent and
M7 lifelong learning in the context of technological changes in the field
of Information Technology.
`

Program Specific Outcomes (PSO)


Create, select and apply appropriate techniques, resources, modern
engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.

Manage complex IT projects with consideration of the human, financial,


ethical and environmental factors and an understanding of risk management
processes and operational and policy implications.

Program Educational Objectives (PEOs)

Graduates will be proficient in utilizing the fundamental knowledge of basic


sciences, mathematics and Information Technology for the applications
relevant to various streams of Engineering and Technology.
Graduates will possess core competencies necessary for applying knowledge
of computers and telecommunications equipment to store, retrieve, transmit,
manipulate and analyze data in the context of business enterprise.
Graduates will be capable of thinking logically, pursue lifelong learning and
will have the capacity to understand technical issues related to computing
systems and to design optimal solutions.
Graduates will be able to develop hardware and software systems by
understanding the importance of social, business and environmental needs in
the human context.
Graduates will gain employment in organizations and establish themselves as
professionals by applying their technical skills to solve real world problems
and meet the diversified needs of industry, academia and research.
Program Outcomes (PO)
PO1 Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex
engineering problems.
PO2 Problem analysis: Identify, formulate, research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
PO3 Design/development of solutions: Design solutions for complex engineering problems
and design system components or processes that meet the specified needs with
appropriate consideration for the public health and safety, and the cultural, societal,
and environmental considerations.
PO4 Conduct investigations of complex problems: Use research-based knowledge and
research methods including design of experiments, analysis and interpretation of data,
and synthesis of the information to provide valid conclusions.
PO5 Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
PO6 The Engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
PO7 Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of,
and need for sustainable development.
PO8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
PO9 Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
PO10 Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend
and write effective reports and design documentation, make effective presentations,
and give and receive clear instructions.
PO11 Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a
member and leader in a team, to manage projects and in multidisciplinary
environments.
PO12 Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change
231ITC311L DATA STRUCTURES LABORATORY

LT PRC 0 04 02

COURSE OBJECTIVES

1. To understand and implement Linear data structures using C


2. To implement Non Linear data structures using C
3. To Implement of Graph and Traversal algorithms
4. To implement Searching and Sorting algorithms
5. To implement Hashing techniques

LIST OF EXPERIMENTS

1. Array implementation of List ADT


2. Array implementation of Stacks
3. Array implementation of Queues
4. Linked list implementation of List ADT
5. Linked list implementation of Stacks
6. Linked list implementation of Queues
7. Application of Stacks and Queues
8. Implementation of Binary Search Trees and Traversal
9. Implementation of AVL Trees
10. Implementation of Heaps using Priority Queues
11. Implementation of Graph and Traversal algorithms
12. Implementation of Sorting Algorithms : Bubble sort & Quick sort
13. Implementation of Linear search and Binary search
14. Implementation of Hashing - any one collision resolution techniques

TOTAL:60 PERIODS
Course Name: 231ITC311L- Data Structures Laboratory Year / Sem: 2023-2024/ III

Students will be able to :

C207.1 Write functions to implement linear data structure operations using C .

C207.2 Solve problems using non-linear data structures.

C207.3 Implement Graph and Traversal algorithms.

C207.4 Develop searching and sorting algorithms.

C207.5 Develop programs using Hashing techniques.


TABLE OF CONTENTS

Ex.No. Date Title of the Experiment Marks Signature

1 Array implementation of List ADT

2 Array implementation of Stacks

3 Array implementation of Queues

4 Linked list implementation of List ADT

5 Linked list implementation of Stacks

6 Linked list implementation of Queues

7.a Application of Stacks

7.b Application of Queues

8 Implementation of Binary Search Trees and Traversal

9 Implementation of AVL Trees

10 Implementation of Heaps using Priority Queues

11 Implementation of Graph and Traversal algorithms

12.a Implementation of Sorting Algorithms : Bubble sort

12.b Implementation of Sorting Algorithms : Quick sort

13.a Implementation of Linear search

13.b Implementation of Binary search

14 Implementation of Hashing - any one collision


resolution techniques

CONTENT BEYOND SYLLABUS

15 Implementation of Radix Sort


‘C’PROGRAMMING

C is a powerful, portable and elegantly structured programming language.It combines features


of a high-level language with the elements of an assembler and therefore,suitable for writing both
system software and application packages.It is the most widely used general- purpose language today.
C has been used for implementing systems such as operating systems, compilers, linkers, word
processors and utility packages.It is a robust language whose rich set of built-in functions and
operators can be used to write any complex program.Programs written in C are fast and efficient.

TurboC IDE

Turbo C IDE facilitates editing, debugging and execution of applications written in C.C
programs are saved with .c extension.Some of the short cut keys are:

Ctrl+F1 Help
F2 Save
F3 Open
Copy Ctrl+Ins
Cut Shift+Del
Paste Shift+Ins
Clear Ctrl+Del
Alt+F9 Compile
Ctrl+F9 Execute
Alt+F5 UserScreen
F7 TraceInto
Alt+F3 Close
Alt+X Quit
Ex NO: 1 ARRAY IMPLEMENTATION OF LIST ADT
DATE :

Aim
To write a ‘C’ program to implement List ADT using arrays.
Algorithm
Step 1: Start.
Step 2: Declare the necessary functions for implementation.
Step 3: Get the input from the user and store it an array.
Step 4: In Insertion, half of the elements to be shifted upwards and in deletion, half of the elements
to
be shifted downwards.
Step 5: Display the output using an array.
Step 6: Stop the program execution.
Result

Thus, the ‘C’ program to implement the list ADT using arrays has been executed and the output is
verified successfully.
Ex NO: 2 ARRAY IMPLEMENTATION OF STACK
DATE :

Aim

To write a ‘C’ program to implement stack using arrays

Algorithm

Step 1: Start.

Step 2: Declare the necessary functions for implementation.

Step 3: Get the input from the user and store it an array.

Step 4: In Insertion, half of the elements to be shifted upwards and in deletion , half of the
elements to
be shifted downwards.
Step 5: Display the output using an array.
Step 6: Stop
Result

Thus the ‘C’ program to implement stack using arrays is executed and the output is verified
successfully.
Ex NO: 3
ARRAY IMPLEMENTATION OF QUEUE
DATE :

Aim

To write a ‘C’ program to implement queue using arrays.

Algorithm

Step1:Define a array which stores queue elements.


Step2:The operations on the queue are
a)INSERT data into the queue
b) DELETE data out of queue
step3:INSERT DATA INTO queue
3a.Enter the data to be inserted into queue.
3b.If TOP is NULL then the input data is the first node in queue.
the link of the node is NULL.TOP points to that node.
3c.If TOP is NOT NULL thenthe link of TOP points to the new node.TOP points to that
node.
Step4:DELETE DATA FROM queue
4a.If TOP is NULL then the queue is empty
4b.If TOP is NOT NULL then the link of TOP is the current TOP.The pervious TOP is
popped
from queue.
Step 5: The queue represented by linked list is traversed to display its content.
Result
Thus, the ‘C ‘ program to implement the queue using array has been executed and the output
is verified successfully.
Ex NO: 4 LINKED LIST IMPLEMENTATION OF LIST
DATE :

Aim
To write a program to implement the linked list using pointers.

Algorithm

Step 1: Start
Step 1: Include all the header files which are used in the program.
Step 2: Declare all the user defined functions.
Step 3: Define a Node structure with two members data and next
Step 4: Define a Node pointer 'head' and set it to NULL.
Step 4: Implement the main method by displaying operations menu and make suitable function calls
in
the main method to perform user selected operation.
Step 6: Stop

Insertion

In a single linked list, the insertion operation can be performed in three ways. They are as follows...
● Inserting At Beginning of the list
● Inserting At End of the list
● Inserting At Specific location in the list
● Inserting At Beginning of the list

The following steps to insert a new node at beginning of the single linked list...

Step 1: Create a newNode with given value.


Step 2: Check whether list is Empty (head == NULL)
Step 3: If it is Empty then, set newNode→next = NULL and head = newNode.
Step 4: If it is Not Empty then, set newNode→next =head and head=newNode

Inserting At End of the list

The following steps to insert a new node at end of the single linked list...

Step 1: Create a newNode with given value and newNode → next as NULL.
Step 2: Check whether list is Empty (head == NULL).
Step 3: If it is Empty then, set head = newNode.
Step 4: If it is Not Empty then, define a node pointer temp and initialize with head.

Step 5: Keep moving the temp to its next node until it reaches to the last nodein the list (until
temp → next is equal to NULL).
Step 6: Set temp → next = newNode.

Inserting At Specific location in the list (After a Node)


The following steps to insert a new node after a node in the single linked list...

Step 1: Create a newNode with given value.


Step 2: Check whether list is Empty (head == NULL)
Step 3: If it is Empty then, set newNode → next = NULL and head = newNode.
Step 4: If it is Not Empty then, define a node pointer temp and initialize with head.
Step 5: Keep moving the temp to its next node until it reaches to the nodeafter which we want to
insert
the newNode (until temp1 → data isequal to location, here location is the node value after which
we want to insert the newNode).
Step 6: Every time check whether temp is reached to last node or not. If it isreached to last node then
display 'Given node is not found in the list!!! Insertion not possible!!!' and terminate the
function. Otherwise movethe temp to next node.
Step 7: Finally, Set 'newNode → next = temp → next' and 'temp → next =newNode'

Deletion
In a single linked list, the deletion operation can be performed in three ways. They are as follows...
● Deleting from Beginning of the list
● Deleting from End of the list
● Deleting a Specific Node
● Deleting from Beginning of the list

The following steps to delete a node from beginning of the single linked list...

Step 1: Check whether list is Empty (head == NULL)


Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the
function.
Step 3: If it is Not Empty then, define a Node pointer 'temp' and initialize with head.
Step 4: Check whether list is having only one node (temp → next == NULL)
Step 5: If it is TRUE then set head = NULL and delete temp (Setting Empty listconditions)
Step 6: If it is FALSE then set head = temp → next, and delete temp.

Deleting from End of the list


We can use the following steps to delete a node from end of the single linked list...

Step 1: Check whether list is Empty (head == NULL)


Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' andterminate the
function.
Step 3: If it is Not Empty then, define two Node pointers 'temp1' and 'temp2'and initialize 'temp1'
with
head.
Step 4: Check whether list has only one Node (temp1 → next == NULL)
Step 5: If it is TRUE. Then, set head = NULL and delete temp1. And terminatethe function.
(Setting Empty list condition)
Step 6: If it is FALSE. Then, set 'temp2 = temp1 ' and move temp1 to its next node. Repeat the same
until it reaches to the last node in the list(until temp1 → next == NULL)
Step 7: Finally, Set temp2 → next = NULL and delete temp1.

Deleting a Specific Node from the list

The following steps to delete a specific node from the single linked list...

Step 1: Check whether list is Empty (head == NULL)


Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the
function.
Step 3: If it is Not Empty then, define two Node pointers 'temp1' and 'temp2'and initialize 'temp1'
with
head.
Step 4: Keep moving the temp1 until it reaches to the exact node to be deleted or to the last node.
And
every time set 'temp2 = temp1' beforemoving the 'temp1' to its next node.
Step 5: If it is reached to the last node then display 'Given node not found in the list! Deletion not
possible!!!'. And terminate the function.
Step 6: If it is reached to the exact node which we want to delete, then checkwhether list is having
only
one node or not
Step 7: If list has only one node and that is the node to be deleted, then sethead = NULL and delete
temp1 (free(temp1)).
Step 8: If list contains multiple nodes, then check whether temp1 is the first node in the list
(temp1 == head).
Step 9: If temp1 is the first node then move the head to the next node (head =head → next) and
delete
temp1.
Step 10: If temp1 is not first node then check whether it is last node in the list(temp1 → next
==NULL).
Step 11: If temp1 is last node then set temp2 → next = NULL and deletetemp1 (free(temp1)).
Step 12: If temp1 is not first node and not last node then set temp2 → next = temp1 → next and
delete
temp1 (free(temp1)).

Displaying a Single Linked List

The following steps to display the elements of a single linked list...

Step 1: Check whether list is Empty (head == NULL)


Step 2: If it is Empty then, display 'List is Empty!!!' and terminate the function.
Step 3: If it is Not Empty then, define a Node pointer 'temp' and initialize with head.
Step 4: Keep displaying temp → data with an arrow (--->) until temp reaches to the last node
Step 5: Finally display temp → data with arrow pointing to NULL (temp → data---> NULL).
Result

Thus, the ‘C’ program to implement linked list using pointers has been executed and the output is
verified successfully.
Ex NO: 5

DATE : LINKED LIST IMPLEMENTATION OF STACK ADT

Aim:
To write a ‘C’ program to implement the linked list using stack ADT.

Algorithm

Step1: Define a array which stores stack elements..


Step 2: The operations on the stack are
a. PUSH data into the stack
b. POP data out of stack
Step 3: PUSH DATA INTO STACK
a.Enter the data to be inserted into stack.
b.If TOP is NULL then the input data is the first node in stack.The link of the node is
NULL.TOP points to that node.
c.If TOP is NOT NULL then the link of TOP points to the new node. TOP points to that
node.
step 4: POP DATA FROM STACK
a. If TOP is NULL then the stack is empty
b. If TOP is NOT NULL then the link of TOP is the current TOP.The pervious TOP is popped
from stack.
Step 5: The stack represented by linked list is traversed to display its content
.
Result

Thus the C program to implement the linked list using stack ADT has been executed and the
output is verified successfully.
Ex NO: 6 LINKED LIST IMPLEMENTATION OF QUEUE ADT
DATE :

Aim
To write a ‘C ‘program to implement linked list using Queue ADT.

Algorithm
Step1: Define a C-struct for each node in the queue. Each node in the queuecontains data and link to
the next node. Front and rear pointer points to first and last node inserted in the queue.
Step 2: The operations on the queue are
a. INSERT data into the queue
b. DELETE data out of queue
Step 3: INSERT DATA INTO queue
a.Enter the data to be inserted into queue.
b.If TOP is NULL then the input data is the first node in queue.The link of the node is NULL.
TOP points to that node.
c.If TOP is NOT NULL then the link of TOP points to the new node.TOP points to that node.
Step 4: DELETE DATA FROM queue
a. If TOP is NULL then the queue is empty
b. If TOP is NOT NULL then the link of TOP is the current TOP.pervious TOP is popped
from
queue.
Step 5: The queue represented by linked list is traversed to display its content.
Result

Thus the ‘C’program to implement the Queue using linked list has been executed and the output is
verified successfully.
Ex NO: 7.a

APPLICATION OF STACK-CONVERSION FROM


DATE : INFIX TO POSTFIX EXPRESSION

Aim
To write a C program to convert Infix to Postfix Expression.

Algorithm
1. Start the program
2. Using the strlen function determine the length of the string
3. Declare three arrays; the decremented value of one array is assigned to the incremented value.
This process is repeated until the parenthesis matches.
4. Until t==0 assign the values to sack1
5. Check if (top2==-1) if the condition is satisfied then assign stack2 [++top2]=str[i];
6. Print the result.
7. Stop the program
Result

Thus the ‘C’ program to convert Infix to Postfix Expression has been executed and the output
is verified successfully.
Ex NO: 7.b
APPLICATIONS OF QUEUE
DATE :
FCFS SCHEDULING ALGORITHM

Aim

To write a C program to implement the FCFS scheduling algorithm

Algorithm

Step1:Start the process

Step 2: Declare the array size

Step 3: Get the number of processes to be inserted

Step 4: Get the value

Step 5: Start with the first process from it’s initial position let other process to be in queue

Step 6: Calculate the total number of burst time

Step 7: Display the values

Step 8: Stop the process


Result

Thus the ‘C’ program to implement theFCFS scheduling algorithm has been executed and the output
is verified successfully.
Ex NO: 8

DATE : IMPLEMENTATION OF BINARY SEARCH TREES


AND TRAVERSALS

Aim

To write a ‘C’ program to implement Binary Search Tree .

Algorithm

Step 1: Start
Step 2: Create a Binary Search Tree for N elements.
Step 3: Traverse the tree in inorder.
Step 4: Traverse the tree in preorder
Step 6: Traverse the tree in postorder.
Step 7: Search the given key element in the BST.
Step 8: Delete an element from BST.
Step 9: Stop
Result

Thus, the ‘C’ program to implement Binary search Tree has been executed and the output is verified
successfully.
Ex NO: 9

DATE : IMPLEMENTATION OF AVL TREES

Aim

To write a ‘C’ program to implement AVL Trees

Algorithm

Step 1: Perform the normal BST insertion.


Step 2:The current node must be one of the ancestors of the newly inserted node. Update the height of
the current node.
Step 3:Get the balance factor (left subtree height – right subtree height) of the current node.
Step 4:If balance factor is greater than 1, then the current node is unbalanced and we are either in Left
Left case or left Right case. To check whether it is left left case or not, compare the newly
inserted key with the key in left subtree root.
Step 5:If balance factor is less than -1, then the current node is unbalanced and we are either in Right
Right case or Right-Left case. To check whether it is Right Right case or not, compare the newly
inserted key with the key in right subtree root.
Result

Thus the ‘C’ program to implement the AVL Tree has been executed and the output is verified
successfully.
Ex NO: 10 IMPLEMENTATION OF HEAPS USING
DATE : PRIORITY QUEUES

Aim

To write a ‘C’ program to implement Priority Queues using heap.

Algorithm

Step 1: Start
Step 2: Initialize all necessary variables and functions.
Step 3: Read the choices.
Step 4: For insertion, read the element to be inserted.
Step 5: If root is NULL, assign the given element as root.
Step 6: If the element is equal to the root, print “Duplicate value”.
Step 7: Else if element value is less than the root value, insert element at the left of the root.
Step 8: Else insert right side of the root.For deletion, get the priority for maximum or minimum.
Step 9: If maximum, it deletes the root and rearranges the tree.
Step 10: If minimum, it deletes the leaf.
Step 11:End of the program
Result

Thus, the ‘C’ program to implement Heaps using priority Queues been executed and the output is
verified successfully.
Ex NO: 11 IMPLEMENTATION OF GRAPH AND
DATE : TRAVERSAL ALGORITHMS

Aim

To write a ‘C’ program to implement Depth First Search (DFS) using Adjacency Matrix
representation of graph.

Algorithm

The DFS algorithm works as follows:

Step 1: Start by putting any one of the graph's vertices on top of a stack.

Step 2: Take the top item of the stack and add it to the visited list.

Step 3: Create a list of that vertex's adjacent nodes. Add the ones, which are not in the visited list to
the

top of stack.

Step 4: Keep repeating steps 2 and 3 until the stack is empty.


Result

Thus, the ‘C’program to implement Depth First Search (DFS) has been executed and the output is
verified successfully.
Ex NO: 12.a
IMPLEMENTATION OF BUBBLE SORT
DATE :

Aim

To write a ‘C’ program to implement bubble sort technique.

Algorithm

Step 1: Initialize the variables i,j,n, and temp.

Step 2: Get the number of elements.

Step 3: Get the numbers to be sorted.

Step 4; Assign a[i] to temp

Step 5: Assign a[i+1] to a[i]

Step 6: Assign Temp to a[i+1]

Step 7: The data is sorted


Result

Thus the ‘C’ program to implement bubble sort has been executed and the output is verified
successfully.
Ex NO: 12.b
IMPLEMENTATION OF QUICK SORT
DATE :

Aim

To write a ‘C’ program to implement Quick sort.

Algorithm

Step 1: Choose the highest index value has pivot


Step 2: Take two variables to point left and right of the list excluding pivot
Step 3: left points to the low index
Step 4: right points to the high
Step 5: while value at left is less than pivot move right
Step 6: while value at right is greater than pivot move left
Step 7: If both step 5 and step 6 does not match swap left and right
Step 8: If left ≥ right, the point where they met is new pivot
Result

Thus the ‘C’ program to implement Quick sort has been executed and the output is verified
successfully.
Ex NO: 13.a
IMPLEMENTATION OF LINEAR SEARCH
DATE :

Aim

To write a ‘C’ program to implement Linear search.

Algorithm

Step 1: Initialize the integer variables

Step 2: Get the number of elements and its values

Step 3: Start from the leftmost element of arr[] and one by one compare x with each element of arr[]

Step 4: If x matches with an element, return the index.

Step 5: If x doesn’t match with any of elements, return -1.

Step 6: Stop the program


Result

Thus the ‘C’ program to implement the Linear search has been executed and the output is
verified successfully.
Ex NO: 13.b
IMPLEMENTATION OF BINARY SEARCH
DATE :

Aim

To write a ‘C’ program to implement binary search.

Algorithm

Step 1: Initialize the integer variables

Step 2: Get the values from the list

Step 3: Sorted List of numbers is got as input.

Step 4: Get the target number from the user.

Step 5: Initialize first value as zero and last as n-1;

Step 6: The mid value is found.

Step 7: If the target is greater than mid then first is mid + 1 if not last is mid -1

Step 8: First is last +1

Step 9: The target is found, if its equal to a(mid) otherwise target is not found.
Result

Thus the ‘C’ program to implement the binary search has been executed and the output is
verified successfully.
Ex NO: 14
HASHING – ANY TWO COLLISION TECHNIQUES
DATE :

Aim

To write a C program toimplement Hashing using Linear and Quadratic Probing.

Algorithm

Step 1: Create a structure, data (hash table item) with key and value as data.
Step 2: Now create an array of structure, data of some certain size. But, the size ofarraymust be
immediately updated to a prime number just greater than initial array
Step 3: A menu is displayed on the screen.
Step 4: User must choose one option from four choices given in the menu
Step 5: Perform all the operations
Step 6: Stop the program
Result

Thus the ‘C’ program to implement Hashing using Linear and Quadratic Probing has been executed and
the output is verified successfully.
Ex NO: 15 CONTENT BEYOND SYLLABUS
DATE : APPLICATIONS OF GRAPHS – DIJIKSTRA’S
ALGORITHM

Aim

To write a ‘C’ program to implement Dijikstra’s Algorithms.

Algorithm

Step 1 : Begin

Step 2: Create cost matrix C[ ][ ] from adjacency matrix adj[ ][ ]. C[i][j] is the cost of going from
vertex
i to vertex j. If there is no edge between vertices i and j then C[i][j] is infinity.

Step 3: Array visited[ ] is initialized to zero.


for(i=0;i<n;i++)
visited[i]=0;

Step 4: If the vertex 0 is the source vertex then visited[0] is marked as 1.

Step 5: Create the distance matrix, by storing the cost of vertices from vertex no. 0 to n-1 from the
source vertex 0.
for(i=1;i<n;i++)
distance[i]=cost[0][i];
Initially, distance of source vertex is taken as 0. i.e. distance[0]=0;

Step 6: for(i=1;i<n;i++)
– Choose a vertex w, such that distance[w] is minimum and visited[w] is 0. Mark visited[w]
as 1.
Recalculate the shortest distance of remaining vertices from the source.
– Only, the vertices not marked as 1 in array visited[ ] should be considered for recalculation
of
distance. i.e. for each vertex v
if(visited[v]==0)
distance[v]=min(distance[v],
distance[w]+cost[w][v])

Step 7: Return
Result
Thus, the ‘C’program to implement Dijikstra’s Algorithm has been executed and the output is
verified successfully.
Ex NO: 16 CONTENT BEYOND SYLLABUS
DATE : IMPLEMENTATION OF RADIX SORT

Aim

To write a ‘C’ program to implement Radix sort.

Algorithm

Step 1:Start the program

Step 2: In 1st pass,we sort the array on basis of least significant digit (1s place) using counting sort.

Step 3: In 2nd pass,we sort the array on basis of next digit (10s place) using counting sort.

Step 4: In 3rd pass,we sort the array on basis of most significant digit (100s place) using counting
sort.

Step 5: Stop the Program


Result
Thus the ‘C’ program to implement the Radix sort using array has been executed and the output is
verified successfully.

You might also like