DAA Using Java Lab
DAA Using Java Lab
02
03
04
05
if (arr[l] == x)
return l;
if (arr[r] == x)
return r;
if (index != -1)
System.out.println("Element " + x + " is present at index " + index);
else
System.out.println("Element " + x + " is not present");
}
}
OUTPUT 1 :-
Element 3 is present at index 3
OUTPUT 2 :-
Element 3 is not present
ORDER OF GROWTH :-
ALGORITHM :-
LinearSearch (array, index, key):
if index < 0:
return -1;
if item = key:
return index
return LinearSearch (array, index-1, key)
Program No.6 :- Write a Java Program to Find Minimum and Maximum of Element in
an array using Recursively
ALGORITHM :-
ALGORITHM :-
PROCEDURE FIBONACCI(NUMBER)
IF NUMBER <= 1 THEN
RETURN NUMBER
ELSE
RETURN FIBONACCI(NUMBER - 1) + FIBONACCI(NUMBER - 2)
END IF
END PROCEDURE
Program No.8 :- Write a Java Program to implement Fibonacci Series using Non-
Recursively
ALGORITHM :-
FUNCTION Fibonacci(N):
num1 = 0
num2 = 1
FOR i FROM 0 TO N-1:
OUTPUT num1
num3 = num2 + num1
num1 = num2
num2 = num3
Program No.9 :- Write a Java Program to implement Tower Of Hanoi using
Recursively
ALGORITHM :-