Search Results

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

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

  • programming books [closed]

    - by davit-datuashvili
    I have only one dream -- to buy these two books: Introduction to Algorithms, Third Edition Concrete Mathematics: A Foundation for Computer Science Sorry for my dream, this is a site for posting programming questions, but unfortunately everything happened

    Read the article

  • "Teach" a computer how to do addition?

    - by ffar
    The problem is to learn computer to do addition. Computer have as input a knowladge of a numbers: he "knows" that after 1 goes 2, after 2 goes 3 and so on... Having that data computer can easyly get next number. Next, computer have knowlandge as input that x+0=x and x+(y+1)=(x+1)+y. This axioms let computer to do addition. For example, to add 5 and 3, computer makes following: 5+3 = 5+(2+1) = (5+1)+2 = 6+2 = 6+(1+1) = (6+1)+1 = 7+1 = 8. But this is too long to add numbers in such way. The problem is to develop program which can improve this way of addition using the rules of mathemetics and logic. The goal addition must executed in O(log(N)) time, not O(N) time, N is magnitude of added numbers. Have this program any science value? Is any program can do such things?

    Read the article

  • How can I find the boundaries of a subset of a sorted list?

    - by Alex
    I have the following dilemma: I have a list of strings, and I want to find the set of string which start with a certain prefix. The list is sorted, so the naive solution is this: Perform binary search on the prefixes of the set, and when you find an element that starts with the prefix, traverse up linearly until you hit the top of the subset. This runs in linear time, however, and I was wondering if anyone can suggest a more efficient way to do it.

    Read the article

  • fastest way to perform string search in general and in python

    - by Rkz
    My task is to search for a string or a pattern in a list of documents that are very short (say 200 characters long). However, say there are 1 million documents of such time. What is the most efficient way to perform this search?. I was thinking of tokenizing each document and putting the words in hashtable with words as key and document number as value, there by creating a bag of words. Then perform the word search and retrieve the list of documents that contained this word. From what I can see is this operation will take O(n) operations. Is there any other way? may be without using hash-tables?. Also, is there a python library or third party package that can perform efficient searches?

    Read the article

  • Recurrent yearly date alert in Python

    - by coulix
    Hello Hackerz, Here is the idea A user can set a day alert for a birthday. (We do not care about the year of birth) He also picks if he wants to be alerted 0, 1, 2, ou 7 days (Delta) before the D day. Users have a timezone setting. I want the server to send the alerts at 8 am on the the D day - deleta +- user timezone Example: 12 jun, with "alert me 3 days before" will give 9 of Jun. My idea was to have a trigger_datetime extra field saved on the 'recurrent event' object. Like this a cron Job running every hour on my server will just check for all events matching irs current time hour, day and month and send to the alert. The problem from a year to the next the trigger_date could change ! If the alert is set on 1st of March, with a one day delay that could be either 28 or 29 of February .. Maybe i should not use the trigger date trick and use some other kind of scheme. All plans are welcome.

    Read the article

  • Search inside dynamic array in python

    - by user2091683
    I want to implement a code that loops inside an array that its size is set by the user that means that the size isn't constant. for example: A=[1,2,3,4,5] then I want the output to be like this: [1],[2],[3],[4],[5] [1,2],[1,3],[1,4],[1,5] [2,3],[2,4],[2,5] [3,4],[3,5] [4,5] [1,2,3],[1,2,4],[1,2,5] [1,3,4],[1,3,5] and so on [1,2,3,4],[1,2,3,5] [2,3,4,5] [1,2,3,4,5] Can you help me implement this code?

    Read the article

  • How to calculate deceleration rate of a flipping coin (in c)?

    - by Horace Ho
    A flipping coin on table will slow down and drop to the table surface, facing up or down. How can I calculate the flip-per-second declaration rate over time? For example, assuming the coin is at 10 flipping per second when it starts how long will it take to stop? For each second (9, 8, 7, 6 ... 3, 2, 1, stop), how is the flipping rate changed? Friction can be approximated as some real world objects (say, a metallic coin on a wooden table). Thanks!

    Read the article

  • [c++/STL] Selective iterator

    - by rubenvb
    FYI: no boost, yes it has this, I want to reinvent the wheel ;) Is there some form of a selective iterator (possible) in C++? What I want is to seperate strings like this: some:word{or other to a form like this: some : word { or other I can do that with two loops and find_first_of(":") and ("{") but this seems (very) inefficient to me. I thought that maybe there would be a way to create/define/write an iterator that would iterate over all these values with for_each. I fear this will have me writing a full-fledged custom way-too-complex iterator class for a std::string. So I thought maybe this would do: std::vector<size_t> list; size_t index = mystring.find(":"); while( index != std::string::npos ) { list.push_back(index); index = mystring.find(":", list.back()); } std::for_each(list.begin(), list.end(), addSpaces(mystring)); This looks messy to me, and I'm quite sure a more elegant way of doing this exists. But I can't think of it. Anyone have a bright idea? Thanks PS: I did not test the code posted, just a quick write-up of what I would try

    Read the article

  • it is very important for me this problem [closed]

    - by davit-datuashvili
    please help this is very important problem for me i am going to get job and need such kind of practise implement heaps priortiy queue and so on what is wrong in my java code please tell i want insert number with heap property and return minimum element what is wrong explain please look http://stackoverflow.com/questions/2902781/priority-queue-implementation/2903288#2903288

    Read the article

  • Merging elements in a scala list

    - by scompt.com
    I'm trying to port the following Java snippet to Scala. It takes a list of MyColor objects and merges all of the ones that are within a delta of each other. It seems like a problem that could be solved elegantly using some of Scala's functional bits. Any tips? List<MyColor> mergedColors = ...; MyColor lastColor = null; for(Color aColor : lotsOfColors) { if(lastColor != null) { if(lastColor.diff(aColor) < delta) { lastColor.merge(aColor); continue; } } lastColor = aColor; mergedColors.add(aColor); }

    Read the article

  • select k th mimimum from array a[0..n-1]

    - by davit-datuashvili
    i have done folloing code from progrmming pearls here is code import java.util.*; public class select { public static int select1(int x[],int l,int u,int k){ //pre l<=k<=u //post x[l..k-1]<=x[k]<=x[k+1..u] Random r=new Random(); int t=r.nextInt(u-1-l)+l; if (l>=u) return -1 ; swap(l,t); int s=x[l]; int i=l; int j=u+1; while (true){ do { i++; }while (i<=u && x[i]<t); do { j--; }while (x[j]>t); if (i>j) break; int temp=x[i]; x[i]=x[j];x[j]=t; swap(l,j); if (j<k){ return select1(x,j+1,u,k); } } return select1(x,l,j-1,k); } public static void main(String[] args) { int x[]=new int[]{4,7,9,3,2,12,13,10,20}; select1(x,0,x.length-1,5); } public static void swap(int i,int j){ int c=i; i=j; j=c; } } but here is mistake Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1 at select.select1(select.java:21) at select.main(select.java:36) Java Result: 1 please help

    Read the article

  • How to map a long integer number to a N-dimensional vector of smaller integers (and fast inverse)?

    - by psihodelia
    Given a N-dimensional vector of small integers is there any simple way to map it with one-to-one correspondence to a large integer number? Say, we have N=3 vector space. Can we represent a vector X=[(int32)x1,(int32)x2,(int32)x3] using an integer (int48)y? The obvious answer is "Yes, we can". But the question is: "What is the fastest way to do this and its inverse operation?"

    Read the article

  • Sort vector<int>(n) in O(n) time using O(m) space?

    - by Adam
    I have a vector<unsigned int> vec of size n. Each element in vec is in the range [0, m], no duplicates, and I want to sort vec. Is it possible to do better than O(n log n) time if you're allowed to use O(m) space? In the average case m is much larger than n, in the worst case m == n. Ideally I want something O(n). I get the feeling that there's a bucket sort-ish way to do this: unsigned int aux[m]; aux[vec[i]] = i; Somehow extract the permutation and permute vec. I'm stuck on how to do 3. In my application m is on the order of 16k. However this sort is in the inner loops and accounts for a significant portion of my runtime.

    Read the article

  • question about Tetration

    - by davit-datuashvili
    i have question how write program which calculates following procedures http://en.wikipedia.org/wiki/Tetration i have exponential program which returns x^n here is code public class Exp{ public static long exp(long x,long n){ long t=0; if (n==0){ t= 1; } else{ if (n %2==0){ t= exp(x,n/2)* exp(x,n/2); } else{ t= x*exp(x,n-1); } } return t; } public static void main(String[]args){ long x=5L; long n=4L; System.out.println(exp(x,n)); } } but how use it in Tetration program?please help

    Read the article

  • Multiply without multiplication, division and bitwise operators, and no loops. Recursion

    - by lxx22
    public class MultiplyViaRecursion{ public static void main(String[] args){ System.out.println("8 * 9 == " + multiply(8, 9)); System.out.println("6 * 0 == " + multiply(6, 0)); System.out.println("0 * 6 == " + multiply(0, 6)); System.out.println("7 * -6 == " + multiply(7, -6)); } public static int multiply(int x, int y){ int result = 0; if(y > 0) return result = (x + multiply(x, (y-1))); if(y == 0) return result; if(y < 0) return result = -multiply(x, -y); return result; } } My question is very simple and basic, why after each "if" the "return" still cannot pass the compilation, error shows missing return.

    Read the article

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