SYBSC SEMIII Labbook 2020 21 Final Version
SYBSC SEMIII Labbook 2020 21 Final Version
WORKBOOK
Student Name:
College:
Year: Division:
Page 3 of 57
Table of Contents
1 Introduction 4
9 Stack 30
10 Applications on Stack 32
Introduction
Data structures and Algorithm is an important core subject of computer science curriculum,
and hands-on laboratory experience is critical to the understanding of theoretical concepts
studied as part of this course. Study of any programming language is incomplete without
hands on experience of implementing solutions using programming paradigms and verifying
them in the lab. This workbook provides rich set of problems covering the basic algorithms as
well as numerous computing problems demonstrating the applicability and importance of
various data structures and related algorithms.
• Bringing uniformity in the way the course is conducted across different colleges
• Bring variation and variety in experiments carried out by different students in a batch
The Data Structures and Algorithms practical syllabus is divided into five assignments. Each
assignment has problems divided into three sets A, B and C.
• Set A is used for implementing the basic algorithms or implementing data structure
along with its basic operations. Set A is mandatory.
Page 5 of 57
• Set B is used to demonstrate small variations on the implementations carried out in set
A to improve its applicability. Depending on the time availability the students should
be encouraged to complete set B.
• Set C prepares the students for the viva in the subject. Students should spend
additional time either at home or in the Lab and solve these problems so that they get
a deeper understanding of the subject.
• Students should prepare oneself before hand for the Assignment by reading the
relevant material.
• Instructor will specify which problems to solve in the lab during the allotted slot and
student should complete them and get verified by the instructor. However student
should spend additional hours in Lab and at home to cover as many problems as
possible given in this work book.
• Explain the assignment and related concepts in around ten minutes using white board
if required or by demonstrating the software.
• The value should also be entered on assignment completion page of the respective
Lab course.
• You have to ensure appropriate hardware and software is made available to each
student.
7 Stack
8 Application on Stack
Total out of 50
University Exam Seat Number _________ has successfully completed the course work
for Lab Course I and has scored _________ Marks out of 15.
Instructor Head
Section I
Data Structure
and
Algorithms I
Page 9 of 57
Searching is the process of finding a value in a list of values.The searching algorithms you
are to use in this assignment are linear, sentinel and binary search.
In Linear search, we search an element or value in a given array by traversing the array from
the starting, till the desired element or value is found.
Algorithm:
Step 1: Start
Step 2: Accept n numbers in an array num and a number to be searched
Step 3: se ti=0 and flag=0
Step 4: if i<n then goto next step else goto step 7
Step 5: Compare num[i] and number
If equal then
set flag=1 and goto step 7
Step 6: i=i+1 and goto step 4
Step 7: if (flag=1) then
Print “Required number is found at location i+1”
else
Print “Require data not found”
Step 8: Stop
Time Complexity:
Sentinel search is a type of linear search where the number of comparisons is reduced as
compared to a traditional linear search. The value to be searched can be appended to the list
at the end as a “sentinel value.
Algorithm:
Step 1: Start
Step 2: Accept n numbers in an array num and a number to be searched
Step 3: set i=0, last=num[n-1], num[n-1]=number
Step 4: Compare num[i] and number
If equal then goto step 6
Step 5: i=i+1 and goto step 4
Page 10 of 57
Step 6: num[n-1]=last
Step 7: if (num[i]=number) then
Print “Required number is found at location i+1”
else
Print “Require data not found”
Step 8: Stop
Time Complexity:
Binary Search is used with sorted array or list. So a necessary condition for Binary search to
work is that the list/array should be sorted. It works by repeatedly dividing in half the portion
of the list that could contain the item.
Algorithm:
Step 1: Start
Step 2: Accept n numbers in an array num and a number to be searched
Step 3: set low=0, high=n-1 and flag=0
Step 5: if low <= high then
middle=(low+high)/2
else
goto step 8.
Step 6: if (num[middle]=number)
position=middle, flag=1 goto step 8.
else if (number< num[middle])
high=middle-1
else
low=middle+1
Step 7: goto step 5
Step 8: if flag=1
Print “Required number is found at location position+1”
Else
Print “Required number is not found.
Step 9: Stop
Time Complexity:
Set A
a) Create a random array of n integers. Accept a value x from user and use linear search
algorithm to check whether the number is present in the array or not and output the position if
the number is present.
b) Accept n values in array from user. Accept a value x from user and use sentinel linear
search algorithm to check whether the number is present in the array or not and output the
position if the number is present.
c) Accept n sorted values in array from user. Accept a value x from user and use binary
search algorithm to check whether the number is present in sorted array or not and output the
position if the number is present.
Set B
a) Read the data from file 'cities.txt' containing names of cities and their STD codes. Accept a
name of the city from user and use linear search algorithm to check whether the name is
present in the file and output the STD code, otherwise output “city not in the list”.
b) Read the data from file 'cities.txt' containing names of cities and their STD codes. Accept a
name of the city from user and use sentinel linear search algorithm to check whether the
name is present in the file and output the STD code, otherwise output “city not in the list”.
c) Read the data from file ‘sortedcities.txt’ containing sorted names of cities and their STD
codes. Accept a name of the city from user and use binary search algorithm to check whether
the name is present in the file and output the STD code, otherwise output “city not in the list”.
Set C
a) If the file contains multiple occurrences of a given element, linear search will give the
Page 12 of 57
position of the first occurrence, what modifications are required to get the last occurrence?
b) If the file contains multiple occurrences of a given element, will binary search output the
position of first occurrence or last occurrence?
c) Which is best case search when searching using linear search, sentinel search and when
using binary search?
d) What modifications are required to linear search, sentinel search and binary search
algorithm to count the number of comparisons?
e) What modifications are required to binary search so that it returns the position where x can
be inserted in the sorted array to retain the sorted order?
Assignment Evaluation
Practical In-charge
Page 13 of 57
Arranging in an ordered sequence is called Sorting.The sorting algorithms you are to use in
this assignment are bubble sort, insertion sort and selection sort. These are non-recursive
algorithms.
Bubble Sort
It compares adjacent elements and swaps if required. The pass is repeated until the list is
sorted.
Algorithm:
Step1: Start
Step2: Accept ‘n’ numbers in array ‘A’
Step3: set i=0
Step4: if i<n-1 then goto next step else goto step 9
Step4: set j=0
Step5: if j<n-i-1 then goto next step else goto step 8
Step6: if A[j] > A[j+1] then
interchange A[j] and A[j+1]
Step7: j=j+1 and goto step 5
Step8: i=i+1 and goto step 4
Step9:Stop
Time Complexity:
Insertion Sort
Insertion sort removes one element from list, find proper location in the list and insert it in the
list. This is repeated until no input element remains.
Algorithm:
Step1: Start
Step2: Accept ‘n’ numbers and store all in array ‘A’
Step3: set i=1
Step4: if i<=n-1 then goto next step else goto step 10
Step5: set Temp=A[i] and j=i-1
Page 14 of 57
Step6: if Temp < A[j] && j>=0 then goto next step else goto step 9
Step7: set A[j+1]=A[j]
Step8: set j=j-1
Step9: set A[j+1]=Temp
Step10: Stop
Time Complexity:
Selection Sort:
In this sort the smallest element is selected from the unsorted array and swapped with the
leftmost element.
Algorithm:
Step1: Start
Step2: Accept ‘n’ numbers and store all in array ‘A’
Step3: set i=0
Step4: if i<n-1 then goto next step else goto step 11
Step5: set min=i and j=i+1
Step6: if j<n then goto next step else goto step 9
Step7: if A[j]<A[min] then
min=j
Step8: set j=j+1 and goto step 7
Step9: if(min not equal to i) then
interchange A[i] and A[min]
Step10: i=i+1 and goto step 4
Step11: Stop
Time Complexity:
In reality data to be sorted is externally stored in files. One need to read data from files and
bring it into memory in an array before sorting and sorted array also need to be written back
to an external file.
Suppose the records to be sorted containing name, age and salary of a set of employees, is in
Page 15 of 57
Rajiv 43 100000
Prakash 34 29000
Vinay 35 20000
..................................
typedef struct
{
char name[30];
int age;
intsalary;
}RECORD;
RECORD emp[100];
main()
{
int n; n=readFile(emp);
sort(emp,n);
writeFile(emp,n);
}
Set A
a) Sort a random array of n integers (accept the value of n from user) in ascending order by
using bubble sort algorithm.
b) Sort a random array of n integers (create a random array of n integers) in ascending order
by using insertion sort algorithm.
c) Sort a random array of n integers (accept the value of n from user) in ascending order by
using selection sort algorithm.
Set B
a) Read the data from the file “employee.txt” and sort on age using bubble sort, insertion sort
and selection sort.
b) Read the data from the file “employee.txt” and sort on names in alphabetical order (use
strcmp) using bubble sort, insertion sort and selection sort.
Set C
a) What modification is required to bubble sort, insertion sort and selection to sort the
integers in descending order?
c)What modifications are required to bubble sort to count the number of swaps?
c)What modifications are required to insertion sort to count the number of key comparisons?
Page 17 of 57
d) What modifications are required to output the array contents after every pass of the sorting
algorithm?
Assignment Evaluation
Practical In-charge
Page 18 of 57
Sorting techniques to be used in this assignment are Counting Sort, Merge sort, Quick sort.
Merge and Quick sort both are recursive and use divide and conquer strategy.
Counting sort is an algorithm for sorting a collection of objects according to keys that are
small integers. So, it is an integer sorting algorithm.
countingSort(array, size)
max <- find largest element in array
initialize count array with all zeros
for j <- 0 to size
find the total count of each unique element and
store the count at jth index in count array
for i<- 1 to max
find the cumulative sum and store it in count array itself
for j <- size down to 1
restore the elements to array
decrease count of each element restored by 1
In Merge sort, data is divided into two parts, each part is sorted by using the same merge sort
technique and the sorted files are then merged using a Merge procedure.
Algorithm:
mergesort(a, N) algorithm:
Step1: Start
Step2: Accept N numbers and store into array a
Step3: Assign low=0 and high=N-1
Step4: if low < high
mid=(low+high)/2
mergesort(a,low,mid);
mergesort(a,mid+1,high);
merge(a,low,mid,high);
Step3: while(i<=mid)
b[k]=a[i]
k=k+1, i=i+1
Step4: while(j<=high)
b[k]=a[j]
k=k+1, j=j+1
In Quick sort, data is partitioned into two parts in such a way that all elements in first part
are less than or equal to elements in second part. Both the parts are then sorted using the same
Quick sort technique.
Algorithm:
QuickSort(A,n)
Step1: Start
Step2: Accept ‘n’ numbers and store all in array ‘A’
Step3: lb=0, ub=n-1
Step3: if (lb<ub)
j=Partition(A,lb,ub)
QuickSort(A,lb,j-1)
QuickSort(A,j+1,ub)
Set A
Page 20 of 57
a) Sort a random array of n integers (accept the value of n from user) in ascending order by
using recursive Counting sort algorithm.
b)Sort a random array of n integers (accept the value of n from user) in ascending order by
using a recursive Merge sort algorithm.
c) Sort a random array of n integers (create a random array of n integers) in ascending order
by using recursive Quick sort algorithm.
Set B
a)Read the data from the ‘employee.txt’ file and sort on age using Counting sort, Merge sort,
Quick sort and write the sorted data to another file 'sortedemponage.txt'.
b)Read the data from the file and sort on names in alphabetical order (use strcmp) using
Counting sort, Merge sort, Quick sort and write the sorted data to another file
'sortedemponname.txt'.
Set C
a) What modifications are required to choose the pivot element randomly instead of choosing
the first element as pivot element while partitioning in Quick sort algorithm?
b)Compare the system time taken by Merge sort and bubble sort by using time command on a
random array of integers of size 10000 or more.
c)What modification is required to Merge sort to sort the integers in descending order?
d)In 'employee.txt' there are records with same name but different age and salary values.
What are the relative positions when the data is sorted on name using Merge sort and what
happens in case of quick sort?
e)Sort a random array of integers of large size and store the sorted file. Compare the system
time taken by Quicksort on a random file of large size and the sorted file of same size. Repeat
the same for Merge sort. Does sorted file give best time?
Assignment Evaluation
Practical In-charge
Page 21 of 57
Header files are helping file of C program which holds the definitions of various functions
and their associated variables.These header files are imported into the C program with the
help of pre-processor #include statement.
#include<file>/* This syntax searches for file-name in the standard list of system
directories */
OR
#include “file”/* This technique is used to search the file(s) within the directory that
contains the file where this include statement is written. */
The custom header file [.h extension] is a file that contains user defined functions. The
Function should accept input (arguments) and generate the output after processing the
received input.
Do you remember how the functions already defined in C header file works?
• Let’s try to explore math.h header file.
• This header file contains the function called as sqrt.
• The signature of the sqrt function is
double sqrt(double arg);
• The sqrt function accepts one argument and returns the result. It doesn’t directly print
the result inside sqrt function.
Note:
Function written inside header file will only accept and return value. It will not have any type
of standard input or output statements.
Page 22 of 57
An abstract data type List is an ordered set of elements where insertions and deletions are
possible from any position. Implementing List statically using an array to store elements is
costly as insertions and deletions require moving of array elements. List is efficiently
implemented dynamically using Linked list.
The linked list is a series of nodes where each node contains the data element and a link to
the node containing the next element. The data element can be integer, character or user
defined type. A list is a single entity which is a pointer to the first node of the linked list. A
dummy node is used as header of the list so that it is not affected by insertions or deletions.
List
append(L, x) Insert the data element x by creating the node containing the data
element x and inserting it in last position.
insert (L, x, pos) inserts the data element x by creating the node containing the data
element x and inserting it in position pos. The links are appropriately
changed. If pos equals 1, the node is inserted in first position
immediately after the header. If pos is greater than the nodes present in
the list, the node is added at the end of the list.
search (L, x) Searches for the data element x and returns the pointer to the node
containing x if x is present or returns NULL.
delete (L, x) Deletes the node containing the data element x by appropriately
modifying the links.
delete (L, pos) Delete the node at a position given by pos. If the position pos is invalid
then display appropriate message.
Page 23 of 57
In a singly linked list there is only a link to the next element. For insertion as well as
deletion one need to traverse with two pointers back and current.
Data Next
Set A
a) Implement a list library (singlylist.h) for a singly linked list with the above six operations.
Write a menu driven driver program to call the operations.
b) Implement a list library (singlylist.h) for a singly linked list. Create a linked list, reverse it
and display reversed linked list.
Set B
a) There are lists where insertion should ensure the ordering of data elements. Since the
elements are in ascending order the search can terminate once equal or greater element is
found. Implement a singly linked list of ordered integers(ascending/descending) with insert,
search and display operations.
b) There are lists where new elements are always appended at the end of the list. The list can
be implemented as a circular list with the external pointer pointing to the last element of the
list. Implement singly linked circular list of integers with append and display operations. The
operation append(L, n), appends to the end of the list, n integers either accepted from user or
randomly generated.
Set C
a) How to divide a singly linked list into two almost equal size lists?
b) The union operation of two disjoint sets takes two disjoint sets S1 and S2 and returns a
disjoint set S consisting of all the elements of S1 and S2 and the original sets S1 and s2 are
destroyed by the union operation. How to implement union in O(1) time using a suitable
list data structure for representing a set?
Page 24 of 57
c) What is the method to reverse a singly linked list in just one traversal?
Assignment Evaluation
Practical In-charge
Page 25 of 57
In a Doubly linked list there is link to the next element as well as a link to the previous
element. For insertion one needs only the pointer to current element and same is true for
deletion.
The two links allow traversal of list in both direction i.e. forward and backward. It is easy to
reverse doubly linked list as compared to singly linked list.
Head
Set A
a) Implement a list library (doublylist.h) for a doubly linked list with the above four
operations. Write a menu driven driver program to call the operationsappend, insert, delete
specific node, delete at position, search, display.
b) Implement a list library (doublylist.h) for a doubly linked list. Create a linked list, reverse
it and display reversed linked list.
Set B
a)There are lists where insertion should ensure the ordering of data elements. Since the
elements are in ascending order the search can terminate once equal or greater element is
found. Implement a doubly linked list of ordered integers(ascending/descending) with insert,
search and display operations.
b)There are lists where new elements are always appended at the end of the list. The list can
be implemented as a circular list with the external pointer pointing to the last element of the
list. Implement doubly linked circular list of integers with append and display operations. The
operation append(L, n), appends to the end of the list, n integers either accepted from user or
randomly generated.
Set C
a) Which operation is performed more efficiently in doubly linked list than singly linked list?
b) What is difference between singly circular linked list and doubly circular linked list?
Page 26 of 57
Assignment Evaluation
Practical In-charge
Page 27 of 57
A linked list is a linear collection of data elements called as nodes in which linear
representation is given by links from one node to another. When we insert a new node in
linked lists, we need to check for OVERFLOW condition, which occurs when no free
memory cell is present in the system. When we delete a node from a linked list, we must first
check for UNDERFLOW condition which occurs when we try to delete a node from a linked
list that is empty. When we delete a node from a linked list, we have to actually free the
memory occupied by that node. The memory is returned back to the free pool so that it can be
used to store other programs and data. Linked lists can be used to implement lists, chains,
single and multi variable polynomials etc.
Two linked lists, each of which is sorted in increasing order, can be merged together into
third list which is again sorted in increasing order.
For example:
Algorithm:
A polynomial is represented by a series of terms, each of which has twointegers. The first
integer represents the coefficient; the second integerrepresents the exponent.
Example: 2x3+ x
Here first term consist of 2x3 , where 2 represent coefficient of x and 3 represent exponent of
x
Page 28 of 57
Two single variable polynomials can be represented by a linked list. Adding two polynomials
means to add the coefficients who have same variable powers.
Example:
Input:
1st number = 6x^2 + 4x^1 + 2x^0
2nd number = 5x^1 + 5x^0
Output:
6x^2 + 9x^1 + 7x^0
Input:
1st number = 3x^3 + 8x^2 + 2x^0
2nd number = 5x^1 + 5x^0
Output:
3x^3 + 8x^2 + 5x^1 + 7x^0
Set A
1)Write a program that merges two ordered linked lists into third new list. When two lists are
merged the data in the resulting list are also ordered. The two original lists should be left
unchanged. That is merged list should be new one. Use linked implementation.
2) Write a program that adds two single variablepolynomials. Each polynomial should be
represented as a list with linked list implementation.
Set B
1) Write a program that sorts the elements of linked list using any of sorting technique.
2) Write a program that multiply two single variable polynomials. Each polynomial should be
represented as a list with linked list implementation.
Set C
1) Write a program to find common elements of two linked lists and create third list. Ensure
Page 29 of 57
that the common elements appear only once in the third list.
Assignment Evaluation
Practical In-charge
Page 30 of 57
Assignment 7: Stack
A stack is a linear data structure in which elements are added and removed only from one
end, which is called the top. Hence, a stack is called a LIFO (Last-In, First-Out) data structure
as the element that is inserted last is the first one to be taken out.
1. Static Implementation:
A stack is implemented statically by using an array of size MAX to hold stack elements and
integer top storing the position of topmost element of the stack. A stack represents a structure
made up of both the array and the top. The stack elements can be integers, characters, strings
or user definedtypes.
Init(S) Create an empty stack and initializes value of top to -1 indicating the
stack is empty
Peek(S) Returns topmost element from the stack S without deleting element.
isEmpty(S) Checks and returns if the stack S is empty or not. Stack isempty when
top==-1
isFull(S) Checks and returns if the stack S is full or not. Stack isfull when
top==MAX-1
2. DynamicImplementation
A stack is implemented dynamically by using a Linked list where each node in the linked
list has two parts, the data element and the pointer to the next element of the stack. Stack is a
single entity i.e. a pointer pointing to the top node in the linked list. The stack elements can
be integers, characters, strings or user defined types. Dynamic lists can grow without limits.
Init(S) Create an empty stack and initializing top to NULL indicating the stack
is empty
S=Pop(S) Deletes top node from stack and returns. Next element will become top
of stack and function returns the changed value of S.
X=Peek(S) Returns topmost element from the stack S without deleting element.
isEmpty(S) Checks and returns if the stack S is empty or not. Stack isempty when
top==NULL
Set A
a) Implement a stack library (ststack.h) of integers using a static implementationof the stack
and implementing the above six operations. Write a driver program that includes stack library
and calls different stackoperations.
Set B
a) Write a program to check whether the contents of two stacks are identical. Use stack
library to perform basic stack operations. Neither stack should be changed.
b) Write a program that copies the contents of one stack into another. Use stack library to
perform basic stack operations. The order of two stacks must be identical.(Hint: Use a
temporary stack to preserve the order).
Set C
a) In dynamic implementation of stack, How to modify pop operation so that it also returns
the popped element as an argument of the pop function?
Assignment Evaluation
Practical In-charge
Page 32 of 57
Stack can be used in many applications like expression conversion, evaluation, parenthesis
checking, checking string is palindrome or not etc. Infix, prefix, and postfix notations are
three different but equivalent notations of writing algebraic expressions.Reversing string of
characters, converting the infix notation into postfix notation and evaluating the postfix
notation make extensive use of stacks as the primary tool. Following are few applications
which extensively uses stack for their implementation.
A string of characters can be reversed by reading each character from a string starting from
the first index and pushing it on a stack. Once all the characters have been read, the
characters can be popped one at a time from the stack and then stored in the another string
starting from the first index.
Infix, prefix, and postfix notations are three different but equivalent notations of writing
algebraic expressions. In postfix notation, operators are placed after the operands, whereas in
prefix notation, operators are placed before the operands. While expression conversion
precedence of operators is considered.
The algorithm accepts an infix expression that may contain operators. The algorithm uses a
stack to temporarily hold operators. The postfix expression is obtained from left-to-right
using the operands from the infix expression and the operators which are removed from the
stack.
Page 33 of 57
Postfix notations are evaluated using stacks. Every character of the postfix expression is
scanned from left to right. If the character is an operand, it is pushed onto the stack. Else, if it
is an operator, then the top two values are popped from the stack and the operator is applied
on these values. The result is then pushed onto the stack.
Set A
a)Write a program that reverses a string of characters. The function should use a stack library
(cststack.h) of stack of characters using a static implementation of the stack.
Set B
Page 34 of 57
b) Write a program that checks whether a string of characters is palindrome or not. The
function should use a stack library (cststack.h) of stack of characters using a static
implementation of thestack.
Set C
a) Write a program that checks the validity of parentheses in any algebraic expression. The
function should use a stack library (cststack.h) of stack of characters using a static
implementation of the stack.
b) Write a program to find all solutions to the four queens problem. Your program will need
to be able to handle a search for a configuration that has no solution.
Assignment Evaluation
Practical In-charge
Page 35 of 57
Queue:
A queue is a linear data structure which follows a particular order in which the operations are
performed. The order is First in First out (FIFO) or Last in Last out (LILO).
In queue elements are added from one end called rear and removed from other end called
front. Linear queue can be implemented statically using arrays and dynamically using linked
lists.
A Queue is implemented statically by using an array of size MAX to hold elements and two
integers called front and rear.
A queue is a single entity that is a structure made up of the array, rear and front. Elements are
added from rear end of the queue and can be deleted from front end of the queue. The ‘front’
stores the position of the current front element and ‘rear’ stores the position of the current
rear element of the queue. The Queue elements can be integers, characters, strings or user
defined types.
isEmpty (Q) Checks whether the queue is empty. Queue becomes empty when rear
equals to front.
isFull(Q) Checks whether the queue is full. Queue becomes full when front
reaches to MAX -1.
A Queue is implemented dynamically by using a Linked list. Each node in the linked list has
two parts, the data element and the pointer to the next element of the queue. Since Queue
should be a single entity, we need to use only one external pointer while here we need two
Page 36 of 57
one for rear and one to the front. To avoid this we use a circular linked list and Queue pointer
is pointing to the rear of the queue. Front can be easily accessed as it is next to rear. The
Queue elements can be integers, characters, strings or user defined types. There is no
restriction on how big the Queue can grow.
add (Q, x) Adding an element x tso the queue Q requires creation of node
containing x and putting it next to the rear and rear points to the
newly added element. This changes the rear pointer Q and the
function should return the changed value of Q. The function call
will be asfollows
X=delete (Q) Deletes the front node from the queue Q which is actually next
element to the rear pointer Q. However if queue contains only
one element, (Q->next == Q) then deleting this single element
can be achieved by making empty Q (Q =NULL). Since the rear
pointer Q is changed in this case, function should return the
changed value of Q. The function call will be asfollows
Q=delete(Q);
returns the data element in the front (Q->next) node of the
X=peek (Q)
Queue Q
isFull(Q) Checks whether the queue is full. Queue becomes full when front
reaches to MAX -1.
1) Circular queue:
In a normal Queue, we can insert elements until queue becomes full. But once queue
becomes full, we cannot insert the next element even if there is a space in front of queue.
Even though there is space available, the overflow condition still exist because the condition
REAR = MAX – 1 still holds true. This is a major drawback of a linear queue.
Circular Queue is a linear data structure in which the operations are performed based on
FIFO (First In First Out) principle and the last position is connected back to the first position
to make a circle, hence making the queue behave like a circular data structure or Ring Buffer.
In case of a circular queue, head pointer will always point to the front of the queue, and tail
pointer will always point to the end of the queue.
Page 37 of 57
Initially, the head and the tail pointers will be pointing to the same location, this would mean
that the queue is empty.New data is always added to the location pointed by the tail pointer,
and once the data is added, tail pointer is incremented to point to the next available location.
In a circular queue, data is not actually removed from the queue. Only the head pointer is
incremented by one position when delete_queue() is executed. As the queue data is only the
data between head and tail, hence the data left outside is not a part of the queue anymore,
hence removed. The head and the tail pointer will get reinitialized to 0 every time they reach
the end of the queue. Also, the head and the tail pointers can cross each other. In other words,
head pointer can be greater than the tail. Sounds odd? This will happen when we
delete_queue the queue a couple of times and the tail pointer gets reinitialized upon reaching
the end of the queue.
Set A
Set B
a) Implement a linear queue library (dyqueue.h) of integers using a dynamic (circular linked
list) implementation of the queue and implementing the above five operations. Write a driver
program that includes queue library and calls different queue operations.
Set C
a) Implement queue library using array or linked list. Use this queue library to simulate
waiting list operations of railway reservation system.
Assignment Evaluation
Practical In-charge
Page 39 of 57
1) Priority queue:
A priority queue is a data structure in which each element is assigned a priority. The priority
of the element will be used to determine the order in which the elements will be processed.
1. An element with higher priority is processed before an element with a lower priority.
2. Two elements with the same priority are processed on a first-come-first-served (FCFS)
basis.
A Priority Queue is different from a normal queue, because instead of being a “first-in-first-
out”, values come out in order by priority, the highest-priority is retrieved first.Thepriority
of the element can be set based on various factors. Priority queues are widely
used in operating systems to execute the highest priority process first.
Doubly Ended Queue is a Queue data structure in which the insert and delete operations can
be performed at both the ends (front and rear) of the queue. That means, we can insert at
both front and rear positions and can delete from both front and rear positions.
Set A
b) A doubly ended queue allows additions and deletions from both the ends that is front and
rear. Initially additions from the front will not be possible. To avoid this situation, the array
can be treated as if it were circular. Implement a queue library (dstqueue.h) of integers using
a static implementation of the circular queue and implementing the nine operations :
1)init(Q), 2) isempty(Q) 3) isFull(Q) 4)getFront(Q), 5)getRear(Q), 6)addFront(Q,x),
7)deleteFront(Q) 8) addRear(Q,x) 9)deleteRear(Q) .
Assignment Evaluation
Practical In-charge
Page 41 of 57
Section II
Software Engineering
Mini Project
Page 42 of 57
MiniProjectusingSoftware EngineeringTechniques
Marks
Sr. (out of 5 for
Assignment Name Signature
No each
diagram)
Structural Model :
1. ➢ Requirement Specification
➢ ER Diagram
➢ Class Diagrams
Behavioral Model :
➢ Sequence Diagram
2. ➢ Collaboration Diagram
➢ Activity Diagram
Architectural Model :
➢ Component Diagram
3.
➢ Deployment Diagram
➢ Package Diagram
Total ( out of 60 )
Total Converted to 10
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
Page 44 of 57
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
Assignment Evaluation
Practical In-charge
Page 45 of 57
Users: Those who will primarily benefit from the new system and those who will be affected
by the new system
Functional Requirements
• Describe what the system actually does
• Describes intended interactions between users and the system, independent of
implementation
Assumptions
List any assumptions that affect the requirements, for example, equipment availability, user
expertise, etc. For example, a specific operating system is assumed to be available; if the
operating system is not available, the Requirements Specification would then have to change
accordingly.
Assignment Evaluation
Practical In-charge
Page 46 of 57
Assignment Evaluation
Practical In-charge
Page 47 of 57
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
______________________________________________________________________
Use Cases:
Page 48 of 57
Assignment Evaluation
Practical In-charge
Page 49 of 57
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
Class Diagram:
Page 50 of 57
Assignment Evaluation
Practical In-charge
Page 51 of 57
Assignment Evaluation
Practical In-charge
Page 52 of 57
Assignment Evaluation
Practical In-charge
Page 53 of 57
Assignment Evaluation
Practical In-charge
Page 54 of 57
Assignment Evaluation
Practical In-charge
Page 55 of 57
Assignment Evaluation
Practical In-charge
Page 56 of 57
Assignment Evaluation
Practical In-charge
Page 57 of 57
Assignment Evaluation
Practical In-charge