Search Results

Search found 5655 results on 227 pages for 'stl algorithm'.

Page 25/227 | < Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >

  • Algorithm to Group All the Cycles Together

    - by Ngu Soon Hui
    I have a lot of cycles ( indicated by numeric values, for example, 1-2-3-4 corresponds to a cycle, with 4 edges, edge 1 is {1:2}, edge 2 is {2:3}, edge 3 is {3,4}, edge 4 is {4,1}, and so on). A cycle is said to be connected to another cycle if they share one and only one edge. For example, let's say I have two cycles 1-2-3-4 and 5-6-7-8, then there are two cycle groups because these two cycles are not connecting to each other. If I have two cycles 1-2-3-4 and 3-4-5-6, then I have only one cycle group because these two cycles share the same edge. What is the most efficient way to find all the cycle groups?

    Read the article

  • Help with a algorithm in linq to resolve a query

    - by Deumber
    I have been some time thinking how to resolve this problem, but out of ideas i prefer expose it for help. I have 2 tables (linq to sql) A and B, A have a many relation with B, so A have a property EntitySet of B A have the following properties: CreateDate (Datetime) ModificateDate (Datetime) Bs (EntitySet<B>) B have the following properties: CreateDate (Datetime) ModificateDate (Datetime) All that i want is return a ordered collection of A by the Max date between : A.CreateDate, A.ModificateDate, The Max B.CreateDate of all B in A The Max B.ModificateDate of all B in A if i someone need a little example, just ask for it.

    Read the article

  • algorithm to make easy my job

    - by gcc
    Iwill tell part of study material task but, dont afraid, I dont want write all of them , I will ask just specific question.okey; User will give me a function with three unknown. example: sin(a+b)+ln(5)*(log(ab)-32/sqrt(abc)) another example for function atan(23/a)-exp(a,b)*(123+asin(ac)) and there are some another input with funtion but in all input a,b and c, are doesnot determined, Anyway,I wont tell the other part,I just asking how I should take the fuction such that I can do my job with easy?

    Read the article

  • suggest an algorithm for the following puzzle!!

    - by garima
    There are n petrol bunks arranged in circle. Each bunk is separated from the rest by a certain distance. You choose some mode of travel which needs 1litre of petrol to cover 1km distance. You can't infinitely draw any amount of petrol from each bunk as each bunk has some limited petrol only. But you know that the sum of litres of petrol in all the bunks is equal to the distance to be covered. ie let P1, P2, ... Pn be n bunks arranged circularly. d1 is distance between p1 and p2, d2 is distance between p2 and p3. dn is distance between pn and p1.Now find out the bunk from where the travel can be started such that your mode of travel never runs out of fuel.

    Read the article

  • Need an algorithm for this problem

    - by Heisenburgor
    There are two integer sequences A[] and B[] of length N,both unsorted. Requirement: through the swapping of elements between A[] and B[], make the difference between {the sum of all elements in A[]} and {the sum of all elements in B[]} to be minimum. Many thanks

    Read the article

  • Algorithm for finding all paths in a NxN grid

    - by Periastron
    Imagine a robot sitting on the upper left hand corner of an NxN grid. The robot can only move in two directions: right and down. How many possible paths are there for the robot? I could find solution to this problem on Google, but I am not very clear with the explanations. I am trying to clearly understand the logic on how to solve this and implement in Java. Any help is appreciated. Update: This is an interview question. For now, I am trying to reach the bottom-right end and print the possible paths.

    Read the article

  • What Math topics & resources to consider as beginner to indulge the book - Introduction to Algorithm

    - by sector7
    I'm a programmer who's beginning to appreciate the knowledge & usability of Algorithms in my work as I move forward with my skill-set. I don't want to take the short path by learning how to apply algorithms "as-is" but would rather like to know the foundation and fundamentals behind them. For that I need Math, at which I'm pretty "basic". I'm considering getting tuition's for that. What I would like is to have a concise syllabus/set of topics/book which I could hand over to my math tutor to get started. HIGHLY DESIRED: one book. the silver bullet. (fingers crossed!) PS: I've got some leads but want to hear you guys/gurus out: Discrete Math, Combinatorics, Graph theory, Calculus, Linear Algebra, and Number Theory. Looking forward to your answers. Thanks!

    Read the article

  • How can I improve the performance of this algorithm

    - by Justin
    // Checks whether the array contains two elements whose sum is s. // Input: A list of numbers and an integer s // Output: return True if the answer is yes, else return False public static boolean calvalue (int[] numbers, int s){ for (int i=0; i< numbers.length; i++){ for (int j=i+1; j<numbers.length;j++){ if (numbers[i] < s){ if (numbers[i]+numbers[j] == s){ return true; } } } } return false; }

    Read the article

  • Need an efficient algorithm solve this kind of complex structure

    - by Rizvan
    Problem Statement is : Given 2 Dimensional array, print output for example If 4 rows and 6 columns, output would be: 1 2 3 4 5 6 16 17 18 19 20 7 15 24 23 22 21 8 14 13 12 11 10 9 I tried it is looking like square within square but when I attempted this problem, I put so many while and if loops but didn't got exact answer. If row and columns increases how to handle it? This is not homework. I was learning solving complex structure so I need to understand it by some guidance.

    Read the article

  • algorithm to find the three majority elements in an array

    - by Qiang Li
    Let's say there are three elements in a non-sorted array all of which appear more than one-fourth times of the total number of elements. What is the most efficient way to find these elements? Both for non-online and online versions of this question. Thank you! Edit The non-online version I was referring to is: this array is specified in full. The online version means the array elements are coming one at a time. I require the space in addition to time complexity to be tight. disclaimer: THIS IS NOT HOMEWORK! I consider this as research-level question.

    Read the article

  • Defining < for STL sort algorithm - operator overload, functor or standalone function?

    - by Andy
    I have a stl::list containing Widget class objects. They need to be sorted according to two members in the Widget class. For the sorting to work, I need to define a less-than comparator comparing two Widget objects. There seems to be a myriad of ways to do it. From what I can gather, one can either: a. Define a comparison operator overload in the class: bool Widget::operator< (const Widget &rhs) const b. Define a standalone function taking two Widgets: bool operator<(const Widget& lhs, const Widget& rhs); And then make the Widget class a friend of it: class Widget { // Various class definitions ... friend bool operator<(const Widget& lhs, const Widget& rhs); }; c. Define a functor and then include it as a parameter when calling the sort function: class Widget_Less : public binary_function<Widget, Widget, bool> { bool operator()(const Widget &lhs, const Widget& rhs) const; }; Does anybody know which method is better? In particular I am interested to know if I should do 1 or 2. I searched the book Effective STL by Scott Meyer but unfortunately it does not have anything to say about this. Thank you for your reply.

    Read the article

  • Can Goldberg algorithm in ocamlgraph be used to find Minimum Cost Flow graph?

    - by Tautrimas
    I'm looking for an implementation to the Minimum Cost Flow graph problem in OCaml. OCaml library ocamlgraph has Goldberg algorithm implementation. The paper called Efficient implementation of the Goldberg-Tarjan minimum-cost flow algorithm is noting that Goldberg-Tarjan algorithm can find minimum cost graph. Question is, does ocamlgraph algorithm also find the minimum cost? Library documentation only states, that it's suitable at least for the maximum flow problem. If not, does anybody have a good link to a nice any minimum cost optimization algorithm code? I will manually translate it into OCaml then. Forgive me, if I missed it on Wikipedia: there are too many algos on flow networks for the first day!

    Read the article

  • Giving a Bomberman AI intelligent bomb placement

    - by Paul Manta
    I'm trying to implement an AI algorithm for Bomberman. Currently I have a working but not very smart rudimentary implementation (the current AI is overzealous in placing bombs). This is the first AI I've ever tried implementing and I'm a bit stuck. The more sophisticated algorithms I have in mind (the ones that I expect to make better decisions) are too convoluted to be good solutions. What general tips do you have for implementing a Bomberman AI? Are there radically different approaches for making the bot either more defensive or offensive? Edit: Current algorithm My current algorithm goes something like this (pseudo-code): 1) Try to place a bomb and then find a cell that is safe from all the bombs, including the one that you just placed. To find that cell, iterate over the four directions; if you can find any safe divergent cell and reach it in time (eg. if the direction is up or down, look for a cell that is found to the left or right of this path), then it's safe to place a bomb and move in that direction. 2) If you can't find and safe divergent cells, try NOT placing a bomb and look again. This time you'll only need to look for a safe cell in only one direction (you don't have to diverge from it). 3) If you still can't find a safe cell, don't do anything. for $(direction) in (up, down, left, right): place bomb at current location if (can find and reach divergent safe cell in current $(direction)): bomb = true move = $(direction) return for $(direction) in (up, down, left, right): do not place bomb at current location if (any safe cell in the current $(direction)): bomb = false move = $(direction) return else: bomb = false move = stay_put This algorithm makes the bot very trigger-happy (it'll place bombs very frequently). It doesn't kill itself, but it does have a habit of making itself vulnerable by going into dead ends where it can be blocked and killed by the other players. Do you have any suggestions on how I might improve this algorithm? Or maybe I should try something completely different? One of the problems with this algorithm is that it tends to leave the bot with very few (frequently just one) safe cells on which it can stand. This is because the bot leaves a trail of bombs behind it, as long as it doesn't kill itself. However, leaving a trail of bombs behind leaves few places where you can hide. If one of the other players or bots decide to place a bomb somewhere near you, it often happens that you have no place to hide and you die. I need a better way to decide when to place bombs.

    Read the article

  • Dynamic Dijkstra

    - by Dani
    I need dynamic dijkstra algorithm that can update itself when edge's cost is changed without a full recalculation. Full recalculation is not an option. I've tryed to "brew" my own implemantion with no success. I've also tryed to find on the Internet but found nothing. A link to an article explaining the algorithm or even it's name will be good. Edit: Thanks everyone for answering. I managed to make algorithm of my own that runs in O(V+E) time, if anyone wishes to know the algorithm just say so and I will post it.

    Read the article

  • algorithm - How to sort a 0/1 array with 2n/3 comparisons?

    - by Jackson Tale
    In Algorithm Design Manual, there is such an excise 4-26 Consider the problem of sorting a sequence of n 0’s and 1’s using comparisons. For each comparison of two values x and y, the algorithm learns which of x < y, x = y, or x y holds. (a) Give an algorithm to sort in n - 1 comparisons in the worst case. Show that your algorithm is optimal. (b) Give an algorithm to sort in 2n/3 comparisons in the average case (assuming each of the n inputs is 0 or 1 with equal probability). Show that your algorithm is optimal. For (a), I think it is fairly easy. I can choose a[n-1] as pivot, then do something like in quicksort partition, scan 0 to n - 2, find the middle point where left side is all 0 and right side is all 1, this take n - 1 comparisons. But for (b), I can't get a clue. It says "each of the n inputs is 0 or 1 with equal probability", so I guess I can assume the numbers of 0 and 1 equal? But how can I get a result which is related to 1/3? divide the whole array into 3 groups? Thanks

    Read the article

  • Is there an efficient algorithm to distribute resources in a way that both avoids conflict and allows bias?

    - by Steve V.
    Background (Skip this if you only care about the algorithm) At the university where I work, one of the biggest hassles in our department is classroom scheduling. For illustration purposes and to lay out the scope of the problem, here's how we do scheduling now: Professors give us a list of the classes they're teaching with the time slots they'd prefer to teach, ranked in order of priority (most desired to least desired). Administration gives us a list of the rooms we may assign along with the times those rooms are available for our department's use. We start assigning professors to rooms trying (at first) to take into account the preferences of the various professors. Inevitably, conflicts arise, professors start asking for changes, and the plan falls to pieces somewhere around professor number 30, at which point we start assigning rooms basically wherever we can fit them in, crumpled pieces of paper are everywhere, and nobody's happy. (If you've ever wondered why your class was at 9.30 in the morning on Thursday but 4 pm every other day, now you know) I have been asked to quietly investigate whether software could do this more optimally. The Actual Question Is there an algorithm to efficiently schedule a set of resources such that the following criteria are met: The algorithm must never assign two professors to the same room at the same time. The task is not complete until every professor has been assigned a room / time. The algorithm need not worry about having too many professors for the amount of time slots available. (We're not that well funded.) As much as is possible the algorithm should respect the scheduling preferences of the individual professors. I feel like I can't be the first one to ask this. Is there a efficient algorithm for this, or is this the sort of problem that can only be brute-forced?

    Read the article

  • Function templates for arbitrary STL containers containing arbitrary types.

    - by Chad Brewbaker
    I have an arbitrary STL container C, which contains elements of an arbitrary type T. I want to create an std::vector that has a copy of all the elements. What is the cleanest way to do this? template <typename C> void myfunction(C container){ /*Derive the type T of elements within the container*/ std::vector<T> mystack; /* Iterate over container and push_back() the elements into mystack*/ }

    Read the article

< Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >