Search Results

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

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

  • question about interface

    - by davit-datuashvili
    i have posted this question http://stackoverflow.com/questions/2874487/how-can-i-implement-this-python-snippet-in-java i have compiled it now i need to use in main project public static void main(String[]args){ } ? can anybody show me example?

    Read the article

  • What is the complexity of this c function

    - by Bunny Rabbit
    what is the complexity of the following c Function ? double foo (int n) { int i; double sum; if (n==0) return 1.0; else { sum = 0.0; for (i =0; i<n; i++) sum +=foo(i); return sum; } } Please don't just post the complexity can you help me in understanding how to go about it . EDIT: It was an objective question asked in an exam and the Options provided were 1.O(1) 2.O(n) 3.O(n!) 4.O(n^n)

    Read the article

  • Generate a valid array key from an URL string in PHP

    - by John Riche
    I have a PHP array with some predefined values: $aArray = array( 0 => 'value0', 1 => 'value1' ); I need to create a function where the string input will always return the same, valid, array key so that when I call: GiveMeAKey('http://www.google.com'); // May return 0 or 1 I receive always the same key (I don't care which one) from the array. Obvisously I can't store the relationship in a database and the string passed to the GiveMeAKey method can be any URL. I wonder if there is a way of doing that ?

    Read the article

  • Finding users near other user

    - by Bunny Rabbit
    what algorithms should I explore to implement a feature which lets a user find other user located near him , the latitude and the longitudes of all the user are known in advance and are fixed [not dynamic]. Also i believe that there should be a better way to store such data then simply storing the lat , long of the user against his user id in a database.What are the efficient ways to handle this ?

    Read the article

  • Shuffle array variables in a pre-specified order, without using extra memory of "size of input array"

    - by Eternal Learner
    Input : A[4] = {0,4,-1,1000} - Actual Array P[4] = {1,0,3,2} - Order to be reshuffled Output: A[4] = {4,0,1000,-1} Condition : Don't use an additional array as memory. Can use an extra variable or two. Problem : I have the below program in C++, but this fails for certain inputs of array P. #include<iostream> using namespace std; void swap(int *a_r,int *r) { int temp = *r; *r = *a_r; *a_r = temp; } int main() { int A[4] = {0,4,-1,1000}; int P[4] = {3,0,1,2}; int value = A[0] , dest = P[0]; for(int i=0; i<4;i++) { swap(&A[dest],&value); dest = P[dest]; } for(int i=0;i<4;i++) cout<<A[i]<<" "; }

    Read the article

  • Word Counter Implementation

    - by kenny
    Is there a better way than the following brute foce implementation of a c# word counting class? UPDATED CODE: Sorry! /// <summary> /// A word counting class. /// </summary> public class WordCounter { Dictionary<string, int> dictTest = new Dictionary<string, int> (); /// <summary> /// Enters a word and returns the current number of times that word was found. /// </summary> /// <param name="word">The word or string found.</param> /// <returns>Count of times Found() was called with provided word.</returns> public int Found ( string word ) { int count = 1; return dictTest.TryGetValue ( word, out count ) ? ++dictTest[word] : dictTest[word] = 1; } }

    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

  • How can I parse free text (Twitter tweets) against a large database of values?

    - by user136416
    Hi there Suppose I have a database containing 500,000 records, each representing, say, an animal. What would be the best approach for parsing 140 character tweets to identify matching records by animal name? For instance, in this string... "I went down to the woods to day and couldn't believe my eyes: I saw a bear having a picnic with a squirrel." ... I would like to flag up the words "bear" and "squirrel", as they appear in my database. This strikes me as a problem that has probably been solved many times, but from where I'm sitting it looks prohibitively intensive - iterating over every db record checking for a match in the string is surely a crazy way to do it. Can anyone with a comp sci degree put me out of my misery? I'm working in C# if that makes any difference. Cheers!

    Read the article

  • Choose between multiple options with defined probability

    - by Sijin
    I have a scenario where I need to show a different page to a user for the same url based on a probability distribution, so for e.g. for 3 pages the distribution might be page 1 - 30% of all users page 2 - 50% of all users page 3 - 20% of all users When deciding what page to load for a given user, what technique can I use to ensure that the overall distribution matches the above? I am thinking I need a way to choose an object at "random" from a set X { x1, x2....xn } except that instead of all objects being equally likely the probability of an object being selected is defined beforehand.

    Read the article

  • question about quicksort 3 way partition

    - by davit-datuashvili
    i want implement quicksort 3 way partition here is code public class quick3{ public static void quicksort3(int a[],int l,int r){ int k; int v=a[r]; if (r<=l) return; int i=l; int j=r; int p=l-1; int q=r; for (;;) { while (a[++i]<v); while (v<a[--j]) if (j==i) break; if (i>=j) break; swap( a,i, j); if (a[i]==v){ p++; swap(a,p,i);} if (v==a[j]){ q--; swap( a,q,j); } } swap(a,i,r); j=i-1; i=i+1; for (k=1;k<=p;k++,j--) swap(a,k,j); for (k=r-1;k>=q;k--,i++) swap(a,k,i); quicksort3(a,l,j); quicksort3(a,i,r); } public static void main(String[]args){ int a[]=new int[]{4,6,5,9,7,8,3}; quicksort3(a,0,a.length-1); for (int i=0;i<a.length;i++){ System.out.println(a[i]); } } public static void swap(int a[],int i,int j){ int t=a[i]; a[i]=a[j]; a[j]=t; } } after change result is 4 8 7 6 3 5 9 any suggestion?please help

    Read the article

  • very confused please answer [closed]

    - by davit-datuashvili
    hi i am very surpise when somebody post question everybody are saying it is homework please show us your effort now i have done this code http://stackoverflow.com/questions/2902781/priority-queue-implementation question is is this implementation correct? and nobody tell me answer also this one http://stackoverflow.com/questions/2896811/question-about-siftdown-operation-on-heap-closed can anybody explain me what is happened?no one answer me why?

    Read the article

  • How to calculate the y-pixels of someones weight on a graph? (math+programming question)

    - by RexOnRoids
    I'm not that smart like some of you geniuses. I need some help from a math whiz. My app draws a graph of the users weight over time. I need a surefire way to always get the right pixel position to draw the weight point at for a given weight. For example, say I want to plot the weight 80.0(kg) on the graph when the range of weights is 80.0 to 40.0kg. I want to be able to plug in the weight (given I know the highest and lowest weights in the range also) and get the pixel result 400(y) (for the top of the graph). The graph is 300 pixels high (starts at 100 and ends at 400). The highest weight 80kg would be plot at 400 while the lowest weight 40kg would be plot at 100. And the intermediate weights should be plotted appropriately. I tried this but it does not work: -(float)weightToPixel:(float)theWeight { float graphMaxY = 400; //The TOP of the graph float graphMinY = 100; //The BOTTOM of the graph float yOffset = 100; //Graph itself is offset 100 pixels in the Y direction float coordDiff = graphMaxY-graphMinY; //The size in pixels of the graph float weightDiff = self.highestWeight-self.lowestWeight; //The weight gap float pixelIncrement = coordDiff/weightDiff; float weightY = (theWeight*pixelIncrement)-(coordDiff-yOffset); //The return value return weightYpixel; }

    Read the article

  • Python structure mistake

    - by jaddy123
    I'm writing a program in which I can Reverse the sequence and Replace all As with Ts, all Cs with Gs, all Gs with Cs, and all Ts with As. the program is to read a sequence of bases and output the reverse complement sequence. I am having trouble to do it so can anyone please help me with this by having a look on my code: word = raw_input("Enter sequence: ") a = word.replace('A', 'T') b = word.replace('C', 'G') c = word.replace('G', 'C') d = word.replace('T', 'A') if a == word and b == word and c == word and d == word: print "Reverse complement sequence: ", word And I want this sort of output: Enter sequence: CGGTGATGCAAGG Reverse complement sequence: CCTTGCATCACCG Regards

    Read the article

  • Best way to reverse a string in C# 2.0

    - by Guy
    I've just had to write a string reverse function in C# 2.0 (i.e. LINQ not available) and came up with this: public string Reverse(string text) { char[] cArray = text.ToCharArray(); string reverse = String.Empty; for (int i = cArray.Length - 1; i > -1; i--) { reverse += cArray[i]; } return reverse; } Personally I'm not crazy about the function and am convinced that there's a better way to do it. Is there?

    Read the article

  • please help me to choose good books on algorithms [closed]

    - by davit-datuashvili
    Possible Duplicate: What is the best book for learning about Algorithms? 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

  • How to find the length of a linked list that is having cycles in it?

    - by Bragaadeesh
    This was one of the interview questions asked. How to find the length of a linked list that is having cycle in it. I know how to calculate whether a linked list has a cycle or not using Hare and Tortoise technique. I even know how to calculate the length by storing the addresses in a hashset. But what I was not able to tell is how to calculate the length of the linked list without using a external space of O(n). Please help me. Thanks.

    Read the article

  • Java How to find a value in a linked list iteratively and recursively

    - by Roxy
    Hi I have a method that has a reference to a linked list and a int value. So, this method would count and return how often the value happens in the linked list. So, I decided to make a class, public class ListNode{ public ListNode (int v, ListNode n) {value = v; next = n;) public int value; public ListNode next; } Then, the method would start with a public static int findValue(ListNode x, int valueToCount){ // so would I do it like this?? I don't know how to find the value, // like do I check it? for (int i =0; i< x.length ;i++){ valueToCount += valueToCount; } So, I CHANGED this part, If I did this recursively, then I would have public static int findValue(ListNode x, int valueToCount) { if (x.next != null && x.value == valueToCount { return 1 + findValue(x, valueToCount);} else return new findvalue(x, valueToCount); SO, is the recursive part correct now?

    Read the article

  • How to get the keyword match number for many categories?

    - by Mike108
    How to get the keyword match number for many categories? The scenario is that when I type a product keyword, I want to get the match item number in many categories. For example, when I type the keyword "iphone" , the page will show the match item number in many categories: Mobile(5) battery(2) app(6) typeA(2) typeB(9) typeC(15) typeC(1) typeD(9) typeE(7) typeF(8) ...... ...... typeZ(5) How to implement this for a better performance? I use C# ASP.NET.

    Read the article

  • is this code correct? [closed]

    - by davit-datuashvili
    hi i have poste this code from this title http://stackoverflow.com/questions/2896363/hi-i-have-question-here-is-pseudo-code-about-sift-up-and-sift-down-on-heaps i have following code of siftup on heap is it correct?i have put here because i have changed at old place my question and it became unreadable so i have posted here public class siftup{ public static void main(String[]args){ int p; int n=12; int a[]=new int[]{15,20,12,29,23,17,22,35,40,26,51,19}; int i=n-1; while (i!=0){ if (i==1) break; p=i/2; if (a[p]<=a[i]){ int t=a[p]; a[p]=a[i]; a[i]=t; } i=p; } for (int j=0;j<n;j++){ System.out.println(a[j]); } } } //result is this 15 20 19 29 23 12 22 35 40 26 51 17 is it correct?

    Read the article

  • please help me to solve problem

    - by davit-datuashvili
    i have operation on heap fixdown operation below is code public class HEap{ public static void fixdown(int a[],int k,int n){ while(2*k<=n){ int j=2*k; if (j<n && a[j]<a[j+1]) j++; if (!(a[k]<a[j])) break; int t=a[k]; a[k]=a[j]; a[j]=k; k=j; } } public static void main(String[]args){ int a[]=new int[]{12,15,20,29,23,22,17,40,26,35,19,51}; fixdown(a,1,a.length); for (int i=0;i<a.length;i++){ System.out.println(a[i]); } } } //and result is 12 29 20 40 23 22 17 3 26 35 19 51 i am interested why is 3 in the list?in the array is not

    Read the article

  • Given the lat/lon of 2 close points on earth (<10m), How do I calculate the distance in metres?

    - by Rory
    I have the lat/lon of 2 points on the earth. They are really close together, <10m. Let's assume the earth is flat. How do I calculate the distance between them in metres? I know about tools (PostGIS, etc.) that can do this correctly, however I'm just doing a rough and ready type, and I'm OK with low accuracy. At such small sizes a difference of 1% is only 10cm, which is fine for me. I'm doing this in stock python. I'm OK with a standard Euclidean distance thing.

    Read the article

  • Doubling a number - shift left vs. multiplication

    - by ToxicAvenger
    What are the differences between int size = (int)((length * 200L) / 100L); // (1) and int size = length << 1; // (2) (length is int in both cases) I assume both code snippets want to double the length parameter. I'd be tempted to use (2) ... so are there any advantages for using (1)? I looked at the edge cases when overflow occurs, and both versions seem to have the same behavior. Please tell me what am I missing.

    Read the article

  • Fastest method to define whether a number is a triangular number

    - by psihodelia
    A triangular number is the sum of the n natural numbers from 1 to n. What is the fastest method to find whether a given positive integer number is a triangular one? I suppose, there must be a hidden pattern in a binary representation of such numbers (like if you need to find whether a number is even/odd you check its least significant bit). Here is a cut of the first 1200th up to 1300th triangular numbers, you can easily see a bit-pattern here (if not, try to zoom out): (720600, '10101111111011011000') (721801, '10110000001110001001') (723003, '10110000100000111011') (724206, '10110000110011101110') (725410, '10110001000110100010') (726615, '10110001011001010111') (727821, '10110001101100001101') (729028, '10110001111111000100') (730236, '10110010010001111100') (731445, '10110010100100110101') (732655, '10110010110111101111') (733866, '10110011001010101010') (735078, '10110011011101100110') (736291, '10110011110000100011') (737505, '10110100000011100001') (738720, '10110100010110100000') (739936, '10110100101001100000') (741153, '10110100111100100001') (742371, '10110101001111100011') (743590, '10110101100010100110') (744810, '10110101110101101010') (746031, '10110110001000101111') (747253, '10110110011011110101') (748476, '10110110101110111100') (749700, '10110111000010000100') (750925, '10110111010101001101') (752151, '10110111101000010111') (753378, '10110111111011100010') (754606, '10111000001110101110') (755835, '10111000100001111011') (757065, '10111000110101001001') (758296, '10111001001000011000') (759528, '10111001011011101000') (760761, '10111001101110111001') (761995, '10111010000010001011') (763230, '10111010010101011110') (764466, '10111010101000110010') (765703, '10111010111100000111') (766941, '10111011001111011101') (768180, '10111011100010110100') (769420, '10111011110110001100') (770661, '10111100001001100101') (771903, '10111100011100111111') (773146, '10111100110000011010') (774390, '10111101000011110110') (775635, '10111101010111010011') (776881, '10111101101010110001') (778128, '10111101111110010000') (779376, '10111110010001110000') (780625, '10111110100101010001') (781875, '10111110111000110011') (783126, '10111111001100010110') (784378, '10111111011111111010') (785631, '10111111110011011111') (786885, '11000000000111000101') (788140, '11000000011010101100') (789396, '11000000101110010100') (790653, '11000001000001111101') (791911, '11000001010101100111') (793170, '11000001101001010010') (794430, '11000001111100111110') (795691, '11000010010000101011') (796953, '11000010100100011001') (798216, '11000010111000001000') (799480, '11000011001011111000') (800745, '11000011011111101001') (802011, '11000011110011011011') (803278, '11000100000111001110') (804546, '11000100011011000010') (805815, '11000100101110110111') (807085, '11000101000010101101') (808356, '11000101010110100100') (809628, '11000101101010011100') (810901, '11000101111110010101') (812175, '11000110010010001111') (813450, '11000110100110001010') (814726, '11000110111010000110') (816003, '11000111001110000011') (817281, '11000111100010000001') (818560, '11000111110110000000') (819840, '11001000001010000000') (821121, '11001000011110000001') (822403, '11001000110010000011') (823686, '11001001000110000110') (824970, '11001001011010001010') (826255, '11001001101110001111') (827541, '11001010000010010101') (828828, '11001010010110011100') (830116, '11001010101010100100') (831405, '11001010111110101101') (832695, '11001011010010110111') (833986, '11001011100111000010') (835278, '11001011111011001110') (836571, '11001100001111011011') (837865, '11001100100011101001') (839160, '11001100110111111000') (840456, '11001101001100001000') (841753, '11001101100000011001') (843051, '11001101110100101011') (844350, '11001110001000111110') For example, can you also see a rotated normal distribution curve, represented by zeros between 807085 and 831405?

    Read the article

  • How to figure out "progress" while sorting?

    - by Mehrdad
    I'm using stable_sort to sort a large vector. The sorting takes on the order of a few seconds (say, 5-10 seconds), and I would like to display a progress bar to the user showing how much of the sorting is done so far. But (even if I was to write my own sorting routine) how can I tell how much progress I have made, and how much more there is left to go? I don't need it to be exact, but I need it to be "reasonable" (i.e. reasonably linear, not faked, and certainly not backtracking).

    Read the article

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