You are on page 1of 2

Data Structures and Algorithms

Assignment
Make groups of four and answer the following questions accordingly.
Part – I Workout
1. Calculate both the time and space complexity of the following program. Show all the necessary
steps.

int main() {
int num, x, y, sum = 0;
cout << "Enter a positive integer: ";
cin >> num;
for (int i = 1; i <= num; i++) {
sum += i;
}
cout <<sum;
if(num%2 == 0){
x = num * num;
y = num + sum;
cout <<x;
cout <<y;
}
else {
x = num + num;
cout <<x;
}
return 0;
}
2. Given the following array, how does the binary search algorithm work to find element 16
form the array? Show all the necessary steps that binary search algorithm follows.
Array = {2, 3, 5, 6, 7, 10, 11, 12, 14, 15, 16, 18, 19, 20, 21}

3. Given the following unsorted array, how does the Selection, Insertion sort, Heap sort, Quick
sort and Merge sort algorithms work to sort elements. Show all the necessary steps that
selection and insertion sort algorithms follow.
Array = {6, 20, 5, 2, 7, 10, 1, 12, 4, 15, 8, 9, 19, 3, 13, 16}
4. Write the prefix and postfix form of the following infix expression.
(3+5) - (2*6) + ((4+8)/5) -9
5. Delete node 14 from the following binary tree and re-structure the tree.

Part – II Programming
1. Given the following linked list and write a program that

1.1. Create the above linked list


1.2. Display all item of the list
1.3. Search and display Node4
1.4. Create a new node Node6 with value 30
1.5. Insert Node6 at the beginning of the list
1.6. Insert Node6 after Node3
1.7. Delete Node4
1.8. Delete Node5
2. Write a leaner search, binary search, Insertion sort, Bubble sort and Merge sort program.
3. Write a stack program that push and pop items from the stack using array.
4. Write a program that implements a Simple Queue with enqueue and dequeue operation.

You might also like