Professional Documents
Culture Documents
Name - Lokesh Banthia Class - Xi A Roll Number - 10
Name - Lokesh Banthia Class - Xi A Roll Number - 10
BANTHIA
CLASS – XI A
ROLL NUMBER – 10
COMPUTER PROJECT
LINEAR SEARCH
// return -1
import java.util.*;
class Linear_Search
int n = arr.length;
if(arr[i] == x)
return i;
return -1;
int n = sc.nextInt();
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
int x = sc.nextInt();
if(result == -1)
else
OUTPUT –
1st -
Enter number of terms to be inputed
23
31
17
19
56
61
Enter the number to be searched
2nd –
Enter number of terms to be inputed
15
16
17
181
19
17
import java.util.*;
class Binary_Search
if (r >= l) {
int mid = l + (r - l) / 2;
// middle itself
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
// in right subarray
return binarySearch(arr, mid + 1, r, x);
// in array
return -1;
int n = sc.nextInt();
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
int x = sc.nextInt();
if (result == -1)
else
System.out.println("Element found at index " + result);
OUTPUT –
1ST –
Enter number of terms to be inputed
23
45
43
43
2ND –
Enter number of terms to be inputed
3564
374
2763
72
337
SELECTION SORT
// Java program for implementation of Selection Sort
import java.util.*;
class Selection_Sort
int n = arr.length;
int min_idx = i;
min_idx = j;
// Swap the found minimum element with the first
// element
arr[min_idx] = arr[i];
arr[i] = temp;
int n = arr.length;
System.out.print(arr[i]+" ");
System.out.println();
int n = sc.nextInt();
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
ob.sort(arr);
System.out.println("Sorted array");
ob.printArray(arr);
OUTPUT –
1ST –
Enter number of terms to be inputed
35
43846
35
314
85
Sorted array
2 4 35 35 85 314 43846
2ND –
Enter number of terms to be inputed
35
58
1235
34
567
Sorted array
34 35 58 567 1235
BUBBLE SORT
// Java program for implementation of Bubble Sort
import java.util.*;
class Bubble_Sort
int n = arr.length;
{
// swap temp and arr[i]
arr[j] = arr[j+1];
arr[j+1] = temp;
int n = arr.length;
System.out.println();
int n = sc.nextInt();
arr[i]=sc.nextInt();
ob.bubbleSort(arr);
System.out.println("Sorted array");
ob.printArray(arr);
OUTPUT –
1ST –
Enter number of terms to be inputed
253
252
47
83
47
36
Sorted array
1 36 47 47 83 252 253
2ND –
Enter number of terms to be inputed
13
56
435
768
Sorted array
3 4 13 56 435 768
import java.util.*;
class ISBN_Verification
// length must be 10
int n = isbn.length();
if (n != 10)
return false;
// of first 9 digits
int sum = 0;
return false;
return false;
// Driver code
if (isValidISBN(isbn))
System.out.print("Valid");
else
System.out.print("Invalid");
OUTPUT –
1ST - 2ND –
Enter the ISBN Number Enter the ISBN Number
1681956993 2753738262
Valid Valid
3RD - 4TH-
Enter the ISBN Number Enter the ISBN Number
1232435666 47475759
Invalid Invalid