Skip to content
Open

Hi #24

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
999ce9c
Create sortAsc.java
gowtham2003ss Oct 20, 2022
1678463
Merge pull request #2 from gowtham2003ss/patch-1
Mathwog2003 Oct 20, 2022
2215590
Update and rename Readme.md to README.md
Mathwog2003 Oct 20, 2022
78cfb59
Update README.md
Mathwog2003 Oct 20, 2022
7f8caa9
Create AvoidDeadLock.java
gowtham2003ss Oct 20, 2022
f7dcc8e
Merge pull request #3 from gowtham2003ss/patch-2
Mathwog2003 Oct 20, 2022
e06f761
Update README.md
Mathwog2003 Oct 20, 2022
b396a29
Update README.md
Mathwog2003 Oct 20, 2022
6e6ade6
Add files via upload
gowtham2003ss Oct 23, 2022
5acbbec
Merge pull request #5 from gowtham2003ss/master
Mathwog2003 Oct 23, 2022
fedf976
Create Binary_search.py
ragupathi09 Oct 23, 2022
41ca1dd
adding a anagramcheck.java program
Mathwog2003 Oct 26, 2022
5c38f87
added a quicksort java program
Feroz1522 Oct 27, 2022
4383bca
Merge pull request #7 from Feroz1522/master
Mathwog2003 Oct 27, 2022
69281d5
Update README.md
Mathwog2003 Oct 27, 2022
2328092
Update README.md
Mathwog2003 Oct 27, 2022
8273446
Merge branch 'Mathwog2003:master' into master
ragupathi09 Oct 27, 2022
d4e1bdd
Delete Binary_search.py
ragupathi09 Oct 27, 2022
8fc7743
Create Binary_search.java
ragupathi09 Oct 27, 2022
2e86df0
Create shortest_path.java
ragupathi09 Oct 27, 2022
5cecb06
Merge pull request #6 from ragupathi09/master
Mathwog2003 Oct 27, 2022
c9746bd
Update README.md
Mathwog2003 Oct 28, 2022
acb1ecb
Stooge sort in JAVA
LOCODAK Oct 28, 2022
12be2db
Add files via upload
hemavimalagithub Oct 28, 2022
420198a
Merge pull request #9 from hemavimalagithub/master
Mathwog2003 Oct 28, 2022
56d0c25
Add files via upload
hemavimalagithub Oct 28, 2022
f35cc5a
Subarray.java
Eziox69 Oct 28, 2022
98f3be1
BFS in Java is created !!
Shivika-113 Oct 28, 2022
d881ba1
Merge pull request #12 from hemavimalagithub/master
Mathwog2003 Oct 28, 2022
f1642e6
Merge pull request #11 from Shivika-113/patch-1
Mathwog2003 Oct 28, 2022
4dfc8e8
Add files via upload
hemavimalagithub Oct 28, 2022
6d960ef
Merge pull request #10 from Eziox69/patch-1
Mathwog2003 Oct 28, 2022
db443a2
Merge pull request #13 from hemavimalagithub/master
Mathwog2003 Oct 28, 2022
1bdae70
Merge pull request #8 from LOCODAK/master
Mathwog2003 Oct 28, 2022
f56037d
Rename Txt.java to Test.java
Mathwog2003 Oct 28, 2022
cd4d2bf
Add files via upload
hemavimalagithub Oct 28, 2022
8785685
Add files via upload
hemavimalagithub Oct 28, 2022
b4d6248
Add files via upload
hemavimalagithub Oct 28, 2022
1538418
Merge pull request #14 from hemavimalagithub/master
Mathwog2003 Oct 28, 2022
b7d3c3b
Java prgrm for DFS is added
ShevvyCS1903 Oct 28, 2022
82d80b8
Merge pull request #15 from ShevvyCS1903/patch-1
Mathwog2003 Oct 28, 2022
9f80261
Add files via upload
Feroz1522 Oct 30, 2022
0fd1446
Merge pull request #16 from Feroz1522/master
Mathwog2003 Oct 30, 2022
8f88e66
Create BucketSort.java
djashan Oct 30, 2022
d2ce8b3
Merge pull request #17 from djashan/master
Mathwog2003 Oct 30, 2022
c7d20a6
Create reverse.java
prajspiben1 Oct 30, 2022
17a70c4
Merge pull request #18 from prajspiben1/master
Mathwog2003 Oct 31, 2022
9672b6d
Add files via upload
Feroz1522 Oct 31, 2022
07dcd41
Merge pull request #23 from Feroz1522/master
Mathwog2003 Nov 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Algorithm/BFS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import java.util.*;


class Main
{
private int V; // No. of vertices
private LinkedList<Integer> adj[]; //Adjacency Lists

// Constructor
Graph(int v)
{
V = v;
adj = new LinkedList[v];
for (int i=0; i<v; ++i)
adj[i] = new LinkedList();
}


void addEdge(int v,int w)
{
adj[v].add(w);
}

// prints BFS traversal from a given source s
void BFS(int s)
{
boolean visited[] = new boolean[V];

// Create a queue for BFS
LinkedList<Integer> queue = new LinkedList<Integer>();

// Mark the current node as visited and enqueue it
visited[s]=true;
queue.add(s);

while (queue.size() != 0)
{
// Dequeue a vertex from queue and print it
s = queue.poll();
System.out.print(s+" ");

Iterator<Integer> i = adj[s].listIterator();
while (i.hasNext())
{
int n = i.next();
if (!visited[n])
{
visited[n] = true;
queue.add(n);
}
}
}
}

public static void main(String args[])
{
Graph g = new Graph(4);

g.addEdge(0, 1);
g.addEdge(0, 2);
g.addEdge(1, 2);
g.addEdge(2, 0);
g.addEdge(2, 3);
g.addEdge(3, 3);

System.out.println("Following is Breadth First Traversal "+
"(starting from vertex 2)");

g.BFS(2);
}
}

35 changes: 35 additions & 0 deletions Algorithm/Binary_search.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.util.*;
class Main{
public static void main(String args[]){
int numArray[] = {5,10,15,20,25,30,35};
System.out.println("The input array: " + Arrays.toString(numArray));
//key to be searched
int key = 20;
System.out.println("\nKey to be searched=" + key);
//set first to first index
int first = 0;
//set last to last elements in array
int last=numArray.length-1;
//calculate mid of the array
int mid = (first + last)/2;
//while first and last do not overlap
while( first <= last ){
//if the mid < key, then key to be searched is in the first half of array
if ( numArray[mid] < key ){
first = mid + 1;
}else if ( numArray[mid] == key ){
//if key = element at mid, then print the location
System.out.println("Element is found at index: " + mid);
break;
}else{
//the key is to be searched in the second half of the array
last = mid - 1;
}
mid = (first + last)/2;
}
//if first and last overlap, then key is not present in the array
if ( first > last ){
System.out.println("Element is not found!");
}
}
}
90 changes: 90 additions & 0 deletions Algorithm/dfs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import java.util.*;

public class Main
{

static class Graph
{
int V; //Number of Vertices

LinkedList<Integer>[] adj; // adjacency lists

//Constructor
Graph(int V)
{
this.V = V;
adj = new LinkedList[V];

for (int i = 0; i < adj.length; i++)
adj[i] = new LinkedList<Integer>();

}

//To add an edge to graph
void addEdge(int v, int w)
{
adj[v].add(w); // Add w to v’s list.
}

// prints all not yet visited vertices reachable from s
void DFS(int s)
{
// Initially mark all vertices as not visited
Vector<Boolean> visited = new Vector<Boolean>(V);
for (int i = 0; i < V; i++)
visited.add(false);

// Create a stack for DFS
Stack<Integer> stack = new Stack<>();

// Push the current source node
stack.push(s);

while(stack.empty() == false)
{
// Pop a vertex from stack and print it
s = stack.peek();
stack.pop();

// Stack may contain same vertex twice. So
// we need to print the popped item only
// if it is not visited.
if(visited.get(s) == false)
{
System.out.print(s + " ");
visited.set(s, true);
}

// Get all adjacent vertices of the popped vertex s
// If a adjacent has not been visited, then push it
// to the stack.
Iterator<Integer> itr = adj[s].iterator();

while (itr.hasNext())
{
int v = itr.next();
if(!visited.get(v))
stack.push(v);
}

}
}
}


public static void main(String[] args)
{
// Total 5 vertices in graph
Graph g = new Graph(5);

g.addEdge(1, 0);
g.addEdge(0, 2);
g.addEdge(2, 1);
g.addEdge(0, 3);
g.addEdge(1, 4);

System.out.println("Following is the Depth First Traversal");
g.DFS(0);
}
}

97 changes: 97 additions & 0 deletions Algorithm/shortest_path.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// A Java program for Dijkstra's single source shortest path algorithm.
// The program is for adjacency matrix representation of the graph
import java.util.*;
import java.lang.*;
import java.io.*;

class ShortestPath {
// A utility function to find the vertex with minimum distance value,
// from the set of vertices not yet included in shortest path tree
static final int V = 9;
int minDistance(int dist[], Boolean sptSet[])
{
// Initialize min value
int min = Integer.MAX_VALUE, min_index = -1;

for (int v = 0; v < V; v++)
if (sptSet[v] == false && dist[v] <= min) {
min = dist[v];
min_index = v;
}

return min_index;
}

// A utility function to print the constructed distance array
void printSolution(int dist[], int n)
{
System.out.println("Vertex Distance from Source");
for (int i = 0; i < V; i++)
System.out.println(i + " tt " + dist[i]);
}

// Function that implements Dijkstra's single source shortest path
// algorithm for a graph represented using adjacency matrix
// representation
void dijkstra(int graph[][], int src)
{
int dist[] = new int[V]; // The output array. dist[i] will hold
// the shortest distance from src to i

// sptSet[i] will true if vertex i is included in shortest
// path tree or shortest distance from src to i is finalized
Boolean sptSet[] = new Boolean[V];

// Initialize all distances as INFINITE and stpSet[] as false
for (int i = 0; i < V; i++) {
dist[i] = Integer.MAX_VALUE;
sptSet[i] = false;
}

// Distance of source vertex from itself is always 0
dist[src] = 0;

// Find shortest path for all vertices
for (int count = 0; count < V - 1; count++) {
// Pick the minimum distance vertex from the set of vertices
// not yet processed. u is always equal to src in first
// iteration.
int u = minDistance(dist, sptSet);

// Mark the picked vertex as processed
sptSet[u] = true;

// Update dist value of the adjacent vertices of the
// picked vertex.
for (int v = 0; v < V; v++)

// Update dist[v] only if is not in sptSet, there is an
// edge from u to v, and total weight of path from src to
// v through u is smaller than current value of dist[v]
if (!sptSet[v] && graph[u][v] != 0 &&
dist[u] != Integer.MAX_VALUE && dist[u] + graph[u][v] < dist[v])
dist[v] = dist[u] + graph[u][v];
}

// print the constructed distance array
printSolution(dist, V);
}

// Driver method
public static void main(String[] args)
{
/* Let us create the example graph discussed above */
int graph[][] = new int[][] { { 0, 4, 0, 0, 0, 0, 0, 8, 0 },
{ 4, 0, 8, 0, 0, 0, 0, 11, 0 },
{ 0, 8, 0, 7, 0, 4, 0, 0, 2 },
{ 0, 0, 7, 0, 9, 14, 0, 0, 0 },
{ 0, 0, 0, 9, 0, 10, 0, 0, 0 },
{ 0, 0, 4, 14, 10, 0, 2, 0, 0 },
{ 0, 0, 0, 0, 0, 2, 0, 1, 6 },
{ 8, 11, 0, 0, 0, 0, 1, 0, 7 },
{ 0, 0, 2, 0, 0, 0, 6, 7, 0 } };
ShortestPath t = new ShortestPath();
t.dijkstra(graph, 0);
}
}
// This code is contributed by Aakash Hasija
67 changes: 67 additions & 0 deletions AnagramCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import java.util.Arrays;

/**
* Java program - String Anagram Example.
* This program checks if two Strings are anagrams or not
*
* @author Javin Paul
*/
public class AnagramCheck {

/*
* One way to find if two Strings are anagram in Java. This method
* assumes both arguments are not null and in lowercase.
*
* @return true, if both String are anagram
*/
public static boolean isAnagram(String word, String anagram){
if(word.length() != anagram.length()){
return false;
}

char[] chars = word.toCharArray();

for(char c : chars){
int index = anagram.indexOf(c);
if(index != -1){
anagram = anagram.substring(0,index)
+ anagram.substring(index +1, anagram.length());
}else{
return false;
}
}

return anagram.isEmpty();
}

/*
* Another way to check if two Strings are anagram or not in Java
* This method assumes that both word and anagram are not null and lowercase
* @return true, if both Strings are anagram.
*/
public static boolean iAnagram(String word, String anagram){
char[] charFromWord = word.toCharArray();
char[] charFromAnagram = anagram.toCharArray();
Arrays.sort(charFromWord);
Arrays.sort(charFromAnagram);

return Arrays.equals(charFromWord, charFromAnagram);
}


public static boolean checkAnagram(String first, String second){
char[] characters = first.toCharArray();
StringBuilder sbSecond = new StringBuilder(second);

for(char ch : characters){
int index = sbSecond.indexOf("" + ch);
if(index != -1){
sbSecond.deleteCharAt(index);
}else{
return false;
}
}

return sbSecond.length()==0 ? true : false;
}
}
Loading