Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Searching in java/binarysearch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.util.*;
public class binarysearch {
public static int bin(int numbers[],int key){
int start=0,end = numbers.length-1;

while(start<=end){
int mid=(start+end)/2;
if(numbers[mid]==key){
return mid;
}
if(numbers[mid]<key){
start=mid+1;
}
else{
end=mid-1;
}
}
return -1;
}
public static void main(String args[]){
int numbers[] = {1,2,6,3,5};
int key=6;
System.out.println("nu is largest : " + bin(numbers,key));
}
}
21 changes: 21 additions & 0 deletions Searching in java/linearsearch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class linearsearch {
public static int linea(int numbers[],int key){
for(int i =0;i<numbers.length;i++){
if(numbers[i]==key){
return i;
}
}
return -1;
}
public static void main(String args[]){
int numbers[]={2,4,6,8,10,12,14,16};
int key=10;
int index=linea(numbers,key);
if(index==-1){
System.out.print("not");
}
else{
System.out.print("key is at index " + index);
}
}
}