Search Results

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

Page 86/203 | < Previous Page | 82 83 84 85 86 87 88 89 90 91 92 93  | Next Page >

  • Display relative time in hour, day, month and year

    - by JohnJohnGa
    I wrote a function toBeautyString(epoch) : String which given a epoch, return a string which will display the relative time from now in hour and minute For instance: // epoch: 1346140800 -> Tue, 28 Aug 2012 05:00:00 GMT // and now: 1346313600 -> Thu, 30 Aug 2012 08:00:00 GMT toBeautyString(1346140800) -> "2 days and 3 hours ago" I want now to extend this function to month and year, so it will be able to print: 2 years, 1 month, 3 days and 1 hour ago Only with epoch without any external libraries. The purpose of this function is to give to the user a better way to visualize the time in the past. I found this: Calculating relative time but the granularity is not enough.

    Read the article

  • C++ priority queue structure used ?

    - by John Retallack
    While searching for some functions in C++ STL documentation I read that push and pop for priority queues needs constant time. "Constant (in the priority_queue). Although notice that push_heap operates in logarithmic time." My question is what kind of data structure is used to mantain a priority queue with O(1) for push and pop ?

    Read the article

  • Space requirements of a merge-sort

    - by Arkaitz Jimenez
    I'm trying to understand the space requirements for a Mergesort, O(n). I see that time requirements are basically, amount of levels(logn) * merge(n) so that makes (n log n). Now, we are still allocating n per level, in 2 different arrays, left and right. I do understand that the key here is that when the recursive functions return the space gets deallocated, but I'm not seeing it too obvious. Besides, all the info I find, just states space required is O(n) but don't explain it. Any hint? function merge_sort(m) if length(m) = 1 return m var list left, right, result var integer middle = length(m) / 2 for each x in m up to middle add x to left for each x in m after middle add x to right left = merge_sort(left) right = merge_sort(right) result = merge(left, right) return result

    Read the article

  • How can I store this kind of graph in neo4j for fast traversal?

    - by James
    This is a graph whose nodes exist in many connected components at once because a node's relationships are a collection of edge groups such that only one edge per edge group can be present at once. I need to be able to find all of the connected components that a node exists in. What would be the best way to store this graph in neo4j to quickly find all of the connected components that a node exists in? Is there a way to use the built in traversals to do this? Also: is there a name for this kind of graph? I'd appreciate any help/ideas. Update: Sorry for not being clear. All nodes are of the same type. Nodes have a variable number of edge groups. Exactly one edge from each edge group needs to be chosen for a particular connected component. I'm going to try to explain through example: Node x1 is related to: (x2 or x3 or x4) AND (x5 or x6) AND (x7) Node x2 is related to: (x8) AND (x9 or x10) So x1's first edge group is (x2, x3, x4), its second edge group is (x5, x6), and its third edge group is (x7). So here are a few connected components that x1 exists in: CC1: x1 is related to: x2, x5, x7 x2 is related to: x8 x9 CC2: x1 is related to: x2, x6, x7 x2 is related to: x8, x9 CC3: x1 is related to: x3, x5, x7 CC4: x1 is related to: x3, x6, x7 etc. I'm grateful for your help in this.

    Read the article

  • Are there Adaptive Replacement Cache patent-free alternatives?

    - by aleccolocco
    An open source high-performance project I'm working on needs to keep a cache of parsed/compiled files. A plain LRU or a plain LFU wouldn't fit. Plain LRU wouldn't work as there will be remote batch/spider processes hitting the service regularly. Plain LFU wouldn't work because content will age. ARC seems like the perfect solution but since IBM holds patents to it at least one open source project dropped it. Are there any (good enough) alternatives? EDIT: I'm not looking for exactly the same thing, just something that could handle those two situations. Perhaps some simple strategy with timestamps and sources. There have to be many programmers who faced this situation before. That's why the "good enough" bit.

    Read the article

  • Methodologies or algorithms for filling in missing data

    - by tbone
    I am dealing with datasets with missing data and need to be able to fill forward, backward, and gaps. So, for example, if I have data from Jan 1, 2000 to Dec 31, 2010, and some days are missing, when a user requests a timespan that begins before, ends after, or encompasses the missing data points, I need to "fill in" these missing values. Is there a proper term to refer to this concept of filling in data? Imputation is one term, don't know if it is "the" term for it though. I presume there are multiple algorithms & methodologies for filling in missing data (use last measured, using median/average/moving average, etc between 2 known numbers, etc. Anyone know the proper term for this problem, any online resources on this topic, or ideally links to open source implementations of some algorithms (C# preferably, but any language would be useful)

    Read the article

  • Extracting a given number of the highest values in a List

    - by James P.
    I'm seeking to display a fixed number of items on a web page according to their respective weight (represented by an Integer). The List where these items are found can be of virtually any size. The first solution that comes to mind is to do a Collections.sort() and to get the items one by one by going through the List. Is there a more elegant solution though that could be used to prepare, say, the top eight items?

    Read the article

  • Is there "good" PRNG generating values without hidden state?

    - by actual
    I need some good pseudo random number generator that can be computed like a pure function from its previous output without any state hiding. Under "good" I mean: I must be able to parametrize generator in such way that running it for 2^n iterations with any parameters should cover all or almost all values between 0 and 2^n - 1, where n is the number of bits in output value. Combined generator output of n + p bits must cover all or almost all values between 0 and 2^(n + p) - 1 if I run it for 2^n iterations for every possible combination of its parameters, where p is the number of bits in parameters. For example, LCG can be computed like a pure function and it can meet first condition, but it can not meet second one. Say, we have 32-bit generator, m = 2^32 and it is constant, our p = 64 (two 32-bit parameters a and c), n + p = 96, so we must peek data by three ints from output to meet second condition. Unfortunately, condition can not be meet because of strictly alternating sequence of odd and even ints in output. To overcome this, hidden state must be introduced, but that makes function not pure and breaks first condition (period become much longer). Am I wanting too much?

    Read the article

  • Where can I find soft-multiply and divide algorithms?

    - by srking
    I'm working on a micro-controller without hardware multiply and divide. I need to cook up software algorithms for these basic operations that are a nice balance of compact size and efficiency. My C compiler port will employ these algos, not the the C developers themselves. My google-fu is so far turning up mostly noise on this topic. Can anyone point me to something informative? I can use add/sub and shift instructions. Table lookup based algos might also work for me, but I'm a bit worried about cramming so much into the compiler's back-end...um, so to speak. Thanks!

    Read the article

  • Priority queue with dynamic item priorities.

    - by sean
    I need to implement a priority queue where the priority of an item in the queue can change and the queue adjusts itself so that items are always removed in the correct order. I have some ideas of how I could implement this but I'm sure this is quite a common data structure so I'm hoping I can use an implementation by someone smarter than me as a base. Can anyone tell me the name of this type of priority queue so I know what to search for or, even better, point me to an implementation?

    Read the article

  • Effective way to calculate a similarity percentage between data sets

    - by UltraVi01
    I am currently working with User objects -- each of which have many Goal objects. The Goal objects are not User specific, that is, Users can share the same Goal. I am attempting to fashion a way to calculate a "similarity percentage" between two Users... (i.e., taking into account how many Goals they share as well as how many Goals they do not share) Does anyone have experience with this type of situation? I am using Grails with Mysql if that is helpful. Thanks

    Read the article

  • Quick way to do data lookup in PHP

    - by Ghostrider
    I have a data table with 600,000 records that is around 25 megabytes large. It is indexed by a 4 byte key. Is there a way to find a row in such dataset quickly with PHP without resorting to MySQL? The website in question is mostly static with minor PHP code and no database dependencies and therefore fast. I would like to add this data without having to use MySQL if possible. In C++ I would memory map the file and do a binary search in it. Is there a way to do something similar in PHP?

    Read the article

  • [C++] std::string manipulation: whitespace, "newline escapes '\'" and comments #

    - by rubenvb
    Kind of looking for affirmation here. I have some hand-written code, which I'm not shy to say I'm proud of, which reads a file, removes leading whitespace, processes newline escapes '\' and removes comments starting with #. It also removes all empty lines (also whitespace-only ones). Any thoughts/recommendations? I could probably replace some std::cout's with std::runtime_errors... but that's not a priority here :) const int RecipeReader::readRecipe() { ifstream is_recipe(s_buffer.c_str()); if (!is_recipe) cout << "unable to open file" << endl; while (getline(is_recipe, s_buffer)) { // whitespace+comment removeLeadingWhitespace(s_buffer); processComment(s_buffer); // newline escapes + append all subsequent lines with '\' processNewlineEscapes(s_buffer, is_recipe); // store the real text line if (!s_buffer.empty()) v_s_recipe.push_back(s_buffer); s_buffer.clear(); } is_recipe.close(); return 0; } void RecipeReader::processNewlineEscapes(string &s_string, ifstream &is_stream) { string s_temp; size_t sz_index = s_string.find_first_of("\\"); while (sz_index <= s_string.length()) { if (getline(is_stream,s_temp)) { removeLeadingWhitespace(s_temp); processComment(s_temp); s_string = s_string.substr(0,sz_index-1) + " " + s_temp; } else cout << "Error: newline escape '\' found at EOF" << endl; sz_index = s_string.find_first_of("\\"); } } void RecipeReader::processComment(string &s_string) { size_t sz_index = s_string.find_first_of("#"); s_string = s_string.substr(0,sz_index); } void RecipeReader::removeLeadingWhitespace(string &s_string) { const size_t sz_length = s_string.size(); size_t sz_index = s_string.find_first_not_of(" \t"); if (sz_index <= sz_length) s_string = s_string.substr(sz_index); else if ((sz_index > sz_length) && (sz_length != 0)) // "empty" lines with only whitespace s_string.clear(); } Some extra info: the first s_buffer passed to the ifstream contains the filename, std::string s_buffer is a class data member, so is std::vector v_s_recipe. Any comment is welcome :)

    Read the article

  • generic binary Search in c#

    - by Pro_Zeck
    Below is my Generic Binary Search it works ok with the intgers type array it finds all the elements in it . But the Problem Arises when i use a string array to find any string data. It runs ok for the first index and last index elements but i cant find the middle elements. Stringarray = new string[] { "b", "a", "ab", "abc", "c" }; public static void BinarySearch<T>(T[] array, T searchFor, Comparer<T> comparer) { int high, low, mid; high = array.Length - 1; low = 0; if (array[0].Equals(searchFor)) Console.WriteLine("Value {0} Found At Index {1}",array[0],0); else if (array[high].Equals(searchFor)) Console.WriteLine("Value {0} Found At Index {1}", array[high], high); else { while (low <= high) { mid = (high + low) / 2; if (comparer.Compare(array[mid], searchFor) == 0) { Console.WriteLine("Value {0} Found At Index {1}", array[mid], mid); break; } else { if (comparer.Compare(searchFor, array[mid]) > 0) high = mid + 1; else low = mid + 1; } } if (low > high) { Console.WriteLine("Value Not Found In the Collection"); } } }

    Read the article

  • Need help with basic optimization problem

    - by ??iu
    I know little of optimization problems, so hopefully this will be didactic for me: rotors = [1, 2, 3, 4...] widgets = ['a', 'b', 'c', 'd' ...] assert len(rotors) == len(widgets) part_values = [ (1, 'a', 34), (1, 'b', 26), (1, 'c', 11), (1, 'd', 8), (2, 'a', 5), (2, 'b', 17), .... ] Given a fixed number of widgets and a fixed number of rotors, how can you get a series of widget-rotor pairs that maximizes the total value where each widget and rotor can only be used once?

    Read the article

  • Operations on bytes in C#

    - by Hooch
    Hello. I'm writing application to control LEDS on LPT. I have everything working except this. This is one small function. I have sth like that: I want to build function that will take two argument and return one number: In actual code those binary numers will be in hex. I put them there like that so that it's easier for you to visualize it. Example1: arg1 = 1100 1100 arg2 = 1001 0001 retu = 0100 1100 Example2: arg1 = 1111 1111 arg2 = 0001 0010 retu = 1110 1101 Example3: arg1 = 1111 0000 arg2 = 0010 0010 retu = 1101 0000 I have no idea how this function should look like. I want it to be as fast as possible. I'll call this function 200 times per second.

    Read the article

  • How does the Amazon Recommendation feature work?

    - by Rachel
    What technology goes in behind the screens of Amazon recommendation technology? I believe that Amazon recommendation is currently the best in the market, but how do they provide us with such relevant recommendations? Recently, we have been involved with similar recommendation kind of project, but would surely like to know about the in and outs of the Amazon recommendation technology from a technical standpoint. Any inputs would be highly appreciated. Update: This patent explains how personalized recommendations are done but it is not very technical, and so it would be really nice if some insights could be provided. From the comments of Dave, Affinity Analysis forms the basis for such kind of Recommendation Engines. Also here are some good reads on the Topic Demystifying Market Basket Analysis Market Basket Analysis Affinity Analysis Suggested Reading: Data Mining: Concepts and Technique

    Read the article

  • Result of Long Positive Integers & Search and element in array..

    - by AGeek
    Hi, I have two Questions for which I cannot find answers by googling, but I find these questions very important for preparation.. Kindly explain only the logic, I will be able to code. In Search of Efficient Logic..... in terms of Memory and Time. WAP to add two long positive integers. What Data structure / data type we can use to store the numbers and result. What is the best way to search an element from an array in shortest time. Size of the array could be large enough, and any elements could be stored in the array(i.e. no range). Thanks.

    Read the article

  • Load balancing and scheduling algorithms.

    - by Lukas Šalkauskas
    Hello there, so here is my problem: I have several different configuarion servers. I have different calculations (jobs); I can predict how long approximately each job will take to be caclulated. Also, I have priorities. My question is how to keep all machines loaded 99-100% and schedule the jobs in the best way. Each machine can do several calculations at a time. Jobs are pushed to the machine. The central machine knows the current load of each machine. Also, I would like to to assign some kind of machine learning here, because I will know statistics of each job (started, finished, cpu load etc.). How can I distribute jobs (calculations) in the best possible way, keeping in mind the priorities? Any suggestions, ideas, or algorithms ? FYI: My platform .NET.

    Read the article

  • How much time should it take to find the sum of all prime numbers less than 2 million?

    - by Shahensha
    I was trying to solve this Project Euler Question. I implemented the sieve of euler as a helper class in java. It works pretty well for the small numbers. But when I input 2 million as the limit it doesn't return the answer. I use Netbeans IDE. I waited for a lot many hours once, but it still didn't print the answer. When I stopped running the code, it gave the following result Java Result: 2147483647 BUILD SUCCESSFUL (total time: 2,097 minutes 43 seconds) This answer is incorrect. Even after waiting for so much time, this isn't correct. While the same code returns correct answers for smaller limits. Sieve of euler has a very simple algo given at the botton of this page. My implementation is this: package support; import java.util.ArrayList; import java.util.List; /** * * @author admin */ public class SieveOfEuler { int upperLimit; List<Integer> primeNumbers; public SieveOfEuler(int upperLimit){ this.upperLimit = upperLimit; primeNumbers = new ArrayList<Integer>(); for(int i = 2 ; i <= upperLimit ; i++) primeNumbers.add(i); generatePrimes(); } private void generatePrimes(){ int currentPrimeIndex = 0; int currentPrime = 2; while(currentPrime <= Math.sqrt(upperLimit)){ ArrayList<Integer> toBeRemoved = new ArrayList<Integer>(); for(int i = currentPrimeIndex ; i < primeNumbers.size() ; i++){ int multiplier = primeNumbers.get(i); toBeRemoved.add(currentPrime * multiplier); } for(Integer i : toBeRemoved){ primeNumbers.remove(i); } currentPrimeIndex++; currentPrime = primeNumbers.get(currentPrimeIndex); } } public List getPrimes(){ return primeNumbers; } public void displayPrimes(){ for(double i : primeNumbers) System.out.println(i); } } I am perplexed! My questions is 1) Why is it taking so much time? Is there something wrong in what I am doing? Please suggest ways for improving my coding style, if you find something wrong.

    Read the article

  • Determine coordinates of rotated rectangle

    - by MathieuK
    I'm creating an utility application that should detect and report the coordinates of the corners of a transparent rectangle (alpha=0) within an image. So far, I've set up a system with Javascript + Canvas that displays the image and starts a floodfill-like operation when I click inside the transparent rectangle in the image. It correctly determines the bounding box of the floodfill operation and as such can provide me the correct coordinates. Here's my implementation so-far: http://www.scriptorama.nl/image/ (works in recent Firefox / Safari ). However, the bounding box approach breaks down then the transparent rectangle is rotated (CW or CCW) as the resulting bounding box no longer properly represents the proper width and height. I've tried to come up with a few alternatives to detect to corners, but have not been able to think up a proper solution. So, does anyone have any suggestions on how I might approach this so I can properly detect the coordinates of 4 corners of the rotated rectangle?

    Read the article

< Previous Page | 82 83 84 85 86 87 88 89 90 91 92 93  | Next Page >