Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurjuneja committed Jun 22, 2015
0 parents commit e5c8173
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .classpath
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>
17 changes: 17 additions & 0 deletions .project
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>
11 changes: 11 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
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 added bin/searching/BinarySearch.class
Binary file not shown.
Binary file added bin/searching/binSearch.class
Binary file not shown.
37 changes: 37 additions & 0 deletions src/searching/BinarySearch.java
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));
}

}

0 comments on commit e5c8173

Please sign in to comment.