Code for Random Graph Generation G(n,p) 1

Code for Random Graph Generation G(n,p)
Following is the Java code for generating a Random Graph G(n, p) where ‘n’ is the number of nodes/ vertices in the graph and ‘p’ is the probability that any edge will form or not. The code makes use of JUNG API for graph visualization and creation. More About JUNG… Java import java.awt.Dimension; import javax.swing.JFrame; ...

ConcurrentHashMap 1

ConcurrentHashMap
Javadoc says… “A hash table except supporting full concurrency of retrievals and adjustable expected concurrency for updates. This class obeys the same functional specification as Hashtable, and includes versions of methods corresponding to each method of Hashtable. However, even though all operations are thread-safe, retrieval operations do not entail locking, and there is not any ...

Matlab code to create k-connected Harary Graph 4

Matlab code to create k-connected Harary Graph
The following is a MATLAB script to create a k-connected Harary Graph of n-nodes. Clearly the inputs required are n (no of nodes) and k (degree of each node). Also, while the code is a MATLAB script the basic technique to generate the adjacency matrix of the graph can be easily adopted to other languages ...

Code Jam Fair and Square

This is a solution to the FairAndSquare problem asked in the qualification round of Google Code Jam-2013. Please read the problem statement very carefully as the correctness of solution depends heavily on how you understand and interpret the problem statement. We present here two solutions to the problem one for the small input and the other for the large ...

Waiting for multiple threads to finish

Description: We need to perform four jobs , out of which three jobs are mutually exclusive and should be performed simultaneously(may be getting data from the database using select query)  and the outcome of three jobs will be served as the input for the fourth job.Hence, the fourth job could not be started untill the first three jobs are completed.   Java package com.example; ...

Triangle Test

 Description:          The following program takes three numbers as input and checks to see if these may form a triangle or not.                                  Primary Inputs:    Three numbers Primary Output:    Determine the type of triangle formed by the input numbers (if any). Platform Used:      JDK 1.6 with Notepad.  Java import java.io.*; class TriangleTest { public static void main(String[] args) { Console con = System.console(); ...

Text Editor

Description:           This program creates a simple Text Editor.   Primary Inputs:    —— Primary Output:    Text Editor Platform Used:      JDK 1.5 or higher.  Java /*save file as "editor.java"*/ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.text.*; import java.text.*; import java.util.*; import javax.swing.undo.*; import javax.swing.event.*; import java.net.*; public class editor extends JFrame { // ALL THE VARIABLES ...

Stack in Java

Sample source code for Stack implementation in Java ===================== MyStack.java ===================== Java public class MyStack { private static int[] stackArr = new int[5]; private static int top = -1; public void push(int element) { if (!this.isFull()) { top++; stackArr[top] = element; } else { System.out.print("\nStack Overflow!!\n"); } } public int pop() { int temp = ...

Selection Sort

Selection Sort
Java implementation of the Selection Sort Algorithm. Java package com.example; public class SelectionSort { public static void main(String[] args) { int[] toSort = { 2, 9, 3, 6, 1, 0, 4, 5, 8, 7 }; System.out.println(); System.out.print("Given Array: "); for (int i = 0; i < toSort.length; i++) { System.out.print(toSort[i] + " "); } // ...

Insertion Sort

Java implementation of the Insertion Sort Algorithm Java package com.coddicted.sort; public class InsertionSort { public static void main(String args[]) { int[] toSort = { 2, 9, 3, 6, 1, 0, 4, 5, 8, 7 }; System.out.print("\nGiven Array:\t"); for (int i = 0; i < toSort.length; i++) { System.out.print(toSort[i] + " "); } int temp; // ...