Search Results

Search found 148 results on 6 pages for 'davit siradeghyan'.

Page 4/6 | < Previous Page | 1 2 3 4 5 6  | Next Page >

  • How Can I Implement This In Java?

    - by davit-datuashvili
    first of all i am doing programs in java language this code is merely taken from web site i have not question about divide and conqurer algorithms but about function and it's argument here is code of ternary search def ternarySearch(f, left, right, absolutePrecision): #left and right are the current bounds; the maximum is between them if (right - left) < absolutePrecision: return (left + right)/2 leftThird = (2*left + right)/3 rightThird = (left + 2*right)/3 if f(leftThird) < f(rightThird): return ternarySearch(f, leftThird, right, absolutePrecision) return ternarySearch(f, left, rightThird, absolutePrecision) i am not asking once again how implement it in java i am asking for example how define function?for example let y=x^+3 yes we can determine it as public static int y(int x){ return x*x+3; } but here return ternarySearch(f, leftThird, right, absolutePrecision) function f does not have argument and how do such?please help me

    Read the article

  • parallel sorting methods

    - by davit-datuashvili
    in book algorithm in c++ by robert sedgewick there is such kind of problem how many parallel steps would be required to sort n records that are distributed on some k disks(let say k=1000 or any value ) and using some m processors the same m can be 100 or arbitrary number i have questions what we should do in such case? what are methods to solve such kind of problems? and what is answer in this case?

    Read the article

  • question about Batcher odd-even sort

    - by davit-datuashvili
    hi i ave question about Batcher's odd-even sort i have following code public class Batcher{ public static void batchsort(int a[],int l,int r){ int n=r-l+1; for (int p=1;p<n;p+=p) for (int k=p;k>0;k/=2) for (int j=k%p;j+k<n;j+=(k+k)) for (int i=0;i<n-j-k;i++) if ((j+i)/(p+p)==(j+i+k)/(p+p)) exch(a,l+j+i,l+j+i+k); } public static void main(String[]args){ int a[]=new int[]{2,4,3,4,6,5,3}; batchsort(a,0,a.length-1); for (int i=0;i<a.length;i++){ System.out.println(a[i]); } } public static void exch(int a[],int i,int j){ int t=a[i]; a[i]=a[j]; a[j]=t; } } //result is 3 3 4 4 5 2 6 what i missed ? hat is wrong?

    Read the article

  • question about function derivatives

    - by davit-datuashvili
    hi i have question for example i have some function int sumefunction(//parameters here let say int x){ return something let say x*x+2*x+3 or does not matter } i am interesting how find derivative of this function ?if i have int f(int x){ return sin(x); } after derivative it must return cos(x) thanks

    Read the article

  • question about quicksort

    - by davit-datuashvili
    i have write code of quicksort from programming pearls here is code public class Quick{ public static void quicksort(int x[], int l,int u) { if (l>=u) return ; int t=x[l]; int i=l; int j=u; do { i++; } while (i<=u && x[i]<t); do { j--; if (i>=j) break; } while ( x[j]>t); swap(x,i,j); swap(x, l,j); quicksort(x, l,j-1); quicksort(x, j+1,u); } public static void main(String[]args){ int x[]=new int[]{55,41,59,26,53,58,97,93}; quicksort(x,0,x.length-1); for (int i=0;i<x.length;i++){ System.out.println(x[i]); } } public static void swap(int x[], int i,int j){ int s=x[i]; x[i]=x[j]; x[j]=s; } } but it does not work here is output 59 41 55 26 53 97 58 93 any idea?

    Read the article

  • binary quicksort

    - by davit-datuashvili
    hi i want implement Binary quicksort algorithm from robert sedgewick book it looks like this public class quickb{ public static final int bitsword=32; public static void quicksortB(int a[],int l,int r,int d){ int i=l; int j=r-1; if (r<=l || d>bitsword) return ; while (j!=i) { while (digit(a[i],d)==0 && (i<j)) i++; while (digit(a[j],d)==1 && (j>i)) j++; int t=a[i]; a[i]=a[j]; a[j]=t; } if (digit(a[r-1],d)== 0) j++; quicksortB(a,l,j-1,d+1); quicksortB(a,j,r,d+1); } public static void main(String[]args){ int a[]=new int[]{4,7,3,9,8,2}; quicksortB(a,0,a.length-1,0); for (int i=0;i<a.length;i++){ System.out.println(a[i]); } } public static int digit(int m,int d){ return (m>>d)&1; } } but it show me error: java.lang.ArrayIndexOutOfBoundsException: 6 at quickb.quicksortB(quickb.java:13) at quickb.main(quickb.java:32) what is wrong?

    Read the article

  • please help me to solve problem

    - by davit-datuashvili
    first of all this is not homework and nobody tag it as homewrok i did not understand this porblem can anybody explain me?this is not english problem it is just misunderstanding what problem say Consider the problem of neatly printing a paragraph on a printer. The input text is a sequence of n words of lengths l1 , l2 , . . . , ln , measured in characters. We want to print this paragraph neatly on a number of lines that hold a maximum of M characters each. Our criterion of “neatness” is as follows. If a given line contains words i through j , where i = j , and we leave exactly one space between words, the number of extra space characters at the end of the line is M - j + i -(k=i,k< j,k++) lk , which must be nonnegative so that the words fit on the line. We wish to minimize the sum, over all lines except the last, of the cubes of the numbers of extra space characters at the ends of lines. Give a dynamic-programming algorithm to print a paragraph of n words neatly on a printer. Analyze the running time and space requirements of your algorithm.

    Read the article

  • question about in -place sort

    - by davit-datuashvili
    for example we have following array char data[]=new char[]{'A','S','O','R','T','I','N','G','E','X','A','M','P','L','E'}; and index array int a[]=new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}: void insitu(char data[],int a[],N){ for (int i=0;i<N;i++) { char v=data[i]; int j,int k; for (k=i;a[k]!=i;k=a[j];a[j]=j) { j=k;data[k]=data[a[k]; } data[k]=v; a[k]=k; } i have question what is initialize value of j? when i run this code it asks me to initialize j and what should do? }

    Read the article

  • How to compare two char* variables

    - by davit-datuashvili
    Suppose we have the following method (it is in c code): const char *bitap_search(const char *text, const char *pattern) My question is how can I compare text and pattern if they are char? This method is like a substring problem but I am confused a bit can I write in term of char such code? if (text[i]==pattern[i])? look i am interesting at this algorithm in java http://en.wikipedia.org/wiki/Bitap_algorithm how implement this in java? R = malloc((k+1) * sizeof *R); and please help me to translate this code in java

    Read the article

  • please help me to choose good boks on algorithms

    - by davit-datuashvili
    i want to help me to choose good books on algorithms many people from this site say me that show me your code and now i ask u to help me to choose good books on algorithms please i have not books on algorithms and in case i decide to buy it of course must buy book which has high quality yes? so please any ideas ?links everything

    Read the article

  • question about siftdown operation on heap

    - by davit-datuashvili
    i have following pseudo code which execute siftdown operation on heap array suppose is x void siftdown(int n) pre heap(2,n) && n>=0 post heap(1,n) i=1; loop /*invariant heap(1,n) except perhaps between i and it's (0,1,or 2) children*/ c=2*i; if (c>n) break; // c is left child of i if (c+1)<=n /* c+1 is rigth child of i if (x[c+1]<x[c]) c++ /* c is lesser child of i if (x[i]<=x[c]) break; swap(c,i) i=c; i have wrote following code is it correct? public class siftdown{ public static void main(String[]args){ int c; int n=9; int a[]=new int[]{19,100,17,2,7,3,36,1,25}; int i=1; while (i<n){ c=2*i; if (c>n) break; //c is the left child of i if (c+1<=n) //c+1 ir rigth child of i if (a[c+1]<a[c]) c++; if (a[i]<=a[c]) break; int t=a[c]; a[c]=a[i]; a[i]=t; i=c; } for (int j=0;j<a.length;j++){ System.out.println(a[j]); } } } // result is 19 2 17 1 7 3 36 100 25

    Read the article

  • please help me to implement such kind of sort

    - by davit-datuashvili
    hi i need to write sucj kind of sorting maybe it is similary to radix sort and also (this is not homework because i created it problem myself and please if anobody can help me) problem is like this suppose i have array int x[]=new int[]{4,5,3,2,1}; let write it into binary form 5 -0101 4- 0100 3-0011 2-0010 1-0001 i want to sort this elements by using bitwise operatos or check each bit and if less exchange it can anybody help me for example take 5 and 4 check first rightmost bit 0==0 so continue in the 1 index also 1==1 next the same 0=0 and last one 10 it means that first element is greater then second so exchange it please help me

    Read the article

  • question on HyperOperation

    - by davit-datuashvili
    i am trying to solve following recurence program http://en.wikipedia.org/wiki/Hyper_operator here is my code i know it has mistakes but i have done what i could public class hyper{ public static int Hyper(int a,int b,int n){ int t=0; if ( n==0) return b+1; if ((n==1) &&(b==0)) return a; if ((n==2) && (b==0)) return 0; if ((n>=3) && (b==0)) return 1; t=Hyper(a,b-1,n); return Hyper (a,t,n-1); } public static void main(String[]args){ int n=3; int a=5; int b=7; System.out.println(Hyper(a,b,n)); } } please help

    Read the article

  • Question about permute-by-sorting

    - by davit-datuashvili
    In the book "Introduction to Algorithms", second edition, there is the following problem: Suppose we have some array: int a[] = {1,2,3,4} and some random priorities array: P = {36,3,97,19} and the goal is to permute the array a randomly using this priorities array. This is the pseudo code: PERMUTE-BY-SORTING (A) 1 n ? length[A] 2 for i ? 1 to n 3 do P[i] = RANDOM (1, n 3) 4 sort A, using P as sort keys 5 return A The result should be the permuted array: B={2, 4, 1, 3}; I have written this code: import java.util.*; public class Permute { public static void main (String[] args) { Random r = new Random(); int a[] = new int[] {1,2,3,4}; int n = a.length; int b[] = new int[a.length]; int p[] = new int[a.length]; for (int i=0; i<p.length; i++) { p[i] = r.nextInt(n*n*n) + 1; } // for (int i=0;i<p.length;i++){ // System.out.println(p[i]); //} } } How do I continue?

    Read the article

  • question about permutation problem

    - by davit-datuashvili
    i have posted similar problem here http://stackoverflow.com/questions/2920315/permutation-of-array but i want following we know that with length n there is n! possible permutation from which one such that all element are in order they are in sorted variant so i want break permutation when array is in order and print result but something is wrong i think that problem is repeated of permutation here is my code import java.util.*; public class permut{ public static Random r=new Random(); public static void display(int a[],int n){ for (int i=0;i<n;i++){ System.out.println(a[i]); } } public static void Permut(int a[],int n){ int j=0; int k=0; while (j<fact(n)){ int s=r.nextInt(n); for (int i=0;i<n;i++){ k=a[i]; a[i]=a[s]; a[s]=k; } j++; if (sorted(a,n)) display(a,n); break; } } public static void main(String[]args){ int a[]=new int[]{3,4,1,2}; int n=a.length; Permut(a,n); } public static int fact(int n){ if (n==0 || (n==1) ) return 1; return n*fact(n-1); } public static boolean sorted(int a[],int n ){ boolean flag=false; for (int i=0;i<n-1;i++){ if (a[i]<a[i+1]){ flag=true; } else{ flag=false; } } return flag; } } can anybody help me? result is nothing

    Read the article

  • question about tree

    - by davit-datuashvili
    i have question for example i want to implement binary tree with array i want understand what will indexes for left child and rigth child ?my array is 0 based i want implement searching in tree using array can anybody help me?

    Read the article

  • Longest increasing subsequence

    - by davit-datuashvili
    I have written this code; is it correct? public static void main(String[] args){ int a[]=new int[]{0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15}; int a_b[]=new int[a.length]; a_b[0]=1; int int_max=0; int int_index=0; for (int i=0;i<a.length;i++){ for (int j=0;j<i;j++){ if (a[i]>a[j] && a_b[i]<(a_b[j]+1)){ a_b[i]=a_b[j]+1; } } if (a_b[i]>int_max){ int_max=a_b[i]; int_index=i; } } int k=int_max+1; int list[]=new int[k]; for (int i=int_index;i>0;i--){ if (a_b[i]==k-1){ list[k-1]=a[i]; k=a_b[i]; } } for (int g=0;g<list.length;g++){ System.out.println(list[g]); } }

    Read the article

  • question about heapsearch order

    - by davit-datuashvili
    ia have meet following problem suppose we have sorted array of size 2^k-1 where k is given number we should copy this array into heapsearch array b the elements in odd positions of a go in order into last half of the positions of b positions congruent to 2 modul0 4 go into b's secodn quarter and so on this is not homework and please nobody tag it as homework it is from programming pearls please any ideas

    Read the article

  • very simple question but i am confused

    - by davit-datuashvili
    Suppose we have the following method (it is in c code): const char *bitap_search(const char *text, const char *pattern) My question is how can I compare text and pattern if they are char? This method is like a substring problem but I am confused a bit can I write in term of char such code? if (text[i]==pattern[i])?

    Read the article

  • question on find value in array

    - by davit-datuashvili
    i have seen a few days ago such problem there is given two array find elements which are common of these array one of the solution was sort big array and then use binary search algorithm and also there is another algorithm- brute-force algorithm for (int i=0;i<array1.length;i++){ for (int j=0;j<array2.length;j++){ if (array1[i]==array2[j]){ //code here } } it's complexity is O(array1.length*array2.length); and i am interested the first method's complexity is also same yes? because we should sort array first and then use search method binary search algorithm's complexity is log_2(n) so it means that total time will be array.length*log_2(n) and about sort? please explain me which is better

    Read the article

  • question about partition

    - by davit-datuashvili
    i have question about hoare partition method here is code and also pseudo code please if something is wrong correct pseudo code HOARE-PARTITION ( A, p, r) 1 x ? A[ p] 2 i ? p-1 3 j ? r +1 4 while TRUE 5 do repeat j ? j - 1 6 until A[ j ] = x 7 do repeat i ? i + 1 8 until A[i] = x 9 if i < j 10 then exchange A[i] ? A[ j ] 11 else return j and my code public class Hoare { public static int partition(int a[],int p,int r) { int x=a[p]; int i=p-1; int j=r+1; while (true) { do { j=j-1; } while(a[j]>=x); do { i=i+1; } while(a[i]<=x); if (i<j) { int t=a[i]; a[i]=a[j]; a[j]=t; } else { return j; } } } public static void main(String[]args){ int a[]=new int[]{13,19,9,5,12,8,7,4,11,2,6,21}; partition(a,0,a.length-1); } } and mistake is this error: Class names, 'Hoare', are only accepted if annotation processing is explicitly requested 1 error any ideas

    Read the article

< Previous Page | 1 2 3 4 5 6  | Next Page >