All Running Java Codes for the Questions Asked in Final Evalutions

download All Running Java Codes for the Questions Asked in Final Evalutions

of 21

description

java codes

Transcript of All Running Java Codes for the Questions Asked in Final Evalutions

Length of longest decreasing subsequence in an arraypublic static void getDecSeq(int[] data) {int currentSeq = 1;int currentIndex = 1;

int longestSeq = 0;int longestIndex = 0;for (int i = currentIndex; i < data.length; i++) {if (data[i] < data[i - 1]) {currentSeq++;} else {currentSeq = 1;currentIndex = i;}if (currentSeq > longestSeq) {longestSeq = currentSeq;longestIndex = currentIndex;}//double[] sequence = new double[longestSeq];//for (int j = longestIndex; j < longestSeq; j++) {//sequence[j] //}}output1= longestSeq;}when we give input0,10,8,31,2the output is 2public static void getDecSeq(int[] data) {int currentSeq = 1;int currentIndex = 1;

int longestSeq = 0;int longestIndex = 0;for (int i = currentIndex; i < data.length; i++) {if (data[i] < data[i - 1]) {currentSeq++;} else {currentSeq = 1;currentIndex = i;}if (currentSeq > longestSeq) {longestSeq = currentSeq;longestIndex = currentIndex;}//double[] sequence = new double[longestSeq];//for (int j = longestIndex; j < longestSeq; j++) {//sequence[j]//}}output1= longestSeq;}Length of longest increasing subsequence in an array

ANS 1)public static void printLIS(int[] nums){String paths[]=new String[nums.length];int sizes[]=new int[nums.length];for(int i=0;i