Professional Documents
Culture Documents
Programs Based ON Recurssions
Programs Based ON Recurssions
Page No.:
PROGRAMS
BASED
ON
RECURSSIONS
RECURSSION BASED PROGRAMS
Page No.:
array.
STEP 1 : Start
member functions.
lmt nn
l 0
u lmt - 1
for i 0 to less than 100 step value 1
a[i] 0
End of parametrized constructor.
End of readdata( ) .
if l <= v
if a[mid] == v
return (mid + 1)
l mid + 1
return binary_search( v )
else
u mid - 1;
return binary_search(v)
end of else if else
else
return -1;
End of binary_search( v )
STEP 9 : if p != -1
else
STEP 11 : End.
RECURSSION BASED PROGRAMS
Page No.:
import java.io.*;
class Rebinary // declaring the class
{
private int a[] = new int[100], lmt,l,u;
// declaring the data members
Rebinary(int nn) // parametrized constructor
{
lmt = nn;
l = 0; //initializing the data members.
u = lmt - 1;
{
a[i] = 0;
}
}
void readdata()throws IOException
// function to accept the elements from the user
{
USAGE OF THE
VARIABLE : DATA TYPE :
VARIABLE:
r Rebinary Encapsulation.
a[] int To store the elements.
To store the size of
lmt int
the array.
To store the index of
u int the topmost element
of the array.
To store the index of
l int the lowermost element
of the array.
Used as a counter
i int
variable.
To store the index of
mid cell between the
mid int
cells represented by u
and l.
To accept the value of
limit in the
parameterized
nn int
constructor and then
pass its value to
variable lmt.
To store the number
k int
to be searched.
To accept the size of
n int array as per users
choice.
To store the position
p int of the searched
element else stores -1.