Search Results

Search found 5070 results on 203 pages for 'algorithm'.

Page 100/203 | < Previous Page | 96 97 98 99 100 101 102 103 104 105 106 107  | Next Page >

  • question about permut-by-sorting

    - by davit-datuashvili
    hi i have following question from book introduction in algorithms second edition there is such problem suppose we have some array A int a[]={1,2,3,4} and we have some random priorities array P={36,3,97,19} we shoud permut array a randomly using this priorities array here is pseudo code P ERMUTE -B Y-S ORTING ( A) 1 n ? length[A] 2 for i ? 1 to n do P[i] = R ANDOM(1, n 3 ) 3 4 sort A, using P as sort keys 5 return A and result will be permuted array B={2, 4, 1, 3}; please help any ideas i have done this code and need aideas how continue import java.util.*; public class Permut { 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]); //} } } please help

    Read the article

  • question about Littles Law

    - by davit-datuashvili
    I know that Little's Law states (paraphrased): the average number of things in a system is the product of the average rate at which things leave the system and the average time each one spends in the system, or: n=x*(r+z); x-throughput r-response time z-think time r+z - average response time now i have question about a problem from programming pearls: Suppose that system makes 100 disk accesses to process a transaction (although some systems require fewer, some systems will require several hundred disk access per transaction). How many transactions per hour per disk can the system handle? please help

    Read the article

  • What guarantees are there on the run-time complexity (Big-O) of LINQ methods?

    - by tzaman
    I've recently started using LINQ quite a bit, and I haven't really seen any mention of run-time complexity for any of the LINQ methods. Obviously, there are many factors at play here, so let's restrict the discussion to the plain IEnumerable LINQ-to-Objects provider. Further, let's assume that any Func passed in as a selector / mutator / etc. is a cheap O(1) operation. It seems obvious that all the single-pass operations (Select, Where, Count, Take/Skip, Any/All, etc.) will be O(n), since they only need to walk the sequence once; although even this is subject to laziness. Things are murkier for the more complex operations; the set-like operators (Union, Distinct, Except, etc.) work using GetHashCode by default (afaik), so it seems reasonable to assume they're using a hash-table internally, making these operations O(n) as well, in general. What about the versions that use an IEqualityComparer? OrderBy would need a sort, so most likely we're looking at O(n log n). What if it's already sorted? How about if I say OrderBy().ThenBy() and provide the same key to both? I could see GroupBy (and Join) using either sorting, or hashing. Which is it? Contains would be O(n) on a List, but O(1) on a HashSet - does LINQ check the underlying container to see if it can speed things up? And the real question - so far, I've been taking it on faith that the operations are performant. However, can I bank on that? STL containers, for example, clearly specify the complexity of every operation. Are there any similar guarantees on LINQ performance in the .NET library specification?

    Read the article

  • binary number comparison

    - by EquinoX
    If I have a 32 bit two's complement number and I want to know what is the easiest way to know of two numbers are equal... what would be the fastest bitwise operator to know this? I know xor'ing both numbers and check if the results are zero works well... any other one's? how about if a number is greater than 0?? I can check the 31'st bit to see if it's greater or equal to 0..but how about bgtz?

    Read the article

  • question about random select

    - by davit-datuashvili
    here is code print number in decreasing order import java.util.*; public class select { public static void Select(int m,int n){ Random r=new Random(); if (m>0) if (r.nextInt(0x3fff8001) % n <m ){ System.out.println(n-1); Select(m-1,n-1); } else{ Select(m,n-1); } } public static void main(String[]args){ int m=35; int n=200; Select(m,n); } } and question is how to changes code such that print number in increasing order? please help

    Read the article

  • Data structure name: combination array/linked list

    - by me_and
    I have come up with a data structure that combines some of the advantages of linked lists with some of the advantages of fixed-size arrays. It seems very obvious to me, and so I'd expect someone to have thought of it and named it already. Does anyone know what this is called: Take a small fixed-size array. If the number of elements you want to put in your array is greater than the size of the array, add a new array and whatever pointers you like between the old and the new. Thus you have: Static array ————————————————————————— |1|2|3|4|5|6|7|8|9|a|b|c| ————————————————————————— Linked list ———— ———— ———— ———— ———— |1|*->|2|*->|3|*->|4|*->|5|*->NULL ———— ———— ———— ———— ———— My thing: ———————————— ———————————— |1|2|3|4|5|*->|6|7|8|9|a|*->NULL ———————————— ————————————

    Read the article

  • Loop through different sets of unique permutations

    - by user558610
    Hi I'm having a hard time getting started to layout code for this problem. I have a fixed amount of random numbers, in this case 8 numbers. R[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; That are going to be placed in 3 sets of numbers, with the only constraint that each set contain minimum one value, and each value can only be used once. For example: R1[] = { 1, 4 } R2[] = { 2, 8, 5, 6 } R3[] = { 7, 4 } I need to loop through all possible combinations of a set R1, R2, R3. Order is not important, so if the above example happened, I don't need R1[] = { 4, 1 } R2[] = { 2, 8, 5, 6 } R3[] = { 7, 4 } NOR R1[] = { 2, 8, 5, 6 } R2[] = { 7, 4 } R3[] = { 1, 4 } What is a good method?

    Read the article

  • Calculating similarites between sentences

    - by codecreator
    I have datbase with thousands of rows of error logs and their description.This error log is for an application that running 24/7. I want to create a dashboard/UI to view the current common errors happening for prodcution support. The problem I am having is that even though there are lot of common errors, the error description differs by the transcation ID or user ID or things that are unique for that sigle prcoess. e.g Error trasaction XYz failed for user 233 e.g 2. Error trasaction XYz failed for user 567 I consider these two erros to be same. So I want to a program that will go through the new error logs and classify them into groups. I am trying to use "edit distance" but its very slow.Since I alraedy have old error logs, i am trying to think of solutions using that information too. Any thoughts?

    Read the article

  • Common strategies to deal with rounding errors in currency-intensive soft?

    - by Max
    What is your advice on: compensation of accumulated error in bulk math operations on collections of Money objects. How is this implemented in your production code? (things like variable rounding, etc...) theory behind rounding in accountancy. any literature on topic. I currently read Fowler. He mentions Money type, but says nothing on strategies. Older posts on money-rounding (here, and here) do not provide a details and formality I need. Thanks for help.

    Read the article

  • fill array with binary numbers

    - by davit-datuashvili
    hi, first of all this is not homework!! my question is from book: Algorithms in C++ third edition by robert sedgewick question is: there is given array of size n by 2^n(two dimensional) and we should fill it by binary numbers with bits size exactly n or for example n=5 so result will be 00001 00010 00011 00100 00101 00110 00111 and so on we should put this sequence of bits into arrays please help me

    Read the article

  • command&pointer&malloc [closed]

    - by gcc
    input 23 3 4 4 42 n 23 0 9 9 n n n 3 9 9 x //according to input,i should create int pointer arrays. pointer arrays starting from 1 (that is initial arrays is arrays[1].when program sees n ,it must be jumb to arrays 2 expected output arrays[1] 3 4 5 42 arrays[2] 23 0 9 9 arrays[5] 3 9 9 x is stopper n is comman to create new pointer array i am new in this site anyone help me how can i write

    Read the article

  • Need Multiple Sudoku Solutions

    - by user1567909
    I'm trying to output multiple sudoku solutions in my program. For example, when You enter this as input: 8..6..9.5.............2.31...7318.6.24.....73...........279.1..5...8..36..3...... .'s denote blank spaces. Numbers represent already-filled spaces. The output should be a sudoku solution like so: 814637925325149687796825314957318462241956873638274591462793158579481236183562749 However, I want to output multiple solutions. This would be all the solutions that should be printed: 814637925325149687796825314957318462241956873638274591462793158579481236183562749 814637925325941687796825314957318462241569873638472591462793158579184236183256749 834671925125839647796425318957318462241956873368247591682793154579184236413562789 834671925125839647796524318957318462241956873368247591682793154519482736473165289 834671925125839647796524318957318462241965873368247591682793154519482736473156289 But my program only prints out one solution. Below is my recursive solution to solving a sudoku solution bool sodoku::testTheNumber(sodoku *arr[9][9], int row, int column) { if(column == 9) { column = 0; row++; if(row == 9) return true; } if(arr[row][column]->number != 0) { return testTheNumber(arr, row, column+1); } for(int k = 1; k < 10; k++) { if(k == 10) { arr[row][column]->number = 0; return false; } if(rowIsValid(arr, k, row) && columnIsValid(arr, k, column) && boxIsValid(arr, k, row, column)) { arr[row][column]->number = k; if(testTheNumber(arr, row, column+1)==true) { return true; } arr[row][column]->number = 0; } } return false; } Could anyone help me come up with a way to print out multiple solutions? Thanks.

    Read the article

  • Linear color interpolation?

    - by user146780
    If I have a straight line that mesures from 0 to 1, then I have colorA(255,0,0) at 0 on the line, then at 0.3 I have colorB(20,160,0) then at 1 on the line I have colorC(0,0,0). How could I find the color at 0.7? Thanks

    Read the article

  • How can I detect common substrings in a list of strings

    - by danio
    Given a set of strings, for example: EFgreen EFgrey EntireS1 EntireS2 J27RedP1 J27GreenP1 J27RedP2 J27GreenP2 JournalP1Black JournalP1Blue JournalP1Green JournalP1Red JournalP2Black JournalP2Blue JournalP2Green I want to be able to detect that these are three sets of files: EntireS[1,2] J27[Red,Green]P[1,2] JournalP[1,2][Red,Green,Blue] Are there any known ways of approaching this problem - any published papers I can read on this? The approach I am considering is for each string look at all other strings and find the common characters and where differing characters are, trying to find sets of strings that have the most in common, but I fear that this is not very efficient and may give false positives. Note that this is not the same as 'How do I detect groups of common strings in filenames' because that assumes that a string will always have a series of digits following it. [Edited 15/09/09 to add more sample strings]

    Read the article

  • priority queue implementation

    - by davit-datuashvili
    i have implemented priority queue and i am interested if it is correct public class priqueue { private int n,maxsize; int x[]; void swap(int i,int j){ int t=x[i]; x[i]=x[j]; x[j]=t; } public priqueue(int m){ maxsize=m; x=new int [maxsize+1]; n=0; } void insert(int t){ int i,p; x[++n]=t; for (i=n;i>1 && x[p=i/2] >x[i];i=p) swap(p,i); } public int extramin(){ int i,c; int t=x[1]; x[1]=x[n--]; for (i=1;(c=2*i)<=n;i=c){ if (c+1<=n && x[c+1]<x[c]) c++; if (x[i]<=x[c]) break; swap(c,i); } return t; } public void display(){ for (int j=0;j<x.length;j++){ System.out.println(x[j]); } } } public class priorityqueue { public static void main(String[] args) { priqueue pr=new priqueue(12); pr.insert(20); pr.insert(12); pr.insert(22); pr.insert(15); pr.insert(35); pr.insert(17); pr.insert(40); pr.insert(51); pr.insert(26); pr.insert(19); pr.insert(29); pr.insert(23); pr.extramin(); pr.display(); } } //result: 0 12 15 17 20 19 22 40 51 26 35 29 23

    Read the article

  • yet another logic.

    - by Sunil
    I'm working on a research problem out of curiosity and I don't know how to program the logic that I've in mind. Let me explain it to you : I've 4 vectors say for example, v1 = 1 1 1 1 v2 = 2 2 2 2 v3 = 3 3 3 3 v4 = 4 4 4 4 Now what I want to do is to add them combination-wise. i.e v12 = v1+v2 v13 = v1+v3 v14 = v1+v4 v23 = v2+v3 v24 = v2+v4 v34 = v3+v4 Till this step it is just fine. The problem/trick is now, at the end of each iteration I give the obtained vectors into a black box function and it returns only few of the vectors say v12, v13 and v34. Now, I want to add each of these vectors one vector from v1,v2,v3,v4 which it hasn't added before. For example v3 and v4 hasn't been added to v12 so I want to create v123 and v124. similarly for all the vectors like, v12 should become : v123 = v12+v3 v124 = v12+v4 v13 should become : v132 // this should not occur because I already have v123 v134 = v13+v4; v14,v23 and v24 cannot be considered because it was deleted in the black box function so all we have in our hands to work with is v12,v13 and v34. v34 should become : v341 // cannot occur because we have 134 v342 = v34+v2 It is important that I do not do all at one step at the start like for example I can do (4 choose 3) 4C3 and finish it off but I want to do it step by step at each iteration. I've asked a modified version of this question before (without including the black box function) and got answers here. Can anybody tell me how to do it when the black box function is included ? A modification of the previous answer would also be great. Thanks in advance.

    Read the article

< Previous Page | 96 97 98 99 100 101 102 103 104 105 106 107  | Next Page >