DS&Algo - Lab Assignment Sheet - New
DS&Algo - Lab Assignment Sheet - New
1) Write a C program for in place reversing an array of integers. You should use a function
that access values of an array using pointers for reversal and pointer as an argument. In
place reversing means without using any other array you have to overwrite it with its own
reversal.
2) Implement and compare the Insertion, Selection and Bubble sort techniques on a
randomly generated data set of size N given by user at runtime. Compare all three
techniques based on (a) total number of comparisons (b) total number of swaps. Repeat
the experiment for five different sets of such a data and tabulate the results.
3) Write a program in C to perform following operations on singly linked list (SLL). For
every operation create a separate function.
a. Create a linked list containing 10 elements. Display the contents of SLL
b. Search an element entered by the user and return its position. For example, if the
elements of the list are: 23, 12, 8, 78, 5, 45, 8, 15, 18, 20, 2, 19, 9, 8, 25, 17, then
the position of 23 is 1 and of 8 is 3.
c. Display the contents of SLL in reverse order.
d. Display identify second largest number in SLL (Do not sort the link list).
4) Write a program to design a library management application using linked list which will
maintain a record of all the books available in the library including (Book name, author,
ISBN, publication year, no of copies available etc.). There is another list containing the
name of the issued books and the name of student, to whom the book is issued. Provide
menu which will contain options to add, delete, display and update the entry in the
records.
5) Write a program to create another single link list (SLL1) having elements as 24, 6, 7, 8, 1,
2, 8, 10, 4, 27, 16, 26. Later, write a program to sort LL2 (retain all the duplicate
elements). Call this list as SLL2. Finally merge SLL2 with SLL1 such that elements of
merged linked list will be in sorted order (retaining all the duplicate elements).
6) Write a program to find sum of all elements of linked list created in Q1 and Q2 above
separately. Write a function to perform following operations: If (sum of all elements of
first LL - sum of all elements of second LL) > last element of first LL then start deleting
last elements of first LL until (remaining elements of first LL - sum of all elements of
second LL) ≈ 0. Otherwise delete elements of first LL from beginning until (remaining
elements of first LL - sum of all elements of second LL) ≈ 0.
7) Write a RemoveDuplicates() function which takes a list sorted in increasing order and
deletes any duplicate nodes from the list.
Week - 2 (15-Jan to 20-Jan) : Lab -Assignment (Practice Assignment)
1) Write a recursive function to sort (in ascending order) the values in a doubly linked list
2) Write a function to mask the values in a circular linked list in the following manner,
a. First node and last node should be retained as it is.
b. In between the first and last node, there should be just five nodes containing ‘*’
value in it. (Irrespective of the number of nodes between first and last node in the
original linked list)
3) Write a program that read numbers from a file and pushes them into stack until we read a
negative no. At this time, we stop reading and pop five items from the stack and print them.
If there are fewer than five items in the stack, print the error message. After printing data
resume reading data and placing them in the stack. When the end of file is detected, print a
message and item remaining in the stack.
4) Write a program to reverse the stack using recursion.
5) Using a queue data structure, implement the concept of a stack
6) Given a queue Q1, shuffle the values stored in first half of queue with the second half of it in
an alternate manner (Recursive function).
For example, (LHS is front of queue and RHS as rear of queue)
Case-1: Q1 : 1 2 3 4 5 6
Output Q2: 1 5 3 4 2 6
Case-2: Q1: 1 2 3 4 5
Output Q2: 1 4 3 2 5
7) Write the function that changes the input stack so that all appearances of the smallest element
are at the bottom of the stack, while the order of the other elements remains the same. The
prototype of the function is:
void changeStack (Stack *stack);
Example:
After the execution of the function the input stack (the top is the leftmost element)
3, 2, 4, 5, 8, 2, 4 is changed into 3, 4, 5, 8, 4, 2, 2
1) The standard use of multi-linked lists is to organize a collection of elements in two different
ways. For example, suppose the elements in node include the name of a person and his/her
age. e.g.
There is need to order these elements alphabetically and also to order them by age. There will
be need for two pointers - NEXT-alphabetically, NEXT-age - and the list header would have
two pointers, one based on name, the other on age [as shown in figure below].
Implement the following operations,
a) Insertion of new nodes in the multilinked list such that the list is sorted after
insertion
b) Deletion of a node from the multilinked list based on the user inputted age/name
c) Display the multilinked list
2) Given a linked list where in addition to the next pointer, each node has a child pointer,
which may or may not point to a separate list. These child lists may have one or more
children of their own, and so on, to produce a multilevel data structure, as shown in
below figure. You are given the head of the first level of the list. Flatten the list so that all
the nodes appear in a single-level linked list. Write the program to flatten the list in way
that all nodes at first level should come first, then nodes of second level, and so on. Each
node is a C struct with the following definition.
struct list
{
int data;
struct list *next;
struct list *child; };
It should then loop through the list, prompting the user to enter the scores for each student.
The scores’ prompt should include the name of the student. After all scores have been
entered, the program should print the scores for each student along with the scoretotal and
avg. The average should include only those scores present.
Topics: Linked list, Circular linked list, Doubly linked list, MultiLinked List, Stack and Queue
1. Construct a binary tree from its level order and in-order traversal.
2. In a binary search tree, write a function to checks if the sum of all the nodes in left sub
tree of the node is equal or greater or lesser than the sum of all the nodes in right sub tree
of the node.
3. Write a function to compute the height of a AVL tree rooted at a node N.
4. Write a function to merge the two given AVL Trees into a single AVL Tree.
5. Write a function to delete all the nodes in both the left and right sub-trees of a given node
N in an AVL Tree.
6. Suppose a particular node in an AVL Tree has to be updated with a new value which may
lead to violation of the AVL Tree properties. Write a function to restore the properties of
the updated AVL Tree
1. Write a program to construct a Red-Black Tree and perform the following operations on the
Red-Black Tree,
a. IsRBTree() – to check whether the constructed RB Tree satisfies all its properties
b. Delete() – to delete the specified node from the RB Tree
2. Implement max-heap and perform insertion and deletion Operations.
a. Insert the element
b. Delete the element
c. Display all elements
3. Write a program to construct priority queue using heap. Print the final contents of the priority
queue.
4. Write a program to perform Heapsort and compute the number of comparisons that is
required to perform this.
5. Write a program for deleting an arbitrary element form min heap.
6. Using heap data structure, design an algorithm to identify 100 biggest numbers out of given
100000000 elements.
7. It is desired to identify all numbers between 100th biggest numbers and 400th biggest numbers
out of given 100000000 elements. Use Heap data structure and identify the 300 numbers in
the given range.
1. Write a program to construct a B-Tree based on the user defined minimal degree-‘t’ and
perform the following operations on the B-Tree,
a. To delete an element from a B-Tree
b. To search for an element in a B-Tree
c. To print the elements in level order
2. Write a program to construct priority queue using heap. Print the final contents of the
priority queue.
3. Write a program to store the graph data structure on an adjacency list and perform the
following operations,
a. To traverse the graph in depth-first search (DFS) manner
b. To traverse the graph in breadth-first search (BFS) manner
c. To check whether given two graphs are isomorphic or not
d. To find the Hamiltonian path for the given graph
e. To find the shortest path using Dijkstra algorithm
f. To find the minimum spanning tree of the given graph using Kruskal’s algorithm