Search Results

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

Page 74/203 | < Previous Page | 70 71 72 73 74 75 76 77 78 79 80 81  | Next Page >

  • Random access gzip stream

    - by jkff
    I'd like to be able to do random access into a gzipped file. I can afford to do some preprocessing on it (say, build some kind of index), provided that the result of the preprocessing is much smaller than the file itself. Any advice? My thoughts were: Hack on an existing gzip implementation and serialize its decompressor state every, say, 1 megabyte of compressed data. Then to do random access, deserialize the decompressor state and read from the megabyte boundary. This seems hard, especially since I'm working with Java and I couldn't find a pure-java gzip implementation :( Re-compress the file in chunks of 1Mb and do same as above. This has the disadvantage of doubling the required disk space. Write a simple parser of the gzip format that doesn't do any decompressing and only detects and indexes block boundaries (if there even are any blocks: I haven't yet read the gzip format description)

    Read the article

  • Is there a website to look up common, already written functions?

    - by pinnacler
    I'm sitting here writing a function that I'm positive has been written before, somewhere on earth. It's just too common to have not been attempted, and I'm wondering why I can't just go to a website and search for a function that I can then copy and paste into my project in 2 seconds, instead of wasting my day reinventing the wheel. Sure there are certain libraries you can use, but where do you find these libraries and when they are absent, is there a site like I'm describing? Possibly a wiki of some type that contains free code that anybody can edit and improve? Edit: I can code things fine, I just don't know HOW to do them. So for example, right now, I'm trying to localize a robot/car/point in space. I KNOW there is a way to do it, just based off of range and distance. Triangulation and Trilateration. How to code that is a different story. A site that could have psuedo code, step by step how to do that would be ridiculously helpful. It would also ensure the optimal solution since everybody can edit it. I'm also writing in Matlab, which I hate because it's quirky, adding to my desire for creating a website like I describe.

    Read the article

  • Write a function that returns the longest palindrome in a given string. e.g "ccddcc" in the string "

    - by Learner
    I thought of a solution but it runs in O(n^2) time Algo 1: Steps: Its a brute force method Have 2 for loops for i = 1 to i less than array.length -1 for j=i+1 to j less than array.length This way you can get substring of every possible combination from the array Have a palindrome function which checks if a string is palindrome so for every substring (i,j) call this function, if it is a palindrome store it in a string variable If you find next palindrome substring and if it is greater than the current one, replace it with current one. Finally your string variable will have the answer Issues: 1. This algo runs in O(n^2) time. Algo 2: Reverse the string and store it in diferent array Now find the largest matching substring between both the array But this too runs in O(n^2) time Can you guys think of an algo which runs in a better time. If possible O(n) time

    Read the article

  • General Address Parser for Freeform Text

    - by Daemonic
    We have a program that displays map data (think Google Maps, but with much more interactivity and custom layers for our clients). We allow navigation via a set of combo boxes that prefill certain fields with a bunch of data (ie: Country: Canada, the Province field is filled in. Select Ontario, and a list of Counties/Regions is filled in. Select a county/region, and a city is filled in, etc...). While this guarantees accurate addresses, it's a pain for the users if they don't know where a street address or a city are located (ie, which county/region is kitchener in?). So we are looking at trying to do an address parser with a freeform text field. The user could enter something like this (similar to Google Maps, Bing Maps, etc...): 22 Main St, Kitchener, On And we could compartmentalize it into sections and do lookups on the data and get to the point they are looking for (or suggest alternatives). The problem with this is that how do we properly compartmentalize information? How do we break up the sections and find possible matches? I'm guessing we wouldn't be guaranteed that the user would enter data in a format we always expected (obviously). A follow up to this would be how to present the data if we don't find an exact match (or find multiple exact matches... two cities with the same street name in different counties, for example). We have a ton of data available in the mapping data (mapinfo tab format mostly). So we can do quick scans of street names, cities, states, etc. But I'm not sure about the best way to go about approaching this problem. Sure, using Google Maps would be nice, bue most of our clients are in closed in networks where outside access is not usually allowed and most aren't willing to rely on google maps (since it doesn't contain as much information as they need, such as custom map layers). They could, obviously, go to google and get the proper location then move to our software, but this would time consuming and speed of the process can be quite important.

    Read the article

  • compare function for upper_bound / lower_bound

    - by Martin Beckett
    I want to find the first item in a sorted vector that has a field less than some value x. I need to supply a compare function that compares 'x' with the internal value in MyClass but I can't work out the function declaration. Can't I simply overload '<' but how do I do this when the args are '&MyClass' and 'float' ? float x; std::vector< MyClass >::iterator last = std::upper_bound(myClass.begin(),myClass.end(),x);

    Read the article

  • maintaing a sorted list that is bigger than memory

    - by tcurdt
    I have a list of tuples. [ "Bob": 3, "Alice: 2, "Jane": 1, ] When incrementing the counts "Alice" += 2 the order should be maintained: [ "Alice: 4, "Bob": 3, "Jane": 1, ] When all is in memory there rather simple ways (some more or some less) to efficiently implement this. (using an index, insert-sort etc) The question though is: What's the most promising approach when the list does not fit into memory. Bonus question: What if not even the index fits into memory? How would you approach this?

    Read the article

  • Diagonal of polygon is inside or outside?

    - by Himadri
    I have three consecutive points of polygon, say p1,p2,p3. Now I wanted to know whether the orthogonal between p1 and p3 is inside the polygon or outside the polygon. I am doing it by taking three vectors v1,v2 and v3. And the point before the point p1 in polygon say p0. v1 = (p0 - p1) v2 = (p2 - p1) v3 = (p3 - p1) With reference to this question, I am using the method shown in the accepted answer of that question. It is only for counterclockwise. What if my points are clockwise. I am also knowing my whole polygon is clockwise or counterclockwise. And accordingly I select the vectors v1 and v2. But still I am getting some problem. I am showing one case where I am getting problem. This polygon is counterclockwise. and It is starting from the origin of v1 and v2.

    Read the article

  • CODE1 at SPOJ - cannot solve it

    - by VaioIsBorn
    I am trying to solve the problem Secret Code on SPOJ, and it's obviously a math problem. The full problem For those who are lazy to go and read, it's like this: a0, a1, a2, ..., an - sequence of N numbers B - a Complex Number (has both real and imaginary components) X = a0 + a1*B + a2*(B^2) + a3*(B^3) + ... + an*(B^n) So if you are given B and X, you should find a0, a1, ..an. I don't know how or where to start, because not even N is known, just X and B. The problem is not as easy as expressing a number in a base B, because B is a complex number. How can it be solved?

    Read the article

  • All words in a trie data-structure

    - by John Smith
    I'm trying to put all words in a trie in a string, a word is detonated by the eow field being true for a certain character in the trie data structure, hence a trie can could have letters than lead up to no word, for ex "abc" is in the trie but "c"'s eow field is false so "abc" is not a word Here is my Data structure struct Trie { bool eow; //when a Trie field isWord = true, hence there is a word char letter; Trie *letters[27]; }; and here is my attemped print-all function, basically trying to return all words in one string seperated by spaces for words string printAll( string word, Trie& data) { if (data.eow == 1) return word + " "; for (int i = 0; i < 26; i++) { if (data.letters[i] != NULL) printAll( word + data.letters[i]->letter, *(data.letters[i])); } return ""; } Its not outputting what i want, any suggestions?

    Read the article

  • CODE1 Spoj - cannot solve it

    - by VaioIsBorn
    I am trying to solve the problem Secret Code and it's obviously math problem. The full problem For those who are lazy to go and read, it's like this: a0,a1,a2,...,an - sequence of N numbers B - some number known to us X = a0 + a1*B + a2*(B^2) + a3*(B^3) + ... + an*(B^n) So if you are given B and X, you should find a0,a1,..an. I don't know how or where to start, because not even N is known, just X and B. Can you help me ?

    Read the article

  • how to determine base of a number?

    - by evil.coder
    Given a integer number and its reresentation in some arbitrary number system. The purpose is to find the base of the number system. For example, number is 10 and representation is 000010, then the base should be 10. Another example: number 21 representation is 0010101 then base is 2. One more example is: number is 6 and representation os 10100 then base is sqrt(2). Does anyone have any idea how to solve such problem?

    Read the article

  • How Can I Improve This Algorithm (LCS)

    - by superguay
    (define (lcs lst1 lst2) (define (except-last-pair list) (if (pair? (cdr list)) (cons (car list) (except-last-pair (cdr list))) '())) (define (car-last-pair list) (if (pair? (cdr list)) (car-last-pair (cdr list)) (car list))) (if (or (null? lst1) (null? lst2)) null (if (= (car-last-pair lst1) (car-last-pair lst2)) (append (lcs (except-last-pair lst1) (except-last-pair lst2)) (cons (car-last-pair lst1) '())) **(if (> (length (lcs lst1 (except-last-pair lst2))) (length (lcs lst2 (except-last-pair lst1)))) (lcs lst1 (except-last-pair lst2)) (lcs lst2 (except-last-pair lst1)))))) I dont want it to run over and over.. Regards, Superguay

    Read the article

  • Grouping rectangles (getting the bounding boxes of rects)

    - by hyn
    What is a good, fast way to get the "final" bounding boxes of a set of random (up to about 40, not many) rectangles? By final I mean that all bounding boxes don't intersect with any other. Brute force way: in a double for loop, for each rect, test for intersection against every other rect. The intersecting rects become a new rect (replaced), indicating the bounding box. Start over and repeat until no intersection is detected. Because the rects are random every time, and the rect count is relatively small, collision detection using spatial hashing seems like overkill. Is there a way to do this more effectively?

    Read the article

  • Algorithms behind load-balancers?

    - by Vimvq1987
    I need to study about load-balancers, such as Network Load Balancing, Linux Virtual Server, HAProxy,...There're somethings under-the-hood I need to know: What algorithms/technologies are used in these load-balancers? Which is the most popular? most effective? I expect that these algorithms/technologies will not be too complicated. Are there some resources written about them? Thank you very much for your help.

    Read the article

  • STL vector reserve() and copy()

    - by natersoz
    Greetings, I am trying to perform a copy from one vector (vec1) to another vector (vec2) using the following 2 abbreviated lines of code (full test app follows): vec2.reserve( vec1.size() ); copy(vec1.begin(), vec1.end(), vec2.begin()); While the call to vec2 sets the capacity of vector vec2, the copying of data to vec2 seems to not fill in the values from vec1 to vec2. Replacing the copy() function with calls to push_back() works as expected. What am I missing here? Thanks for your help. vectest.cpp test program followed by resulting output follows. Compiler: gcc 3.4.4 on cygwin. Nat /** * vectest.cpp */ #include <iostream> #include <vector> using namespace std; int main() { vector<int> vec1; vector<int> vec2; vec1.push_back(1); vec1.push_back(2); vec1.push_back(3); vec1.push_back(4); vec1.push_back(5); vec1.push_back(6); vec1.push_back(7); vec2.reserve( vec1.size() ); copy(vec1.begin(), vec1.end(), vec2.begin()); cout << "vec1.size() = " << vec1.size() << endl; cout << "vec1.capacity() = " << vec1.capacity() << endl; cout << "vec1: "; for( vector<int>::const_iterator iter = vec1.begin(); iter < vec1.end(); ++iter ) { cout << *iter << " "; } cout << endl; cout << "vec2.size() = " << vec2.size() << endl; cout << "vec2.capacity() = " << vec2.capacity() << endl; cout << "vec2: "; for( vector<int>::const_iterator iter = vec2.begin(); iter < vec2.end(); ++iter ) { cout << *iter << endl; } cout << endl; } output: vec1.size() = 7 vec1.capacity() = 8 vec1: 1 2 3 4 5 6 7 vec2.size() = 0 vec2.capacity() = 7 vec2:

    Read the article

  • calculating offer period for subscription

    - by TheVillageIdiot
    I'm maintaining a web application which deals with some kind of subscriptions. Users can to renew their subscriptions from 2 months before expiry (not earlier than that). Sometimes user does not renew before expiry and get grace period which is of 3 months. Now he can renew in these 3 months of grace period. Now the problem part. In the previous transactions of renew requests I have to show what was the offer period for that particular request (subscription start and subscription end period if renew was granted). Things are pretty simple if user renews before expiry, but I'm not able to get things straight if there is grace period specially when the subscriptions is expiring in last months of the year. Also there sometimes calculations go haywire when subscription is ending in jan or feb. All this is happening because offer period is not saved with the application anywhere (I don't know why). so if subscription is ending in 20 October 2008 and renew application is submitted in 16 January 2009 (because of grace period) the offer period should be 21 October 2008 to 20 October 2009.

    Read the article

  • red black tree balancing?

    - by Anirudh Kaki
    i am working to generate tango tree, where i need to check whether every sub tree in tango is balanced or not. if its not balanced i need to make it balance? I trying so hard to make entire RB-tree balance but i not getting any proper logic so can any one help me out?? here i am adding code to check how to find my tree is balanced are not but when its not balanced how can i make it balance. static boolean verifyProperty5(rbnode n) { int left = 0, right = 0; if (n != null) { bh++; left = blackHeight(n.left, 0); right = blackHeight(n.right, 0); } if (left == right) { System.out.println("black height is :: " + bh); return true; } else { System.out.println("in balance"); return false; } } public static int blackHeight(rbnode root, int len) { bh = 0; blackHeight(root, path1, len); return bh; } private static void blackHeight(rbnode root, int path1[], int len) { if (root == null) return; if (root.color == "black"){ root.black_count = root.parent.black_count+1; } else{ root.black_count = root.parent.black_count; } if ((root.left == null) && (root.right == null)) { bh = root.black_count; } blackHeight(root.left, path1, len); blackHeight(root.right, path1, len); }

    Read the article

  • Given 4 objects, how to figure out whether exactly 2 have a certain property

    - by Cocorico
    Hi guys! I have another question on how to make most elegant solution to this problem, since I cannot afford to go to computer school right so my actual "pure programming" CS knowledge is not perfect or great. This is basically an algorhythm problem (someone please correct me if I am using that wrong, since I don't want to keep saying them and embarass myself) I have 4 objects. Each of them has an species property that can either be a dog, cat, pig or monkey. So a sample situation could be: object1.species=pig object2.species=cat object3.species=pig object4.species=dog Now, if I want to figure out if all 4 are the same species, I know I could just say: if ( (object1.species==object2.species) && (object2.species==object3.species) && (object3.species==object4.species) ) { // They are all the same animal (don't care WHICH animal they are) } But that isn't so elegant right? And if I suddenly want to know if EXACTLY 3 or 2 of them are the same species (don't care WHICH species it is though), suddenly I'm in spaghetti code. I am using Objective C although I don't know if that matters really, since the most elegant solution to this is I assume the same in all languages conceptually? Anyone got good idea? Thanks!!

    Read the article

  • determine if intersection of a set with conjunction of two other sets is empty

    - by koen
    For any three given sets A, B and C: is there a way to determine (programmatically) whether there is an element of A that is part of the conjunction of B and C? example: A: all numbers greater than 3 B: all numbers lesser than 7 C: all numbers that equal 5 In this case there is an element in set A, being the number 5, that fits. I'm implementing this as specifications, so this numerical range is just an example. A, B, C could be anything.

    Read the article

  • How to find nth element from the end of a singly linked list?

    - by Codenotguru
    The following function is trying to find the nth to last element of a singly linked list. For example: If the elements are 8->10->5->7->2->1->5->4->10->10 then the result is 7th to last node is 7. Can anybody help me on how this code is working or is there a better and simpler approach? LinkedListNode nthToLast(LinkedListNode head, int n) { if (head == null || n < 1) { return null; } LinkedListNode p1 = head; LinkedListNode p2 = head; for (int j = 0; j < n - 1; ++j) { // skip n-1 steps ahead if (p2 == null) { return null; // not found since list size < n } p2 = p2.next; } while (p2.next != null) { p1 = p1.next; p2 = p2.next; } return p1; }

    Read the article

  • Choice of programming language for learning data structures and algorithms

    - by bguiz
    Which programming language would you recommend to learn about data structures and algorithms in? Considering the follwing: Personal experience Language features (pointers, OO, etc) Suitability for learning DS & A concepts I ask because there are some books out there that are programming language-agnostic (written from a Mathematical perspective, and use pseudocode). If I learn from one of these I would like to work out the algorithms in a chosen language. Then, there are other books which introduce DS & A concepts with examples in a particular programming laguage - and I would follow these examples as well. Either way, I have to choose a language, and I would like to stick to one throughout. Which one best fits the bill.

    Read the article

< Previous Page | 70 71 72 73 74 75 76 77 78 79 80 81  | Next Page >