Posts

partition problems - Print all subsets with given sum

Given S = {3,1,1,2,2,1}, a valid solution to the partition problem is the two sets S1 = {1,1,1,2} and S2 = {2,3}. Both sets sum to 5, and they partition S. Note that this solution is not unique. S1 = {3,1,1} and S2 = {2,2,1} is another solution. import java.util.*; public class KNumberSubset { private int number; private int sum; private LinkedList<Integer> subset; private int[] numbers; static LinkedList<LinkedList<Integer>> all=new LinkedList<>(); public KNumberSubset(int[] numbers, int number) { this.numbers = numbers; this.number = number; sum = 0; subset = new LinkedList<Integer>(); } public void findSubset(int startPoint, int limit) { if (sum == number) { //System.out.println(subset + " :: " + sum); all.add((LinkedList<Integer>)subset.clone()); //all.add(subset); } else { for (int i = startPoint; i < numbers.length; i++) { sum = sum + numbers[i]; if (sum > li...

Java 9 Reactive Streams

JDK 1.9 :  Reactive Streams The Reactive Streams initiative provides a standard for asynchronous stream processing with nonblocking back pressure. A reactive stream provides a way to signal its source to ease production of data when the stream's destination becomes overwhelmed with that data. This signaling capability is like a valve on a water pipe. Closing this valve increases back pressure (the pressure back at the source) while easing the burden on the destination. The initiative's objective is to govern the exchange of stream data across an asynchronous boundary (such as passing data to another thread) while ensuring that the destination isn't forced to buffer arbitrary amounts of data. In other words, back pressure is an integral part of this model in order to allow the queues that mediate between threads to be bounded. Note that the communication of back pressure is handled asynchronously. Reactive Streams focuses on finding a minimal set of interfaces, method...

What is double locking java

Java programmers created the double-checked locking to be used with the Singleton creation pattern to limit how much code is synchronized. However, due to some little-known details of the Java memory model, this double-checked locking is not guaranteed to work. Instead of failing consistently, it will fail sporadically. In addition, the reasons for its failure are not obvious and involve intimate details of the Java memory model. These facts make a code failure due to double-checked locking very difficult to track down. Singleton creation:  To understand where the double-checked locking originated, you must understand the common singleton creation. class Singleton {                private static Singleton instance;               private Singleton() {                ...

How do you write an algorithm for the multiplication of two matrix [2D array]?

Problem statement: Given two matrices, the task is to multiply them. Matrices can either be square or rectangular. Example: Input: int m1[][] = {{2, 3, 4}, {5, 6, 7}}; // 2 X 3 matrix int m2[][] = {{1, 2}, {3, 4}, {5, 6}}; // 3 X 2 matrix Output: {{31, 40},{58,76}} public class  MatrixMultiplication  {     public static void main(String args[]) {         int  m1 [][] = {{2, 3, 4}, {5, 6, 7}};    // 2 X 3 matrix         int  m2 [][] = {{1, 2}, {3, 4}, {5, 6}};  // 3 X 2 matrix           int  res [][] = new int[2][2];    // resultant matrix of 2 X 2         for (int  i  = 0;  i  < 2;  i ++) {   //  i  represent row             for (int  j  = 0;  j  < 2;  j ++) {   //  j  represent column     ...

RTC plugin component Developments

Image
See Env setup Create Plug-in  Open IDE(Eclipse) Create a new Plug-in Development-> Plug-in Project Fill out the second dialog as follows, and select Next. Fill out the second dialog as follows, and select Finish. Open  MANIFEST.MF  or  Plugin.xml  file for your project From the  Overview tab  select This plug-in is a singleton. Save this file. From the Dependencies tab, select the Add… button. Add the following four plug-ins to the list. After adding, save the file com.ibm.team.process.common  com.ibm.team.process.service  com.ibm.team.workitem.common  com.ibm.team.repository.common these are the few dependencies, for others functionality you may have to add others dependencies. Like for   SCM  you have to add *  scm.common  and *  scm.service repository.common and  repository.service Search for available  .service and .common  and add ...

RTC server side Plugin Extension Deployment

RTC server side UI plugin developments

Download Template