Data Structure Using C
Data Structure Using C
To ensure that the Diploma level Technical Education constantly matches the latest requirements of
technology industry and includes the all-round personal development of students including social
concerns and to become globally competitive, technology led organization.
MISSION
To provide high quality technical and managerial manpower, information and consultancy services
to the industry and community to enable the industry and community to face the changing
technological & environmental challenges.
QUALITY POLICY
We, at MSBTE are committed to offer the best-in-class academic services to the students and
institutes to enhance the delight of industry and society. This will be achieved through continual
improvement in management practices adopted in the process of curriculum design, development,
Implementation, evaluation and monitoring system along with adequate faculty development
programmes.
CORE VALUES
MSBTE believes in the followings:
Semester-III
(BD/CM/CO/CW/HA/IF/IH)
Maharashtra State
Board of Technical Education, Mumbai
(Autonomous) (ISO 9001:2015)
(ISO/IEC 27001:2013)
Maharashtra State Board of Technical Education,
(Autonomous) (ISO 9001:2015) (ISO/IEC 27001:2013)
4th Floor, Government Polytechnic Building, 49, Kherwadi,
Bandra (East), Mumbai- 400051.
(Printed on July, 2024)
MAHARASHTRA STATE BOARD OF
TECHNICAL EDUCATION
Certificate
Seal of
Institution
Data Structure Using C (313301)
Preface
The primary focus of any engineering laboratory/ field work in the technical education system is to develop
the much-needed industry relevant competencies and skills. With this in view, MSBTE embarked on this
innovative ‘K’ Scheme curricula for engineering diploma programmes with outcome-base education as the
focus and accordingly, relatively large amount of time is allotted for the practical work. This displays the
great importance of laboratory work making each teacher; instructor and student to realize that every minute
of the laboratory time need to be effectively utilized to develop these outcomes, rather than doing other
mundane activities. Therefore, for the successful implementation of this outcome-based curriculum, every
practical has been designed to serve as a ‘vehicle’ to develop this industry identified competency in every
student. The practical skills are difficult to develop through ‘chalk and duster’ activity in the classroom
situation. Accordingly, the ‘I’ scheme laboratory manual development team designed the practical’s to focus
on the outcomes, rather than the traditional age old practice of conducting practical’s to ‘verify the theory’
(which may become a byproduct along the way).
This laboratory manual is designed to help all stakeholders, especially the students, teachers and instructors
to develop in the student the pre-determined outcomes. It is expected from each student that at least a day
in advance, they have to thoroughly read through the concerned practical procedure that they will do the
next day and understand the minimum theoretical background associated with the practical. Every practical
in this manual begins by identifying the competency, industry relevant skills, course outcomes and practical
outcomes which serve as a key focal point for doing the practical. The students will then become aware
about the skills they will achieve through procedure shown there and necessary precautions to be taken,
which will help them to apply in solving real-world problems in their professional life.
This manual also provides guidelines to teachers and instructors to effectively facilitate student-centered lab
activities through each practical exercise by arranging and managing necessary resources in order that the
students follow the procedures and precautions systematically ensuring the achievement of outcomes in the
students.
This course provides essential knowledge to any graduate or undergraduate belonging to any discipline
involving computer science and software engineering. Data Structure, specifically demonstrates logical and
mathematical model of storing and organizing data in a particular way in a computer, required for designing
and implementing efficient algorithms. Through this course student will able to understand different kinds
of data structures like arrays, linked lists, stacks, queues etc. are suited to different kinds of applications.
Although all care has been taken to check for mistakes in this laboratory manual, yet it is impossible to
claim perfection especially as this is the first edition. Any such errors and suggestions for improvement can
be brought to our notice and are highly welcome.
Program Outcomes
Basic and Discipline specific knowledge: Apply knowledge of basic mathematics, science and
engineering fundamentals and engineering specialization to solve the engineering problems.
Problem analysis: Identify and analyze well-defined engineering problems using codified
standard methods.
Design/ development of solutions: Design solutions for well-defined technical problems and
assist with the design of systems components or processes to meet specified needs.
Engineering Tools, Experimentation and Testing: Apply modern engineering tools and
appropriate technique to conduct standard tests and measurements.
Life-long learning: Ability to analyse individual needs and engage in updating in the context of
technological changes.
The following industry relevant skills of the competency ‘Implement algorithm using relevant Data
Structures’ are expected to be developed in you by undertaking the practical’s of this laboratory manual.
Guidelines to Teachers
1. For incidental writing on the day of each practical session every student should maintain a dated
logbook for the whole semester, apart from this laboratory manual, which s/he has to submit for
assessment to the teacher in the next practical session.
2. Teachers should give opportunity to students for hands-on after the demonstration.
3. Assess the skill achievement of the students and COs of each unit.
5. List of few sample questions for reference. Teachers must design more such questions to ensure the
achievement of identified CO.
6. Teacher should ensure that the practical skill and competencies are developed in the students after
the completion of the practical exercise.
7. Teacher may provide additional knowledge and skills to the students even though it’s not covered
in the manual but are expected from the students by the industries.
8. Teacher may suggest the students to refer additional related literature of the Technical papers/
Reference books/ Seminar proceedings, etc.
9. Teacher shall assess the performance of students continuously as per norms prescribed by MSBTE.
10. During assessment teacher is expected to ask questions to the students to tap their Achievements
grading related knowledge and skills so that student can prepare while submitting record of the
practical focus should be given on development of enlisted skills rather than theoretical knowledge.
3. Listen carefully to the instructions given by the teacher about importance of relevant program
outcomes, relevant course outcomes, practical significance, competency and practical skills,
practical outcome and the theoretical background during the practical session.
4. Write the answers of the questions allotted by the teacher during practical session.
5. Student should develop the habit of group discussion related to the practical, so that exchange of
knowledge/skills could take place.
7. Student shall refer technical magazines, websites related to the scope of the course.
8. Student should develop habit to submit the practical, exercise continuously and progressively on the
scheduled dates and should get the assessment done.
9. Student should be well prepared while submitting the write up of the exercise.
10. Student should not hesitate to ask any difficulty faced during conduct of practical.
Content Page
List of Practical and Progressive Assessment Sheet
Sr. Title of the Practical Page Date Date of Assessment Dated Remarks
No No of submi marks (25) sign. of (if any)
. Perfo ssion teacher
rman
ce
1 *Write a ‘C’ program to 1
perform following Operations
on Array: Create, Insert,
Delete, Display.
2 Write a ‘C’ Program to Search 8
a particular data from the given
Array of numbers using:
Linear Search Method.
3 * Write a ‘C’ Program to 15
Search a particular data from
the given Array of Strings
using Linear Search Method.
4 * Write a ‘C’ program to 21
Search a particular data from
the given Array of numbers
using Binary Search Method.
5 Write a ‘C’ Program to Search 28
a particular data from the given
Array of Strings using Binary
Search Method.
6 * Write a ‘C’ Program to Sort 34
an Array of numbers using
Bubble Sort Method.
7 Write a ‘C’ Program to Sort an 43
Array of Strings using Bubble
Sort Method.
8 * Write a ‘C’ Program to Sort 50
an Array of numbers using
Selection Sort Method.
9 Write a ‘C’ Program to Sort an 57
Array of Strings using
Selection Sort Method.
10 * Write a ‘C’ Program to Sort 64
an Array of numbers using
Insertion Sort Method.
11 Write a ‘C’ Program to Sort an 71
Array of Strings using
Insertion Sort Method.
Sr. Title of the Practical Page Date Date of Assessment Dated Remarks
No No of submi marks (25) sign. of (if any)
. Perfo ssion teacher
rman
ce
12 * Write a 'C' Program to 78
Implement Singly Linked List
with Operations: (i) Insert at
beginning, (ii) Search, (iii)
Display
13 * Write a C Program to 85
Implement Singly Linked List
with Operations: (i) Insert at
end, (ii) Insert After, (iii)
Delete (iv) Display
14 Write a C Program to Create 94
Two Polynomials using a
Linked List.
15 * Write a 'C' Program to add 100
Two Polynomials using a
Linked List.
16 * Write a 'C' Program to 109
perform PUSH and POP
Operations on Stack using an
Array.
17 * Write a 'C' Program to 115
perform PUSH and POP
Operations on a Stack using a
Linked List.
18 * Write a 'C' program to 121
perform multiplication of two
numbers using recursion.
19 Write a 'C' program to print 127
given string in reverse using
recursion.
20 Write a 'C' program to create a 133
Singly Linked List and traverse
in reverse order using
recursion.
21 * Write a 'C' Program to 139
perform INSERT and
DELETE Operations on Linear
Queue using an Array.
22 * Write a 'C' Program to 146
perform INSERT and
DELETE operations on Linear
Queue using a Linked List.
23 * Write a 'C' Program to 152
perform INSERT and
Sr. Title of the Practical Page Date Date of Assessment Dated Remarks
No No of submi marks (25) sign. of (if any)
. Perfo ssion teacher
rman
ce
DELETE operations on
Circular Queue using an Array.
24 Write a 'C' Program to perform 160
INSERT and DELETE
operations on Circular Queue
using a Linked List.
25 Write a 'C' Program to Create a 166
Priority Queue using a Linked
List.
26 * Write a 'C' Program to 173
Implement BST (Binary
Search Tree) and Traverse in
In-Order.
27 Write a 'C' Program to 180
Traverse BST in Preorder, and
Post-Order.
Practical No.1: * Write a ‘C’ program to perform following Operations on Array: Create,
Insert, Delete, Display.
I Practical Significance
Writing a 'C' program to perform operations on an array helps in understanding fundamental data
structures, memory management, and algorithm development. It provides a foundation for more
complex programming tasks and real-world applications, reinforcing essential problem-solving
skills in computer science.
To create an array in C, you declare a variable of array type, specifying the data type of its
elements and the number of elements it can hold. For example:
In C, arrays are zero-indexed, meaning the first element is at index 0 and the last element is
at index (size - 1).
Inserting elements into an array involves assigning values to specific elements within the
array.
To insert an element at a specific index in the array, you can directly assign a value to that
index. However, this will overwrite any existing value at that index.
If you want to insert an element and shift the existing elements to accommodate the new one,
you would typically use a loop to move elements to make space for the new element.
Deleting elements from an array involves removing elements from specific positions within
the array.
To delete an element from an array, you typically shift the elements after the deleted element
one position to the left to fill the gap created by the deletion.
You may also need to adjust the size of the array to reflect the removal of an element, which
is not straightforward in C since arrays have fixed sizes once declared.
4. Display Array:
Displaying the contents of an array involves iterating over the elements of the array and
printing or displaying each element.
This can be done using a loop, such as a for loop, to iterate over the array and print each
element.
For example:
It's important to note that in C, arrays are fixed-size data structures, meaning their size cannot
be changed once they are declared. To implement dynamic resizing or other more complex
operations, you would typically need to use dynamic memory allocation techniques, such as
malloc() and free(), along with pointer arithmetic. Additionally, error handling and boundary
checks are crucial to ensure the correctness and robustness of array operations in C.
VII Algorithm
IX C Program Code
X Resources required
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of Dynamic memory allocation to store Stack data
4. Follow safety practices.
XIII Conclusion
XV Exercise
1. List limitations of array in C.
2. Explain how sizeOf operator works with arrays.
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………………………………………………
Practical No.2: * Write a ‘C’ Program to Search a particular data from the given
Array of numbers using: Linear Search Method.
I Practical Significance
In C, a program using linear search can efficiently find a specific data within an array of numbers
by sequentially checking each element until the target is found or the end of the array is reached.
This method is straightforward and suitable for small or unsorted arrays.
II Industry/ Employer Expected Outcome
Demonstrate proficiency in writing C program.This includes understanding how to implement the
algorithm correctly, handling edge cases, and writing clean, well-commented code. Additionally,
students should be able to analyze the time complexity of their solution and possibly optimize it
for better performance. Overall, industry seeks candidates who can effectively apply fundamental
programming concepts to solve real-world problems. By performing this experiment student
should-
1. Locate a specific data within an array of numbers, demonstrating the candidate's ability to
work with arrays, loops, and conditional statements
2. Write clean and well commented code
3. Use optimization technique for performance improvement
The value of K, i.e., 41, is not matched with the first element of the array. So, move to the next
element. And follow the same process until the respective element is found.
Now, the element to be searched is found. So algorithm will return the index of the element
matched.
VII Algorithm
IX C Program Code
X Resources required
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of Dynamic memory allocation to store Stack data
4. Follow safety practices.
XIII Conclusion
1. Modify the linear search program to find and print all occurrences of the target value in the
array.
2. Explore real-world applications where linear search is used, such as searching for elements in a
list of contacts or searching for files in a directory.
XV Exercise
1. Calculate time and space complexity of Linear Search.
2. Explain how Linear search can be modified for multiple occurrences.
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No.3: Write a ‘C’ Program to Search a particular data from the given
Array of Strings using Linear Search Method.
I Practical Significance
In C, a program using linear search can efficiently find a specific data within an array of
Strings by sequentially checking each element until the target is found or the end of the
array is reached. This method is straightforward and suitable for small or unsorted arrays.
VII Algorithm
IX C Program Code
X Resources required
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Follow safety practices.
XIII Conclusion
XV Exercise
1. Write applications of Linear Search Algorithm.
2. Modify the linear search function to perform a case-insensitive search.
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No-4: Write a ‘C’ program to Search a particular data from the given Array
of numbers using Binary Search Method.
I Practical Significance
Binary search is a highly efficient algorithm for finding a specific value in a sorted array. It
significantly reduces the search time complexity to O(log n) by repeatedly dividing the search
interval in half, making it particularly useful for large datasets.
II Industry/Employer Expected Outcome
The binary search algorithm's efficiency is crucial in various industries, particularly in database
management, information retrieval, and software development.
1. Enable rapid data lookup and retrieval
2. Enhance performance in applications like search engines, data analytics platforms, and
inventory management systems
3. Lead to faster query responses and improved user experiences.
III Course Level Learning Outcomes
Perform operations on Stack using Array and Linked List Implementations.
IV Laboratory Learning Outcome
Implement Binary search method on numbers.
V Relevant Affective Domain Outcome(s)
1. Follow safety practices.
2. Follow ethical practices.
Now, the element to search is found. So algorithm will return the index of the element matched.
VII Algorithm
IX C Program Code
X Resources required
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of Dynamic memory allocation to store Stack data
4. Follow safety practices.
XIII Conclusion
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No.5: Write a ‘C’ Program to Search a particular data from the given Array of
Strings using Binary Search Method
I Practical Significance
Binary search is a highly efficient algorithm for finding a specific value in a sorted array. It
significantly reduces the search time complexity to O(log n) by repeatedly dividing the search
interval in half, making it particularly useful for large datasets.
II Industry/Employer Expected outcome
The binary search algorithm's efficiency is crucial in various industries, particularly in database
management, information retrieval, and software development.
1. Enable rapid data lookup and retrieval
2. Enhance performance in applications like search engines, data analytics platforms, and
inventory management systems
3. Lead to faster query responses and improved user experiences.
III Course Level Learning Outcome(s)
Perform operations on Stack using Array and Linked List Implementations.
IV Laboratory Learning Outcome(s)
Implement Binary Search Method on Strings.
V Relevant Affective domain related Outcome(s)
1. Follow safety practices.
2. Follow ethical practices.
VI Relevant Theoretical Background
Binary search is a popular algorithm for finding an item from a sorted list of items, and it can be
applied to strings as well as numbers. When applying binary search to strings in C, there are some
important considerations and steps to follow. Below, I will outline the theory and implementation
details for performing a binary search on an array of strings in C.
Theory
Array of Strings: The binary search algorithm requires the array to be sorted. For strings, this means
they should be sorted lexicographically.
Comparison Function: Since we are dealing with strings, we need a way to compare them. In C, the
`strcmp` function from the C standard library can be used for this purpose. `strcmp` compares two
strings and returns:
• A negative value if the first string is less than the second string.
• Zero if the two strings are equal.
• A positive value if the first string is greater than the second string.
• Start with two pointers, `left` and `right`, which initially point to the first and last elements
of the array, respectively.
• Calculate the middle index.
• Compare the middle element with the target string using `strcmp`.
• If the middle element matches the target string, return the index.
• If the target string is less than the middle element, search in the left half of the array.
• If the target string is greater than the middle element, search in the right half of the array.
• Repeat the process until the pointers cross or the target string is found.
VII Algorithm
IX C Program Code
XIV Conclusion
1. Write a C program that performs binary search on a sorted array of strings. The program
should:
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
1. https://www.javatpoint.com/data-structure-introduction
2. https://www.geeksforgeeks.org/introduction-to-data-structures/
Practical No.6: * Write a ‘C’ Program to Sort an Array of numbers using Bubble Sort
Method.
I Practical Significance
Bubble sort is one of the simplest sorting algorithms that works by repeatedly stepping through the
list to be sorted, comparing each pair of adjacent items, and swapping them if they are in the wrong
order. This process is repeated until no swaps are needed, which indicates that the list is sorted.
Bubble sort is one of the simplest sorting algorithms that works by repeatedly stepping through the
list to be sorted, comparing each pair of adjacent items, and swapping them if they are in the wrong
order. This process is repeated until no swaps are needed, which indicates that the list is sorted.
Key Characteristics:
Simple Implementation: Easy to understand and implement.
Comparison-Based: Each element is compared with its adjacent element.
In-Place Sorting: Requires a constant amount of additional memory space.
Stable Sort: Maintains the relative order of records with equal keys (i.e., values).
In summary, the bubble sort algorithm repeatedly swaps adjacent elements until the array is sorted.
The algorithm has a time complexity of O(n2), which makes it inefficient for large data sets.
Working of Bubble Sort
Suppose we are trying to sort the elements in ascending order.
1. First Iteration (Compare and Swap)
Starting from the first index, compare the first and the second elements.
If the first element is greater than the second element, they are swapped.
Now, compare the second and the third elements. Swap them if they are not in order.
The above process goes on until the last element.
2. Remaining Iteration
The same process goes on for the remaining iterations.
After each iteration, the largest element among the unsorted elements is placed at the end.
In each iteration, the comparison takes place up to the last unsorted element.
The array is sorted when all the unsorted elements are placed at their correct positions.
The array is sorted if all elements are kept in the right order
IX C Program Code
X Resources required
Equipment Name with broad specification Relevant LLO
Sr.
Number
No.
1 Computer System with all necessary Peripherals and
Internet Connectivity ALL
‘C’ Compiler / GCC Compiler/ Online ‘C’ Compiler All
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of Static memory allocation using fixed memory size
4. Follow safety practices.
XIII Conclusion
XV Exercise
1. Enlist Applications of Bubble Sort.
2. Explain why Bubble sort is called as stable Sort.
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No.7: * Write a ‘C’ Program to Sort an Array of Strings using Bubble Sort
Method
I Practical Significance
Bubble sort is one of the simplest sorting algorithms that works by repeatedly stepping through the
list to be sorted, comparing each pair of adjacent items, and swapping them if they are in the wrong
order. This process is repeated until no swaps are needed, which indicates that the list is sorted.
Step-by-Step Process:
1. Initial Array:
2. First Pass:
- Compare "banana" and "apple". Since "banana" > "apple", swap them.
["apple", "banana", "cherry", "date"]
- Compare "banana" and "cherry". No swap needed as "banana" < "cherry".
- Compare "cherry" and "date". No swap needed as "cherry" < "date".
3. Second Pass:
- Compare "apple" and "banana". No swap needed as "apple" < "banana".
- Compare "banana" and "cherry". No swap needed as "banana" < "cherry".
4. Third Pass:
- Compare "apple" and "banana". No swap needed as "apple" < "banana".
Since no swaps were needed in the last pass, the array is now sorted.
Sorted Array:
VII Algorithm
X Resources required
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of Dynamic memory allocation to store Stack data
4. Follow safety practices.
XIII Conclusion
………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No.8: * Write a ‘C’ Program to Sort an Array of numbers using Selection
Sort Method.
I Practical Significance
Selection Sort is an in-place comparison sorting algorithm. It divides the input list into two parts:
the sublist of items already sorted, which is built up from left to right at the front of the list, and the
sublist of items remaining to be sorted that occupy the rest of the list. The algorithm proceeds by
finding the smallest (or largest, depending on sorting order) element from the unsorted sublist,
exchanging it with the leftmost unsorted element, and moving the sublist boundaries one element to
the right.
Let’s see the basic working and principles of the selection sort algorithm using your example
array: arr[] = {17, 34, 25, 49, 09}
Selection Sort Working Principle:
Initialization: Start with the first element as the current “minimum” (initially assuming it’s the
smallest).
Search for Minimum: Iterate through the remaining unsorted elements, comparing each one with
the current “minimum.” If you find a smaller element, update the current “minimum.”
Swap: After completing the iteration and finding the actual minimum among the unsorted elements,
swap it with the first unsorted element (the one you started with).
Repeat: Repeat steps 1-3 for the next unsorted element, then the next, until the entire array is sorted.
Here’s how selection sort works step-by-step for your array
VII Algorithm
IX C Program Code
X Resources required
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of Dynamic memory allocation to store Stack data
4. Follow safety practices.
XIII Conclusion
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No.9: * Write a ‘C’ Program to Sort an Array of Strings using Selection Sort
Method.
I Practical Significance
Selection Sort is an in-place comparison sorting algorithm. It divides the input list into two parts:
the sublist of items already sorted, which is built up from left to right at the front of the list, and the
sublist of items remaining to be sorted that occupy the rest of the list. The algorithm proceeds by
finding the smallest (or largest, depending on sorting order) element from the unsorted sublist,
exchanging it with the leftmost unsorted element, and moving the sublist boundaries one element to
the right.
2. First Pass:
- Find the minimum string in the array, which is "apple".
- Swap "apple" with the string at the first position.
["apple", "banana", "cherry", "date", "elderberry"]
3. Second Pass:
- Find the minimum string in the remaining array, which is "banana".
- Swap "banana" with the string at the second position.
["apple", "banana", "cherry", "date", "elderberry"]
4. Third Pass:
- The minimum string in the remaining array is "cherry", which is already in its correct
position.
["apple", "banana", "cherry", "date", "elderberry"]
5. Fourth Pass:
- The minimum string in the remaining array is "date", which is already in its correct
position.
["apple", "banana", "cherry", "date", "elderberry"]
6. Fifth Pass:
- The remaining string "elderberry" is already in its correct position as it is the largest.
["apple", "banana", "cherry", "date", "elderberry"]
7. Array is Sorted:
- The array is now sorted lexicographically.
["apple", "banana", "cherry", "date", "elderberry"]
VII Algorithm
IX C Program Code
X Resources required
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of Dynamic memory allocation to store Stack data
4. Follow safety practices.
XIII Conclusion
XV Exercise
1. Discuss whether Selection Sort maintains the stability of the original array when sorting an
array of strings. Provide reasoning for your answer and, if necessary, demonstrate with
examples.
2. Explain why Selection Sort is considered inefficient for large datasets.
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No.10: * Write a ‘C’ Program to Sort an Array of numbers using Insertion Sort
Method
I Practical Significance
Insertion sort is a simple sorting algorithm that works by iteratively inserting each element of an
unsorted list into its correct position in a sorted portion of the list. It is a stable sorting algorithm,
meaning that elements with equal values maintain their relative order in the sorted output.
Suppose we have an array [ 6,2,1,3,5 ], the insertion sort algorithm considers the first element is
already sorted. There are going to be n-1 passes to sort the array in ascending order.
First Pass:
The second element i.e. 2 is compared to the first element 6, which is lesser, hence swapping is
performed with the first pass making it [6,6,1,3,5], ending with the processed array [ 2,6,1,3,5 ]
Second Pass:
For this pass, the index will be at the 2nd position or 3rd element, as the swapping is valid now that
1>6, the array turns [2,6,6,3,5] and on the following iteration, the result of this pass is obtained as
[2,2,6,3,5] and the final processed array obtained becomes [1,2,6,3,5]
Third Pass:
As the array up and until now is [1,2,6,3,5], 3 will be the key, with its transition being, [1,2,6,6,5]
and result as [1,2,3,6,5] on the assignment of the key.
Fourth Pass:
The n-1th and also the last pass on this array of 5 elements, only one iteration will be possible with
5 replacing the second last element 6 i.e. [1,2,3,6,6] and assignment of the key to give us the obtained
array in the form of [1,2,3,5,6] as the output.
VII Algorithm
IX C Program Code
X Resources required
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of Dynamic memory allocation to store Stack data
4. Follow safety practices.
XIII Conclusion
1. Modify the Insertion Sort algorithm to use binary search for finding the correct position to
insert the current element. Implement this modified algorithm and compare its performance
with the standard Insertion Sort.
2. Use the Insertion Sort algorithm to count the number of inversions in an array. An inversion
is a pair of elements where the earlier element is greater than the later element.
XV Exercise
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No.11: * Write a ‘C’ Program to Sort an Array of Strings using Insertion Sort
Method
I Practical Significance
Insertion sort is a simple sorting algorithm that works by iteratively inserting each element of an
unsorted list into its correct position in a sorted portion of the list. It is a stable sorting algorithm,
meaning that elements with equal values maintain their relative order in the sorted output.
Time Complexity:
In the worst-case scenario, when the array is in reverse order, insertion sort has a time
complexity of O(n^2).
In the best-case scenario, when the array is already sorted, insertion sort has a time
complexity of O(n).
The average-case time complexity is also O(n^2).
Space Complexity:
Insertion sort typically has a space complexity of O(1) since it sorts the array in-place
without requiring any additional space proportional to the size of the input.
Stability:
Insertion sort is a stable sorting algorithm, meaning it preserves the relative order of equal
elements.
Adaptiveness:
Insertion sort is adaptive. It performs better when the input array is partially sorted or nearly
sorted, as it requires fewer comparisons and swaps in such case s.
Practical Use Cases:
Insertion sort is often used for small arrays or partially sorted arrays where simplicity and
adaptiveness outweigh the efficiency concerns of other sorting algorithms.
It's also useful in scenarios where stability is important, such as sorting structures with
multiple fields where one field serves as the primary key and the other as a secondary key.
IX C Program Code
X Resources required
Equipment Name with broad specification Relevant LLO
Sr.
Number
No.
1 Computer System with all necessary Peripherals and Internet
Connectivity ALL
‘C’ Compiler / GCC Compiler/ Online ‘C’ Compiler All
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Follow safety practices.
XIII Conclusion
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No.12: *Write a 'C' Program to Implement Singly Linked List with Operations:
(i) Insert at beginning, (ii) Search, (iii) Display
I Practical Significance
A Singly Linked List is a linear data structure in which the elements are not stored in contiguous
memory locations and each element is connected only to its next element using a pointer.
1. Provide a reliable and efficient data structure that can be used as a building block for more
complex algorithms and applications.
2. Perform basic operations such as insertion, deletion, and traversal without errors or unexpected
behavior.
3. Minimize memory usage.
4. Optimize traversal and search operations
VII Algorithm
IX C Program Code
X Resources required
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of Dynamic memory allocation to store Stack data
4. Follow safety practices.
XIII Conclusion
XV Exercise
1. Explain the use of Singly Linked List
2. Write advantages and disadvantages of Singly Linked List
3. Calculate length of Singly Linked List
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No.13: *Write a 'C' Program to Implement Singly Linked List with
Operations: (i) Insert at end (ii) Insert after (iii)Delete(iv) Display
I Practical Significance
A Singly Linked List is a linear data structure in which the elements are not stored in
contiguous memory locations and each element is connected only to its next element using a
pointer.
IX C Program Code
X Resources required
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of Dynamic memory allocation to store Stack data
4. Follow safety practices.
XIII Conclusion
XV Exercise
1. Write applications of Singly Linked List.
2. Explain the procedure to find middle of singly linked list.
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
I Practical Significance
Polynomial is a fundamental operation in mathematics and computer science, widely used
in various applications such as signal processing, computer graphics, and scientific
simulations. When dealing with polynomials, it is essential to have an efficient and
flexible data structure to represent and perform operations on them. Linked lists provide
an elegant solution for efficiently handling polynomials due to their dynamic memory
allocation and straightforward implementation.
Let us consider an example an example to show how the addition of two polynomials is
performed,
P(x) = 3x4 + 2x3 - 4 x2 + 7
Q (x) = 5x3 + 4 x2 - 5
These polynomials are represented using a linked list in order of decreasing exponents as
follows:
VII Algorithm
IX C Program Code
X Resources required
Sr. Equipment Name with broad specification Relevant LLO
No. Number
1 Computer System with all necessary Peripherals and Internet
Connectivity ALL
‘C’ Compiler / GCC Compiler/ Online ‘C’ Compiler All
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of linked list to create polynomials
4. Follow safety practices.
XIII Conclusion
XV Exercise
1. Give reason for using linked lists for polynomial creation?
2. Compare creating polynomial using Array and Linked List. (any two points)
………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
XVI References / Suggestions for further Reading Software/Learning Websites
1. https://www.prepbytes.com/blog/linked-list/adding-two-polynomials-using-linked-list/
2. https://www.javatpoint.com/application-of-linked-list
3. https://www.geeksforgeeks.org/adding-two-polynomials-using-linked-list/
4. https://gist.github.com/jamesgeorge007/336622f348815f0bef589bae5b622cff
I Practical Significance
Polynomial is a fundamental operation in mathematics and computer science, widely used
in various applications such as signal processing, computer graphics, and scientific
simulations. When dealing with polynomials, it is essential to have an efficient and flexible
data structure to represent and perform operations on them. Linked lists provide an elegant
solution for efficiently handling polynomials due to their dynamic memory allocation and
straightforward implementation.
Let us consider an example an example to show how the addition of two polynomials is performed,
These polynomials are represented using a linked list in order of decreasing exponents as follows:
To generate a new linked list for the resulting polynomials that is formed on the addition of given
polynomials P(x) and Q(x), we perform the following steps,
1. Traverse the two lists P and Q and examine all the nodes.
2. We compare the exponents of the corresponding terms of two polynomials. The first term
of polynomials P and Q contain exponents 4 and 3, respectively. Since the exponent of the
first term of the polynomial P is greater than the other polynomial Q, the term having a
larger exponent is inserted into the new list.
The new list initially looks as shown below:
1. We then compare the exponent of the next term of the list P with the exponents of the present
term of list Q. Since the two exponents are equal, so their coefficients are added and appended
to the new list as follows:
2. Then we move to the next term of P and Q lists and compare their exponents. Since exponents
of both these terms are equal and after addition of their coefficients, we get 0, so the term is
dropped, and no node is appended to the new list after this
VII Algorithm
X Resources required
Equipment Name with broad specification Relevant LLO
Sr.
Number
No.
1 Computer System with all necessary Peripherals and Internet
Connectivity ALL
‘C’ Compiler / GCC Compiler/ Online ‘C’ Compiler All
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of linked list to create and two polynomials
4. Follow safety practices.
XIII Conclusion
XV Exercise
1. Give applications of Polynomial Addition using Linked List in C.
2. List advantages of Polynomial Addition using Linked List in C
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No.16: * Write a 'C' Program to perform PUSH and POP Operations on
Stack using an Array.
I Practical Significance
Stacks are a fundamental data structure in computer science and have numerous practical
applications based on their LIFO (Last In, First Out) property. Hence Stack is Linear Data
Structure where insertion and deletion take place only from one end called as Stack Top.
VII Algorithm
IX C Program Code
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of Static memory allocation using fixed memory size
4. Follow safety practices.
XII Result (Output of Program)
XIII Conclusion
XV Exercise
1. Enlist stack applications.
2. Consider the following stack and observe how many operations are required to delete smallest
element from given stack.
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No.17: * Write a 'C' Program to perform PUSH and POP Operations on
Stack using Linked List.
I Practical Significance
Stacks are a fundamental data structure in computer science and have numerous practical
applications based on their LIFO (Last In, First Out) property. Hence Stack is Linear Data
Structure where insertion and deletion take place only from one end called as Stack Top.
POP operation:
First thing is to check if the stack is not already empty Now, we follow the same concept we learnt
while deleting an element at the head or at the index 0 in a linked list. Just update the top pointer
with the next node, skipping the current top.
VII Algorithm
IX C Program Code
X Resources required
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of Dynamic memory allocation to store Stack data
4. Follow safety practices.
XIII Conclusion
XV Exercise
1. What are the advantages of using a linked list to implement a stack?
2. Give limitations of using Linked List based Stack.
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
I Practical Significance
In essence, recursion is a fundamental concept in computer science and mathematics that
provides a method for solving problems by breaking them down into smaller, more
manageable sub-problems. Particularly in Data Structure, it is a powerful tool to work
with recursive data structures like trees and graphs. For example, tree traversals (in-order,
pre-order, post-order) are most easily implemented using recursion. Similarly, many
graph algorithms, such as depth-first search (DFS), are naturally expressed recursively.
Some classical algorithms like Merge Sort, Quick Sort use a recursive divide-and-
conquer strategy. Hence by storing the results of subproblems (memorization), recursive
algorithms can be optimized to avoid redundant computations.
VII Algorithm
IX C Program Code
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Follow safety practices.
XIII Conclusion
XV Exercise
1. Define a term recursion and give its advantages.
2. Describe how stack is used in recursion with example.
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No.19: Write a 'C' program to print given string in reverse using recursion.
I Practical Significance
Recursion is a powerful programming technique where a function calls itself in order
to solve smaller instances of the same problem. This approach can be particularly useful
for certain types of string operations.
VII Algorithm
IX C Program Code
X Resources required
XIII Conclusion
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Practical No.20: Write a 'C' program to create a Singly Linked List and traverse
in reverse order using recursion.
I Practical Significance
Linear data structure, particularly Singly Linked List is also known as One-way header list.
It can be traversed only in one direction from first node to last node of linked list. In order to
traverse it in reverse order we have two approaches- one is using stack and other is using
recursion. Although the first approach works well but it requires extra space, hence to avoid
it we can use recursive function call to traverse linked list in reverse order.
OUTPUT: 5 4 3 2 1
Figure 20.1: Traversing a Linked List using recursion
VII Algorithm
IX C Program Code
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of recursive function call
4. Follow safety practices
XIII Conclusion
XV Exercise
1. Give recursive function to create a copy of linked list using recursion.
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
I Practical Significance
The ability to manage ordered sequences of elements and handling of tasks and resources
efficiently makes the use of queue indispensable in various applications across different fields,
from computing and networking to business operations and service management. It is a linear data
structure works in First in First (FIFO) Order with two operational ends Front End to add new
element and Rear End to delete or process new element.
Figure 21.1: Insertion (enqueue) and Deletion (dequeue) operations on Linear Queue
VII Algorithm
IX C Program Code
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of recursive function call
4. Follow safety practices.
XIII Conclusion
XV Exercise
1. Describe Queue as Abstract Data Type (ADT).
2. Give applications of Queue in different domains.
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
I Practical Significance
The major problem with the queue implemented using an array is, t will work for an only fixed
number of data values. That means, the amount of data must be specified at the beginning itself.
Queue using an array is not suitable when we don't know the size of data which we are going to
use. A queue data structure can be implemented using a linked list data structure. The queue which
is implemented using a linked list can work with the variable size of data. Implementing a queue
using a linked list provides dynamic size management, efficient insertions and deletions, avoidance
of overflow issues, better memory utilization, and flexibility. These characteristics make linked
list-based queues suitable for various real-world applications, especially where dynamic and
efficient data handling is critical.
Figure 22.1: Insertion (enqueue) and Deletion (dequeue) operations on Linear Queue using
Linked List
VII Algorithm
IX C Program Code
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of recursive function call
4. Follow safety practices.
XIII Conclusion
XV Exercise
1. Differentiate between stack and queue.
2. Give advantages of using linked list in implementation of Queue.
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
I Practical Significance
Circular queues offer significant advantages over linear queues, particularly in terms of space
efficiency, fixed size implementation, efficient operations, and suitability for real-time systems.
They are widely used in various applications where predictable and efficient data handling is
crucial.
Hence to utilize the empty spaces for adding new items in the queue we can use a circular queue
implementation in which both pointers front and rear are circular increments that mean after
reaching the end of the queue the pointers come back to the start of the queue.
IX C Program Code
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of recursive function call
4. Follow safety practice
XIII Conclusion
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
I Practical Significance
Unlike arrays, linked lists do not have a fixed size. This allows the circular queue to grow and
shrink as needed without wasting memory or encountering overflow issues. Using Linked List
Memory is allocated dynamically, ensuring that only the necessary amount of memory is used,
reducing waste. These advantages make circular queues implemented with linked lists a good
choice, especially in scenarios where the maximum number of elements is not known in advance
or can vary significantly over time.
If there is more than one node in Queue then make front next to front hen initialize rear next from
front.
Print temp and free temp.
VI Algorithm
X Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of linked list
4. Follow safety practices.
XII Conclusion
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
I Practical Significance
A priority queue is a specialized data structure that operates similarly to a regular queue, but with
an added feature: each element is associated with a priority. Elements are dequeued not based on
their order of arrival, but according to their priority. It can be used in different applications like
process scheduling, networking, simulations etc.
VII Algorithm
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure correct use of linked list in implementing priority queue.
4. Follow safety practices.
XIII Conclusion
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
XVI References / Suggestions for further Reading Software/Learning Websites
1. https://www.prepbytes.com/blog/linked-list/priority-queue-using-linked-list/
2. https://prepinsta.com/c-program/implementation-of-priority-queue-using-linked-list/
3. https://www.javatpoint.com/priority-queue-using-linked-list
4. https://www.scholarhat.com/tutorial/datastructures/priority-queue-in-data-structures
Practical No.26: * Write a 'C' Program to Implement BST (Binary Search Tree)
and Traverse in In-Order.
I Practical Significance
Binary trees are a fundamental and versatile data structure with numerous applications in
computer science and software engineering. Their efficient representation of hierarchical
data, support for various traversal methods, and foundational role in more complex
structures make them an essential concept to understand and utilize effectively. Binary
trees support various traversal methods (Pre-order, In-order, Post-order), which are useful
for different applications, such as expression evaluation, syntax parsing, and more.
X Resources required
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of dynamic memory allocation
4. Follow safety practices.
XIII Conclusion
XV Exercise
1. Create Binary Search Tree of alphabet A to G.
2. Write In-order Traversal for above Tree.
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
Post-order Traversal
In a post-order traversal, nodes are visited in the order: left subtree, right subtree, current node.
This is useful for deleting the tree.
VII Algorithm
IX C Program Code
XI Precautions to be Followed
1. Ensure that all C statements must end with a semicolon (;).
2. Use white spaces in c to describe blanks and tabs.
3. Ensure use of dynamic memory allocation
4. Follow safety practices.
XIII Conclusion
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
…………………………………………………………………………………
XVI References / Suggestions for further Reading Software/Learning Websites
1. https://www.scholarhat.com/tutorial/datastructures/binary-search-tree-in-data-structures