DSA - I Assignment 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

`CSE 2215 DSA - I

Assignment 1
● Answer all the questions.
● The solutions must be handwritten.
● After the completion of the assignment , assign page numbers to every page.
● Scan every page, attach a cover page (with your name and id) and generate a pdf file
● Submit the assignment in the eLMS portal

SN Problem

1 How does the descending order Merge Sort algorithm work on the following data?
Draw the complete recursive tree.
33 42 12 8 28 102 78

2 Discuss the Drifting Queue Problem with the help of an illustrative example

3 Determine the time complexity of the following algorithm.


sum=0;
for(i=1; i<=n; i++){
for(j=1; j<=i; j++){
sum=sum+i+j;
}
}
printf(“%d”, sum);

4 Answer the following questions for the doubly linked list as shown below, where p =
last two digits of your student id + 5, q = p+3, r = p+q, s = r-1, t = r+s.
5 Consider the following single linked list.

Write the code for a function called insert_before. If you want to insert another Node
before the Node 30 with the value 25 in the given linked list, the function can be called.
The function will take two integers as parameters which in this example will be 30 and
25 respectively. After the function call insert_before(30,25) the condition of the linked
list will be as follows:

6. Write a function insertAtIth that takes in two arguments: an integer i representing the
position (0-based index) and an integer data representing the value of the new node.
The function should insert a new node with the given data at the ith position of a
single linked list. If i is greater than the length of the linked list, append the node at the
end.

Function Signature :
void insertAtIth(int i, int data);

7. Write a function length that returns the length of a single linked list. The function
should traverse the linked list and count the number of nodes.

8. Write a function sum that returns the sum of all the data values in the linked list. The
function should traverse the linked list and accumulate the sum of all the data values.

9. Write a function mergeLinkeList (header1,header2). This function shall take the


headers of two single linked lists as input and append the second linked list at the end
of the first linked list and thus form a one single linked list.

You might also like