0% found this document useful (0 votes)
7 views11 pages

Experiments Mannual

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)
7 views11 pages

Experiments Mannual

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/ 11

Experiment 1: Input and Print Using Arrays

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:

1. Declare a character array to hold the input.


2. Prompt the user for input.
3. Use a function to read the input and store it in the array.
4. Print the contents of the array.

Conclusion:

This experiment reinforces the concept of arrays as a fundamental data structure in


C, enabling the storage and retrieval of user input effectively.

Source Code:

Experiment 2: Implement Stack Using Arrays


Aim:

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:

Experiment 3: Implement Linear Queue Using Arrays

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:

Experiment 4: Implement Circular Queue Using Arrays

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:

The program implements enqueue and dequeue operations in a circular manner,


checking for overflow and underflow. The front and rear indices wrap around the
array, demonstrating the circular nature and preventing wastage of space in the
queue.

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:

Experiment 5: Implement Linear Search

Aim:

To implement and understand the linear search algorithm.

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:

This experiment illustrates the simplicity of linear search, its ease of


implementation, and its use case in scenarios where the dataset is small or
unsorted.

Source Code:

Experiment 6: Implement Binary Search

Aim:

To implement the binary search algorithm and understand its efficiency.

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:

This experiment highlights the efficiency of binary search compared to linear


search, demonstrating the importance of data structure organization for
performance.

Source Code:

Experiment 7: Implement Insertion Sort

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:

This experiment provides insights into sorting algorithms, illustrating how


insertion sort functions and its applicability in small datasets or partially sorted
arrays.

Source Code:

Experiment 8: Implement Selection Sort

Aim:

To implement the selection sort algorithm and understand its operation.

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:

1. Iterate through the entire array.


2. For each position, find the minimum element from the unsorted portion.
3. Swap the minimum element with the first element of the unsorted portion.
4. Repeat until the entire array is sorted.

Conclusion:

This experiment reinforces understanding of sorting algorithms and demonstrates


the simplicity of selection sort, as well as its inefficiencies compared to more
advanced algorithms.

Source Code:

Experiment 9: Implement Radix Sort

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:

1. Determine the maximum number to find the number of digits.


2. For each digit (starting from least significant):
3. Use a stable sorting algorithm (like counting sort) to sort the array based on
the current digit.
4. Repeat until all digits have been processed.

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:

Experiment 10: Implement Singly Linked List

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:

You might also like