-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e5c8173
Showing
6 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Interview</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.4 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning | ||
org.eclipse.jdt.core.compiler.source=1.3 |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//Given a sorted array, binary search returns the index of the searched element | ||
//Time complexity: O(logn) | ||
|
||
package searching; | ||
|
||
class binSearch{ | ||
|
||
|
||
//Recursive Binary Search | ||
public int recSearch(int[] arr,int left,int right,int num){ | ||
if(right >= left){ | ||
int mid = (right-1)/2 + 1; | ||
//if element is present at the middle itself | ||
if (arr[mid] == num) | ||
return mid; | ||
|
||
// If element is smaller than mid, then it can only be present | ||
// in left subarray | ||
if(arr[mid] > num) | ||
return recSearch(arr,left,mid-1,num); | ||
//else element can only be present in right subarray | ||
return recSearch(arr,mid+1,right,num); | ||
} | ||
return -1; | ||
|
||
} | ||
} | ||
|
||
public class BinarySearch { | ||
public static void main(String[] args){ | ||
|
||
int[] arr = {10,23,47,51,78}; | ||
binSearch bs = new binSearch(); | ||
System.out.println("index of the element(51) searched is "+ bs.recSearch(arr,0,arr.length,51)); | ||
} | ||
|
||
} |