DSA HU Assig..
DSA HU Assig..
I, Individual assignment
Q. Find a recursive algorithm equivalent and it’s output for the following iterative algorithm with
necessary comments for every statement.
#include <stdio.h>
else {
low = mid + 1;
}
}
return -1;
}
int main(void)
{
int nums[] = { 2, 5, 6, 8, 9, 10 };
int target = 5;
int n = sizeof(nums)/sizeof(nums[0]);
int index = binarySearch(nums, n, target);
if (index != -1) {
printf("Element found at index %d", index);
}
else {
printf("Element not found in the array");
}
return 0;
}
II, Group assignment
Q. Write a program to solve the Tower of Hanoi problem with 6,7,8 and 9 discs. The
objective is to move all the discs from the first tower to the third tower while following
three rules:
Your program should output a sequence of moves that will solve the Tower of Hanoi
problem for each given number of discs (6,7, 8 and 9) by moving the discs from the
source tower to the destination tower. Each move should be represented as a pair of
tower numbers, where the first number is the source tower and the second number is
the destination tower.
For example, if you are solving the Tower of Hanoi problem for 5 discs, the output
should be a sequence of moves like this: (1, 3), (1, 2), (3, 2), (1, 3), (2, 1), (2, 3), (1,
3), ... (where (1, 3) represents moving a disc from tower 1 to tower 3).
Remember to implement the solution algorithmically, taking into account the three
rules mentioned above.
Submit your program code along with the output sequence of moves for each
number of discs.