-
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
0a271a8
commit 2d2b340
Showing
21 changed files
with
982 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="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="src" path="src"/> | ||
<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>Alogoritham_DataStructure</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=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
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.8 |
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,45 @@ | ||
package com.akash.circular; | ||
|
||
public class CircularOrNot { | ||
|
||
public static void main(String[] args) { | ||
// TODO | ||
|
||
String path = "GLGLGLG"; | ||
|
||
char chPath[] = path.toCharArray(); | ||
|
||
if(isCircularPath(chPath)) | ||
System.out.println("Given Sequence "+ " of moves is circular"); | ||
else | ||
System.out.println("Given Sequence "+ " of moves is not circular"); | ||
} | ||
|
||
private static boolean isCircularPath(char[] chPath) { | ||
// TODO | ||
|
||
int x=0; int y=0; | ||
int dir = 0; | ||
|
||
for(int i = 0; i<chPath.length; i++) { | ||
char move = chPath[i]; | ||
if(move == 'R') { | ||
dir = (dir+1)%4; | ||
}else if (move == 'L') { | ||
dir = (4+dir-1)%4; | ||
}else { | ||
if(dir==0) { | ||
y++; | ||
}else if(dir==1) { | ||
x++; | ||
}else if(dir==2) { | ||
y--; | ||
}else { | ||
x--; | ||
} | ||
} | ||
} | ||
return (x==0 && y==0); | ||
} | ||
|
||
} |
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,44 @@ | ||
package com.akash.hashTable; | ||
|
||
import java.util.LinkedList; | ||
|
||
public class HashTableDemo { | ||
|
||
private LinkedList[] data; | ||
|
||
public HashTableDemo(int size) { | ||
// TODO | ||
this.data = new LinkedList[size]; | ||
for(int i = 0; i<size; i++) { | ||
this.data[i] = new LinkedList<>(); | ||
} | ||
} | ||
|
||
/*public void insert(String value) { | ||
int index = Math.abs(hashFunction(value)) % data.length; | ||
this.data[index].insert(value); | ||
} | ||
public boolean delete(String value) { | ||
int index = Math.abs(hashFunction(value)) % data.length; | ||
return data[index].delete(value); | ||
} | ||
public boolean search(String value) { | ||
int index = Math.abs(hashFunction(value)) % data.length; | ||
return data[index].search(value); | ||
} | ||
*/ | ||
private int hashFunction(String value) { | ||
// TODO | ||
int hash = 7; | ||
for(char c : value.toCharArray()) { | ||
hash = hash*31+c; | ||
} | ||
return hash; | ||
} | ||
|
||
|
||
|
||
|
||
} |
58 changes: 58 additions & 0 deletions
58
Alogoritham/src/com/akash/largestPrime/LargestPrimeNumber.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,58 @@ | ||
package com.akash.largestPrime; | ||
|
||
public class LargestPrimeNumber { | ||
|
||
public static void main(String[] args) { | ||
// TODO | ||
String str = "1000"; | ||
StringBuilder sb = new StringBuilder(str); | ||
System.out.println(largestPrimeNumber(sb)); | ||
|
||
} | ||
|
||
private static String largestPrimeNumber(StringBuilder sb) { | ||
// TODO | ||
for(int i = 0; i<sb.length(); i++) { | ||
|
||
if (!isPrime(sb.charAt(i))) { | ||
while(i>=0 && sb.charAt(i) <= '2') | ||
i--; | ||
if(i<0) { | ||
i=0; | ||
decreaseNum(sb, i); | ||
} | ||
else | ||
decreaseNum(sb, i); | ||
|
||
for(int j = i+1; j<sb.length(); j++) | ||
sb.setCharAt(j, '7'); | ||
break; | ||
} | ||
|
||
} | ||
return sb.toString(); | ||
} | ||
|
||
private static void decreaseNum(StringBuilder sb, int i) { | ||
// TODO | ||
if(sb.charAt(i)<='2') { | ||
sb.deleteCharAt(i); | ||
sb.setCharAt(i, '7'); | ||
}else if(sb.charAt(i)=='3') { | ||
sb.setCharAt(i, '2'); | ||
}else if(sb.charAt(i) <= '5') { | ||
sb.setCharAt(i, '3'); | ||
}else if(sb.charAt(i)<= '7') { | ||
sb.setCharAt(i, '5'); | ||
}else { | ||
sb.setCharAt(i, '7'); | ||
} | ||
return; | ||
} | ||
|
||
private static boolean isPrime(char c) { | ||
// TODO | ||
return (c=='2' || c=='3' || c=='5' || c=='7'); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
Alogoritham/src/com/akash/largestSumGivenDigit/FindLargestGivenSum.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,41 @@ | ||
package com.akash.largestSumGivenDigit; | ||
|
||
public class FindLargestGivenSum { | ||
|
||
public static void main(String[] args) { | ||
|
||
int num = 9, n =2; | ||
findLargestSum(num, n); | ||
} | ||
|
||
private static void findLargestSum(int num, int n) { | ||
// TODO | ||
|
||
if(num == 0) { | ||
System.out.print( n==1 ? "Largest Num is 0 ": "Not Possible"); | ||
return; | ||
} | ||
|
||
if(num > 9*n) { | ||
System.out.println("Not Possible"); | ||
return; | ||
} | ||
|
||
int res[] = new int[n]; | ||
|
||
for(int i =0; i<n; i++) { | ||
if(num>=9) { | ||
res[i] = 9; | ||
num = num-9; | ||
}else { | ||
res[i] = num; | ||
num = 0; | ||
} | ||
} | ||
|
||
System.out.print("largest Number : "); | ||
for(int i = 0; i<n; i++) { | ||
System.out.print(res[i]); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Alogoritham/src/com/akash/largesttriangle/LargestAreaTriangleAlgo.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,28 @@ | ||
package com.akash.largesttriangle; | ||
|
||
public class LargestAreaTriangleAlgo { | ||
|
||
public static void main(String[] args) { | ||
|
||
int points[][] = {{0,0},{0,1},{1,0},{0,2},{2,0}}; | ||
|
||
double result = LargestTriangleArea(points); | ||
System.out.println(result); | ||
} | ||
|
||
private static double LargestTriangleArea(int[][] points) { | ||
// TODO | ||
|
||
double res = -1; | ||
|
||
for(int [] x : points) { | ||
for(int [] y : points) { | ||
for(int [] z : points) { | ||
double temp = 0.5*Math.abs(x[0]*(y[1]-z[1])+y[0]*(z[1]-x[1])+z[0]*(x[1]-y[1])); | ||
res = Math.max(res, temp); | ||
} | ||
} | ||
} | ||
return res; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
Alogoritham/src/com/akash/matrixsprial/SprialMatrixDemo.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,72 @@ | ||
package com.akash.matrixsprial; | ||
|
||
import java.util.Arrays; | ||
|
||
public class SprialMatrixDemo { | ||
|
||
private static final int m = 5; | ||
private static final int n = 5; | ||
|
||
public static void main(String[] args) { | ||
// TODO | ||
|
||
int arr[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, | ||
16,17,18,19,20,21,22,23,24,25}; | ||
|
||
int[][] mat = new int[m][n]; | ||
printsprialMatrixOrder(arr, mat); | ||
|
||
for(int[] v : mat) { | ||
System.out.println(Arrays.toString(v)); | ||
} | ||
|
||
} | ||
|
||
private static void printsprialMatrixOrder(int[] arr, int[][] mat) { | ||
// TODO | ||
|
||
int top = 0, bottom = m-1; | ||
int left = 0, right = n-1; | ||
|
||
int index = 0; | ||
|
||
while(true) { | ||
if(left>right) { | ||
break; | ||
} | ||
|
||
for(int i = left; i<=right; i++) { | ||
mat[top][i]=arr[index++]; | ||
} | ||
top++; | ||
|
||
if(top>bottom) { | ||
break; | ||
} | ||
|
||
for(int i = top; i<=bottom; i++) { | ||
mat[i][right] = arr[index++]; | ||
} | ||
right--; | ||
|
||
|
||
if(left>right) { | ||
break; | ||
} | ||
for(int i= right; i>=left; i--) { | ||
mat[bottom][i] = arr[index++]; | ||
} | ||
bottom--; | ||
|
||
if(top>bottom) { | ||
break; | ||
} | ||
|
||
for(int i= bottom; i>=top; i--) { | ||
mat[i][left] = arr[index++]; | ||
} | ||
left++; | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.