0% found this document useful (0 votes)
405 views

DS&Algo - Lab Assignment Sheet - New

This lab assignment sheet outlines 6 weeks of assignments on data structures and algorithms. Week 1 includes assignments on arrays, sorting, and linked lists. Week 2 focuses on stacks, queues, and linked lists. Week 3 involves multi-linked lists and tree traversal. Week 4 is an evaluation on linked lists, stacks, and queues. Weeks 5-7 cover sorting algorithms, binary trees, and more linked list problems. Week 8 assigns binary search trees and tree traversal problems.

Uploaded by

Varsha Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
405 views

DS&Algo - Lab Assignment Sheet - New

This lab assignment sheet outlines 6 weeks of assignments on data structures and algorithms. Week 1 includes assignments on arrays, sorting, and linked lists. Week 2 focuses on stacks, queues, and linked lists. Week 3 involves multi-linked lists and tree traversal. Week 4 is an evaluation on linked lists, stacks, and queues. Weeks 5-7 cover sorting algorithms, binary trees, and more linked list problems. Week 8 assigns binary search trees and tree traversal problems.

Uploaded by

Varsha Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Lab Assignment Sheet – Even Sem 2018

Data Structure & Algorithms Laboratory


Week - 1 (08-Jan to 13-Jan) : Lab -Assignment (Practice Assignment)

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

Week - 3 (22-Jan to 27-Jan) : Lab -Assignment (Practice Assignment)

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.

(FRED,19) (MARY,16) (JACK,21) (JILL,18)

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; };

The above list should be converted to 10->5->12->7->11->4->20->13->17->6->2->16->9-


>8->3->19->15
3) Write a program to read a list of students from a file and create a linked list. Each entry in the
linked list should have the student’s name, a pointer to the next pointer, and a pointer to a
linked list of scores. There may be up to 4 scores for each student. The program should
initialize the student list by reading the students’ names from the file and creating null score
lists.

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.

Week - 4 (29-Jan to 03-Feb) : Evaluation-1 (10 Marks)

Topics: Linked list, Circular linked list, Doubly linked list, MultiLinked List, Stack and Queue

Week - 5 (05-Feb to 10-Feb) : Practice Lab

1) Write a program to implement the following variations of Quicksort


a. First element is the pivot element
b. Middle element is the pivot element
c. Select any random element to be the pivot element
For a given array display the number of iterations for each of above variation of
QuickSort.
2) Write a program to implement
(a) Median search
(b) Interpolation search
(c) Shell sort
(d) Merge sort
Week - 6 (13-Feb to 17-Feb) : T1 Examination (No Lab Classes)
---
Week - 7 (19-Feb to 24-Feb) : Practice Lab
1) Write a code to construct doubly linked list and test the code to rectify the error given in
Q2 of T1 paper
void fun (struct node *currNode, struct node *nextNode){
struct node *temp;
if (currNode!=NULL &&nextNode!=NULL){
temp=nextNode->next;
currNode->prev=nextNode;
nextNode->next=currNode;
if(currNode=start)
currNode->next=NULL;
fun(nextNode,temp);
}
start=currNode;
}
void main()
{
//start is point to the first node of DLL
fun (start, start->next);
}
2) Using a multi-linked list, write a code for Q3 in T1 paper
3) You have been given a list of characters as {A, B, C, D, E, F, G, H, and I). Write a program to
insert these elements into a complete binary tree. Also, write the code to perform the following
functionalities on the constructed binary tree,
a. To find a node with specified value
b. To compute height of a given node
c. To compute the depth of a node
d. To check whether the given tree is complete binary tree or not

Week - 8 (26-Feb to 10-Mar) : Practice Lab


1) WAP to implement a Binary Search Tree(BST) for the following elements.
21,26,30,9,4,14,28,18,15,10,2,3,7
a. Write Insert and Delete function for given position.
b. Traverse it Preorder, Postorder, Inorder and Level order iteratively.
2) WAP for finding the Kth smallest elements in BST.
3) Given a binary tree and inorder traversal, construct a new binary tree with additional
pointers such that the inorder traversal is reflected in the new tree. (Hint: Threaded binary
tree).
4) Given a BST, transform it into greater sum tree where each node contains sum of all
nodes greater than that node.
Week - 9 (12-March to 17-March) : Lab Test-1 (20 Marks)
Topics: Linked list, Circular linked list, Doubly linked list, MultiLinked List, Stack, Queue,
Binary Tree and Binary Search Tree

Week - 10 (19-March to 24-March) : Practice Lab

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

Week - 10 (26-March to 31-March) : Practice Lab

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.

Week - 11 (02-Apr to 07-Apr) : T2 Examination (No Lab Classes)


---

Week - 12 (09-Apr to 14-Apr) : Lab Evaluation-2 (15 Marks)

Topics: AVL Tree, Red Black Tree, Heap Tree

Week - 13 (16-Apr to 21-Apr) : Practice Lab

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

Week - 14 (23-Apr to 28-Apr) : Lab Evaluation-3 (15 Marks)

Week - 15 (30-Apr to 05-May) : Lab Test-2

You might also like