Dsa Tuto4 1220501
Dsa Tuto4 1220501
• Fibonacci Series
• Linear Search
• Binary Search
• Quick Sort
• Merge Sort
• Tower of Hanoi
• Tree Traversals
• Graph Traversals
The recursive call is the last operation within the Some operations occur after the recursive call.
function and there’s no other work to do after the The function needs to perform additional
recursive call. It can directly return the result of operations using the returned value from the
the recursive call. recursive call before it can return its result.
A function calls itself directly in its own A method calls themselves indirectly
body. through calling other method and involves
at least two functions.
6. Provide an example (must not be from the lecture notes) of a nested recursion.
printNumberLine(i); }
}
7. Provide an example (must not be from the lecture notes) of an excessive recursion.
System.out.println(n);
recursiveMethod(n - 1);
}
private static void excessive(int n) {
if (n <= 0) { return;
}
System.out.println(n);
excessive(n - 1); excessive(n - 1);
}
}
Programming Questions
8. Implement iteration concept using for loop to print “Hi” three times.
public class Iteration { public
static void main(String[] args){
10. For these questions, you need to use recursion and iteration concept.
Node(int data) {
this.data = data;
this.next = null;
}
}
head = null;
for (int i = n - 1; i >= 0; i--) {
push(keys[i]);
}
reverse();
printList(head);
}
}
2. Sum of array elements
import java.util.Scanner;
}
return array[n - 1] + sumOfArray(array, n - 1);
}
scanner.close();
}
}
3. Reverse a stack
import java.util.EmptyStackException;
import java.util.Stack;
reverse();