Skip to content

Commit

Permalink
added new java project
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshcusat committed Nov 21, 2011
1 parent 8a57c03 commit ce0c757
Show file tree
Hide file tree
Showing 15 changed files with 648 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Algorithm/Java/InterviewTest/.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/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions Algorithm/Java/InterviewTest/.project
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 Algorithm/Java/InterviewTest/.settings/org.eclipse.jdt.core.prefs
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
31 changes: 31 additions & 0 deletions Algorithm/Java/InterviewTest/src/MainTest.java
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>();


}
}
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 Algorithm/Java/InterviewTest/src/com/search/MatrixSearch.java
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 Algorithm/Java/InterviewTest/src/com/stringtest/StringPermute.java
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 Algorithm/Java/InterviewTest/src/com/stringtest/StringSearch.java
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 Algorithm/Java/InterviewTest/src/com/test/BinarySearchTree.java
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;
}



}
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);
}
}
Loading

0 comments on commit ce0c757

Please sign in to comment.