Experiments Mannual
Experiments Mannual
Aim:
To understand how to take input from the user and print it using arrays in C.
Abstract:
This experiment demonstrates the process of receiving user input and storing it in
an array. The program then outputs the stored data, illustrating basic array
operations and user interaction.
Description:
In this experiment, the user is prompted to enter a string. The input is stored in a
character array, which allows for easy manipulation and retrieval of the data. The
program showcases fundamental concepts such as array declaration, input handling
using functions like fgets(), Scanf() and output using printf().
Algorithm:
Conclusion:
Source Code:
To implement a stack data structure using arrays and understand its fundamental
operations.
Abstract:
The stack is a linear data structure that follows the Last In First Out (LIFO)
principle. This experiment explores stack operations—push and pop—using an
array to manage the data.
Description:
A stack is created using an array, and operations such as pushing an element onto
the stack and popping an element off the stack are implemented. The program
checks for overflow and underflow conditions to ensure safe stack operations,
demonstrating the stack's behavior and limitations.
Algorithm:
1. Define a structure for the stack with an array and a top index.
2. Initialize the stack by setting the top index to -1.
3. Define a function for pushing an element:
4. Check if the stack is full.
5. If not, increment the top index and add the element.
6. Define a function for popping an element:
7. Check if the stack is empty.
8. If not, return the element at the top and decrement the top index.
Conclusion:
Implementing a stack using arrays illustrates the LIFO principle and provides
insight into managing data with constraints, essential for understanding more
complex data structures.
Source Code:
Aim:
To implement a linear queue using arrays and explore its basic operations.
Abstract:
A queue is a linear data structure that follows the First In First Out (FIFO)
principle. This experiment focuses on implementing queue operations using an
array.
Description:
The program allows the user to enqueue and dequeue elements from a linear
queue. It checks for conditions like queue overflow and underflow, ensuring that
operations respect the FIFO nature. The structure keeps track of the front and rear
of the queue to facilitate these operations.
Algorithm:
1. Define a structure for the queue with an array, front, and rear indices.
2. Initialize the queue by setting front and rear to -1.
3. Define a function for enqueue:
4. Check if the queue is full.
5. If not, update the rear index and add the element.
6. Define a function for dequeue:
7. Check if the queue is empty.
8. If not, return the element at the front and update the front index.
Conclusion:
This experiment provides a practical understanding of queues and their operations,
reinforcing the concepts of FIFO and memory management through arrays.
Source Code:
Aim:
To create a circular queue using arrays and understand its advantages over a linear
queue.
Abstract:
A circular queue enhances the linear queue by allowing the last position to connect
back to the first, thus efficiently utilizing storage. This experiment focuses on
implementing a circular queue and its operations.
Description:
Algorithm:
1. Define a structure for the circular queue with an array, front, and rear
indices.
2. Initialize the queue by setting front and rear to -1.
3. Define a function for enqueue:
4. Check if the queue is full.
5. If not, update the rear index (circularly) and add the element.
6. Define a function for dequeue:
7. Check if the queue is empty.
8. If not, return the element at the front and update the front index (circularly).
Conclusion:
Implementing a circular queue using arrays showcases efficient use of memory and
enhances understanding of queue data structures, providing practical experience
with circular indexing.
Source Code:
Aim:
Abstract:
Linear search is a simple searching algorithm that checks each element in a list
until the desired element is found. This experiment focuses on its implementation
and analysis.
Description:
The program searches for a specified element in an array by iterating through each
element sequentially. It returns the index of the element if found or indicates that
the element is not present.
Algorithm:
1. Iterate through each element in the array.
2. For each element, check if it matches the search key.
3. If a match is found, return the index.
4. If the end of the array is reached without finding a match, return -1.
Conclusion:
Source Code:
Aim:
Abstract:
Binary search is an efficient searching algorithm that works on sorted arrays. This
experiment explores its implementation and compares it with linear search.
Description:
The program applies binary search by repeatedly dividing the search interval in
half. It checks if the middle element is the target, and based on comparison, it
narrows the search to either the left or right half of the array.
Algorithm:
1. Set two pointers, left (0) and right (size - 1).
2. While left is less than or equal to right:
3. Calculate the middle index.
4. If the middle element is equal to the search key, return the index.
5. If the middle element is less than the search key, update left to mid + 1.
6. If the middle element is greater than the search key, update right to mid - 1.
7. If the element is not found, return -1.
Conclusion:
Source Code:
Aim:
To implement the insertion sort algorithm and analyze its sorting mechanism.
Abstract:
Insertion sort is a simple sorting algorithm that builds a sorted array one element at
a time. This experiment focuses on its implementation and characteristics.
Description:
The program sorts an array by iterating through each element, inserting it into the
correct position within the already sorted part of the array. It demonstrates the
mechanics of shifting elements to make space for the new element.
Algorithm:
1. Iterate through each element of the array starting from the second element.
2. Store the current element as the key.
3. Compare the key with elements in the sorted portion:
4. Shift elements larger than the key to the right.
5. Insert the key into its correct position.
6. Repeat until the entire array is sorted.
Conclusion:
Source Code:
Aim:
Abstract:
Selection sort is a straightforward sorting algorithm that divides the array into
sorted and unsorted regions. This experiment explores its implementation and
performance.
Description:
The program repeatedly selects the smallest (or largest) element from the unsorted
region and moves it to the end of the sorted region. This process is repeated until
the entire array is sorted.
Algorithm:
Conclusion:
Source Code:
Aim:
To implement the radix sort algorithm and analyze its performance for sorting
integers.
Abstract:
Radix sort is a non-comparative integer sorting algorithm that sorts numbers digit
by digit. This experiment focuses on its implementation and efficiency.
Description:
The program sorts an array of integers by processing each digit from least
significant to most significant, using a stable sub-sorting algorithm (like counting
sort) to sort the elements based on each digit.
Algorithm:
Conclusion:
This experiment illustrates the efficiency of radix sort for specific types of data and
highlights the importance of choosing the right sorting algorithm based on data
characteristics.
Source Code:
Aim:
To implement a singly linked list and understand its structure and operations.
Abstract:
A singly linked list is a dynamic data structure that consists of nodes, where each
node contains data and a pointer to the next node. This experiment explores its
implementation and common operations.
Description:
The program defines a singly linked list, allowing operations such as insertion,
deletion, and traversal. It demonstrates how linked lists provide flexibility in
memory allocation and management compared to static data structures like arrays.
Algorithm:
1. Define a node structure containing data and a pointer to the next node.
2. Initialize the head pointer to NULL.
3. Define functions for:
4. Insertion (at the beginning, end, or specific position).
5. Deletion (of a specific node).
6. Traversal (to display the list).
7. Update the head pointer as necessary during insertions and deletions.
Conclusion:
This experiment reinforces the concept of linked lists, illustrating their advantages
in dynamic memory usage and their applications in various programming
scenarios.
Source Code: