Search Results

Search found 133 results on 6 pages for 'davit datuashvili'.

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

  • permutation of array

    - by davit-datuashvili
    for example i have array int a[]=new int[]{3,4,6,2,1}; I need list of all permutation such that if one is like this, {3,2,1,4,6}, others must not be the same i know that if length of array=n then there is n! possible combination please help me to write this algortihm what to do?

    Read the article

  • help implementing All Nearest Smaller Values algorithm

    - by davit-datuashvili
    http://en.wikipedia.org/wiki/All_nearest_smaller_values this is site of the problem and here is my code but i have some trouble to implement it import java.util.*; public class stack{ public static void main(String[]args){ int x[]=new int[]{ 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 }; Stack<Integer> st=new Stack<Integer>(); for (int a:x){ while (!st.empty() && st.pop()>=a){ System.out.println( st.pop()); if (st.empty()){ break; } else{ st.push(a); } } } } } and here is pseudo code from site S = new empty stack data structure for x in the input sequence: while S is nonempty and the top element of S is greater than or equal to x: pop S if S is empty: x has no preceding smaller value else: the nearest smaller value to x is the top element of S push x onto S

    Read the article

  • bit count in array

    - by davit-datuashvili
    hello i have following question i know that to count number of set bit in number of number of 1 bit there is following code int t ;//in which we want count how many bit are set for instance 3 011 there is 2 bit set int count=0; while(t>0){ t&=(t-1); count++; } now let take array example int x[]={3,5,6,8,9,7}; i have following code int sum=0; int count; for (int i=0;i<x.length;i++){ count=0; while (x[i]>0){ x[i]&=(x[i]-1); count++; } sum+=count; } I have question what is wrong? it doesn't work doesn't show me result;

    Read the article

  • question about missing element in array

    - by davit-datuashvili
    i have following problem from book introduction algorithm second edition by MIT university problem is following An array A[1 . . n] contains all the integers from 0 to n except one. It would be easy to determine the missing integer in O(n) time by using an auxiliary array B[0 . . n] to record which numbers appear in A. In this problem, however, we cannot access an entire integer in A with a single operation. The elements of A are represented in binary, and the only operation we can use to access them is “fetch the j th bit of A[i],” which takes constant time. Show that if we use only this operation, we can still determine the missing inte- ger in O(n) time please help

    Read the article

  • Looking for advice on how to do some bit-twiddling [closed]

    - by davit-datuashvili
    hi everybody fisrt of all this is not homework and now question is like this suppose i have array int a[]=new int[]{0xBCDA,0xABFE,0xBCAD,0xEFCA,0xFFCA} i know that there is always some hexadecimal number which occurs in all number or in this case A is repeat in array everywhere so my aim is print only repeat number and other numbers should be zero so my new array should be like this 0x000A, 0xA000,0x00A0 0x000A,0x000A any idea please help me? p.s please nobody say that this is homework

    Read the article

  • Heap property of this array

    - by davit-datuashvili
    From programming pearls, it is known that array[1...n] has heap property if for all 2<=i<=n x[i/2]<=x[i]. Here is my code: import java.math.*; public class Heap { public static void main(String[]args){ int x[]=new int[]{12,20,15,29,23,17,22,35,40,26,51,19}; int i=1; while (i<x.length) { if (x[Math.round(i/2)]<=x[i]) System.out.println("heap"); i++; } System.out.println("not heap"); } } Here I used Math.round because 4/2 and 5/2 is same and =2. When I compile this code it shows me at last line that it is not heap. Maybe because the index starts from 1 and we don't pay attention to index 0, yes?

    Read the article

  • select i th smallest element from array

    - by davit-datuashvili
    i have divide and conqurer method to find i th smalles element from array here is code public class rand_select{ public static int Rand_partition( int a[],int p,int q,int i){ //smallest in a[p..q] if ( p==q) return a[p]; int r=partition (a,p,q); int k=r-p+1; if (i==k) return a[r]; if (i<k){ return Rand_partition(a,p,r-1,i); } return Rand_partition(a,r-1,q,i-k); } public static void main(String[]args){ int a[]=new int []{6,10,13,15,8,3,2,12}; System.out.println(Rand_partition(a,0,a.length-1,7)); } public static int partition(int a[],int p,int q){ int m=a[0]; while ( p<q){ while (p<q && a[p++] <m){ p++; } while (q>p && a[q--]>m){ q--; } int t=a[p]; a[p]=a[q]; a[q]=t; } int k=0; for (int i=0;i<a.length;i++){ if ( a[i]==m){ k=i; } } return k; } } but here is problem java.lang.ArrayIndexOutOfBoundsException please help me

    Read the article

  • partition from programming pearls

    - by davit-datuashvili
    hi suppose i have following array int a[]=new int[]{55,41,59,26,53,58,97,93}; i want to partition it around 55 so new array will be such } 41,26,53,55,59,58,93,93}; i have done such kinds of problems myself but this is from programming pearls and here code is like this we have some array[a..b] and given value t we write code following way int m=a-1; for i=[a..b] if ( array[i]<t) swap (++m;i); where swap function exchange two element in array at indexes ++m and i, i have run this program and it showed me mistake Exception java.lang.NullPointerException can anybody help me?

    Read the article

  • 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 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

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