forked from rakeshcusat/Code4Reference
-
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
1 parent
8a57c03
commit ce0c757
Showing
15 changed files
with
648 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/JavaSE-1.6"/> | ||
<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>InterviewTest</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> |
12 changes: 12 additions & 0 deletions
12
Algorithm/Java/InterviewTest/.settings/org.eclipse.jdt.core.prefs
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,12 @@ | ||
#Thu Nov 17 17:03:56 EST 2011 | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.6 | ||
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=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.6 |
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,31 @@ | ||
import java.util.HashMap; | ||
|
||
|
||
|
||
|
||
|
||
public class MainTest { | ||
|
||
/** | ||
* @param args | ||
*/ | ||
public static void main(String[] args) { | ||
|
||
// TrieTree tt=new TrieTree(); | ||
// tt.insertWord("rakesh"); | ||
// System.out.println("----------------------"); | ||
// tt.insertWord("rajesh"); | ||
// | ||
// if(tt.searchWord("rakesm")){ | ||
// System.out.println("Word is present"); | ||
// }else{ | ||
// System.out.println("Word is not present in the trie "); | ||
// } | ||
// | ||
// tt.printSuggestedWord("rak"); | ||
|
||
HashMap<Integer, String> hashmap=new HashMap<Integer, String>(); | ||
|
||
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
Algorithm/Java/InterviewTest/src/com/recursion/MatchingParentheses.java
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,36 @@ | ||
package com.recursion; | ||
|
||
public class MatchingParentheses { | ||
|
||
int count; | ||
|
||
public MatchingParentheses(int count){ | ||
this.count = count; | ||
} | ||
|
||
public void printPar(){ | ||
char []str = new char[count*2]; | ||
printPar(count,count,str,0); | ||
} | ||
|
||
private void printPar(int l,int r,char[] str,int count){ | ||
if(l<0 ||l>r){ | ||
return; | ||
} | ||
|
||
if(l==0 && r == 0){ | ||
System.out.println(new String(str)); | ||
return; | ||
} | ||
|
||
if(l > 0){ | ||
str[count]='('; | ||
|
||
printPar(l-1,r,str,count+1); | ||
} | ||
if(r>0){ | ||
str[count]=')'; | ||
printPar(l,r-1,str,count+1); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Algorithm/Java/InterviewTest/src/com/search/MatrixSearch.java
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,32 @@ | ||
package com.search; | ||
|
||
public class MatrixSearch { | ||
|
||
int [][] array; | ||
int m,n; | ||
|
||
public MatrixSearch(int[][] array, int m, int n){ | ||
this.array = array; | ||
this.m = m; | ||
this.n = n; | ||
} | ||
|
||
public boolean seach(int no){ | ||
|
||
int column=n-1; | ||
int row=0; | ||
while(column>=0 && row<n){ | ||
|
||
if(array[row][column]==no){ | ||
System.out.println("row : "+row+", Column : "+column); | ||
return true; | ||
} | ||
if(array[row][column]>no){ | ||
column--; | ||
}else{ | ||
row++; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Algorithm/Java/InterviewTest/src/com/stringtest/StringPermute.java
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 @@ | ||
package com.stringtest; | ||
|
||
public class StringPermute { | ||
String str; | ||
public StringPermute(String str){ | ||
this.str = str; | ||
} | ||
public void permute(){ | ||
int length = str.length(); | ||
boolean[] used = new boolean[length]; | ||
StringBuffer out = new StringBuffer(); | ||
char[] in = str.toCharArray(); | ||
|
||
doPermute(in, out,used,length,0); | ||
} | ||
private void doPermute(char[] in, StringBuffer out, boolean[] used, | ||
int length,int level) { | ||
|
||
if(level==length){ | ||
System.out.println(out.toString()); | ||
return; | ||
} | ||
|
||
for(int index=0;index<length;index++){ | ||
if(used[index]){ | ||
continue; | ||
} | ||
|
||
out.append(in[index]); | ||
used[index]=true; | ||
doPermute(in,out,used,length,level+1); | ||
used[index]=false; | ||
out.setLength(out.length()-1); | ||
} | ||
|
||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Algorithm/Java/InterviewTest/src/com/stringtest/StringSearch.java
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,51 @@ | ||
package com.stringtest; | ||
|
||
public class StringSearch { | ||
|
||
String str; | ||
|
||
public StringSearch(String str){ | ||
this.str =str; | ||
} | ||
|
||
public int rabinKarp(String sub){ | ||
int count =-1; | ||
int hsub = stringHash(sub); | ||
int m = sub.length(); | ||
int n = this.str.length(); | ||
int hs = stringHash(this.str.substring(0,m)); | ||
|
||
for(int index=0;index<n-m-1;index++){ | ||
if(hs==hsub){ | ||
if(this.str.substring(index,index+m).equals(sub)){ | ||
return index; | ||
} | ||
} | ||
|
||
hs=rollingHash(this.str,index,index+m+1,hs); | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
/** | ||
* zero based index. | ||
* @param strarg | ||
* @param start | ||
* @param end | ||
* @param hash | ||
* @return | ||
*/ | ||
private int rollingHash(String strarg,int start,int end,int hash){ | ||
return hash-strarg.charAt(start)+strarg.charAt(end); | ||
} | ||
|
||
private int stringHash(String strarg){ | ||
int hashvalue=0; | ||
|
||
for(int index=0;index<strarg.length();index++){ | ||
hashvalue +=strarg.charAt(index); | ||
} | ||
return hashvalue; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
Algorithm/Java/InterviewTest/src/com/test/BinarySearchTree.java
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,83 @@ | ||
package com.test; | ||
|
||
import java.util.Stack; | ||
|
||
public class BinarySearchTree { | ||
Node root; | ||
|
||
public void makeMinHightTree(Integer[] arr){ | ||
root = makeMinHightTree(arr,0,arr.length-1); | ||
} | ||
/** | ||
* print in-order BST using iterative algorithm | ||
*/ | ||
public void printIterInOrder(){ | ||
Node node = root; | ||
Stack<Node> stack = new Stack<Node>(); | ||
while(!stack.isEmpty() || node != null){ | ||
if(node!=null){ | ||
stack.push(node); | ||
node = node.getLeftNode(); | ||
}else{ | ||
node = stack.pop(); | ||
System.out.print(node); | ||
node = node.getRightNode(); | ||
} | ||
} | ||
} | ||
|
||
public void printIterPreOrder(){ | ||
Stack<Node> stack = new Stack<Node>(); | ||
Node node = root; | ||
stack.push(node); | ||
|
||
while(!stack.isEmpty()){ | ||
node = stack.pop(); | ||
if(node.hasRightNode()){ | ||
stack.push(node.getRightNode()); | ||
} | ||
if(node.hasLeftNode()){ | ||
stack.push(node.getLeftNode()); | ||
} | ||
node.print(); | ||
} | ||
} | ||
|
||
/** | ||
* Prints the Tree in in-order form by recursive method | ||
*/ | ||
public void printRecInOrder(){ | ||
if(root!=null){ | ||
printRecInOrder(root); | ||
} | ||
} | ||
|
||
/** | ||
* internal method for recursively prints binary search tree in In-order form | ||
* @param node | ||
*/ | ||
private void printRecInOrder(Node node){ | ||
if(node!=null){ | ||
printRecInOrder(node.getLeftNode()); | ||
System.out.print(node); | ||
printRecInOrder(node.getRightNode()); | ||
} | ||
|
||
} | ||
|
||
public Node makeMinHightTree(Integer[] arr,int start, int end){ | ||
if(start>end){ | ||
return null; | ||
} | ||
int mid = (start + end)/2; | ||
Node n = new Node(arr[mid]); | ||
|
||
n.setLeftNode(makeMinHightTree(arr, start, mid-1)); | ||
n.setRightNode(makeMinHightTree(arr, mid+1, end)); | ||
|
||
return n; | ||
} | ||
|
||
|
||
|
||
} |
12 changes: 12 additions & 0 deletions
12
Algorithm/Java/InterviewTest/src/com/test/ClassImplMarkerInterface.java
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,12 @@ | ||
package com.test; | ||
|
||
public class ClassImplMarkerInterface implements MarkerInterface{ | ||
String str; | ||
public ClassImplMarkerInterface(String str){ | ||
this.str = str; | ||
} | ||
|
||
public void print(){ | ||
System.out.println(str); | ||
} | ||
} |
Oops, something went wrong.