- vertex: each node of the graph
- edges: describe realationships between vertices
- Weigthed / Not Weigthed
static int mostFrequent(int arr[], int n) | |
{ | |
// Insert all elements in hash | |
Map<Integer, Integer> hp = | |
new HashMap<Integer, Integer>(); | |
for(int i = 0; i < n; i++) | |
{ | |
int key = arr[i]; | |
if(hp.containsKey(key)) |
Map<Integer, Integer> hp = new HashMap<Integer, Integer>(); |
public static void main(String[] args){ | |
//create threadpool | |
ExecutorService pool = Executors.newFixedThreadPool(iterations); | |
//create array of runnables that will be used to lunch each thread | |
myRunnable [] vec = new myRunnable [iterations]; | |
//fill array of runnables | |
int iterations = 10; | |
for(int iter = 0; iter < iterations; iter++){ |
/* | |
*In an array a | |
*figures out the element e | |
*in an index after performing r RIGHT rotations | |
*/ | |
public class Tragaperras { | |
static int circularRightArrayRotation(int[] a, int r, int index) { | |
int l = a.length; | |
int R = r - (r/l*l); | |
//Get rid of over-rotations |
/* | |
*In an array a | |
*figures out the element e | |
*in an index after performing r LEFT rotations | |
*/ | |
public class Tragaperras { | |
static int circularLeftArrayRotation(int[] a, int r, int index) { | |
int l = a.length; | |
int R = r - (r/l*l); | |
//Get rid of over-rotations |
// Following program is a Java implementation | |
// of Rabin Karp Algorithm given in the CLRS book | |
public class Main | |
{ | |
// d is the number of characters in the input alphabet | |
public final static int d = 256; | |
/* pat -> pattern | |
txt -> text |
public class MaxSubArraySum { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
int[] a = {1, -3, 2, 1,-1}; | |
int result = maxSumSubarray(a); | |
System.out.println(result); | |
} | |
public static int maxSumSubarray(int[] A){ |
public class MinSubArraySum { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
int[] a = {1, 3, -2, -1,1}; | |
int result = minSumSubarray(a); | |
System.out.println(result); | |
} | |
public static int minSumSubarray(int[] A){ |
public class removeDupsUnsorted { | |
public static void main(String[] args){ | |
//Create unsorted linked list | |
List<Integer> list = new LinkedList<Integer>(); | |
list.add(4); | |
list.add(3); | |
list.add(1); | |
list.add(3); | |
list.add(6); |