Search Results

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

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

  • how to find out if a shape is passable

    - by jd
    I have a complex polygon (possibly concave) and a few of its edges marked as entry/exit points. there is a possibility that inside this polygon may lie one or more blockades of arbitrary shape. what approaches could I use to determine whether a path of certain width exists between a pair of entry/exit edges? having read through the question it looks like a homework type - it is not. I just wish to have a at least a few leads I could pursue, as this is new to me.

    Read the article

  • please help me to implement such kind of sort

    - by davit-datuashvili
    hi i need to write sucj kind of sorting maybe it is similary to radix sort and also (this is not homework because i created it problem myself and please if anobody can help me) problem is like this suppose i have array int x[]=new int[]{4,5,3,2,1}; let write it into binary form 5 -0101 4- 0100 3-0011 2-0010 1-0001 i want to sort this elements by using bitwise operatos or check each bit and if less exchange it can anybody help me for example take 5 and 4 check first rightmost bit 0==0 so continue in the 1 index also 1==1 next the same 0=0 and last one 10 it means that first element is greater then second so exchange it please help me

    Read the article

  • Structure of Astar (A*) graph search data in C#

    - by Shawn Mclean
    How do you structure you graphs/nodes in a graph search class? I'm basically creating a NavMesh and need to generate the nodes from 1 polygon to the other. The edge that joins both polygons will be the node. I'll then run A* on these Nodes to calculate the shortest path. I just need to know how to structure my classes and their properties? I know for sure I wont need to create a fully blown undirected graph with nodes and edges.

    Read the article

  • Constructing a tree using Python

    - by stealthspy
    I am trying to implement a unranked boolean retrieval. For this, I need to construct a tree and perform a DFS to retrieve documents. I have the leaf nodes but I am having difficulty to construct the tree. Eg: query = OR ( AND (maria sharapova) tennis) Result: OR | | AND tennis | | maria sharapova I traverse the tree using DFS and calculate the boolean equivalent of certain document ids to identify the required document from the corpus. Can someone help me with the design of this using python? I have parsed the query and retrieved the leaf nodes for now.

    Read the article

  • Reduce text length to fit cell width in a smart manner

    - by Andrei Ciobanu
    Hello, I am in project where we are building a simple web calendar using Java EE technologies. We define a table where every row is an employee, and every column represents an hour interval. The table width and column widths are adjustable. In every cell we have a text retrieved from a database, indicating what the employee is doing / should do in that time interval. The problem is that sometimes the text in cells is getting bigger than the actual cell. My task is to make the text more "readable" by reducing it's length in a "smart way" so that it can fit in the cell more "gracefully". For example if initially in a cell I have: "Writing documents", after the resize I should retrieve: "Wrtng. dcmnts" or "Writ. docum." so that the text can fit well. Is there a smart way to do it ? Or removing vocals / split the string in two is enough ?

    Read the article

  • How to store and collect data for mining such information as most viewed for last 24 hours, last 7 d

    - by Kirzilla
    Hello, Let's imagine that we have high traffic project (a tube site) which should provide sorting using this options (NOT IN REAL TIME). Number of videos is about 200K and all information about videos is stored in MySQL. Number of daily video views is about 1.5KK. As instruments we have Hard Disk Drive (text files), MySQL, Redis. Views top viewed top viewed last 24 hours top viewed last 7 days top viewed last 30 days top rated last 365 days How should I store such information? The first idea is to log all visits to text files (single file per hour, for example visits_20080101_00.log). At the beginning of each hour calculate views per video for previous hour and insert this information into MySQL. Then recalculate totals (for last 24 hours) and update statistics in tables. At the beginning of every day we have to do the same but recalculate for last 7 days, last 30 days, last 365 days. This method seems to be very poor for me because we have to store information about last 365 days for each video to make correct calculations. Is there any other good methods? Probably, we have to choose another instruments for this? Thank you.

    Read the article

  • What is the most efficient method to find x contiguous values of y in an array?

    - by Alec
    Running my app through callgrind revealed that this line dwarfed everything else by a factor of about 10,000. I'm probably going to redesign around it, but it got me wondering; Is there a better way to do it? Here's what I'm doing at the moment: int i = 1; while ( ( (*(buffer++) == 0xffffffff && ++i) || (i = 1) ) && i < desiredLength + 1 && buffer < bufferEnd ); It's looking for the offset of the first chunk of desiredLength 0xffffffff values in a 32 bit unsigned int array. It's significantly faster than any implementations I could come up with involving an inner loop. But it's still too damn slow.

    Read the article

  • Routing algorithm

    - by isaac
    Hello, I'm giving a presentation about computer routing and I want to make a good analogy with a real-world situation. However, I could not find it. Do you have in mind any of the situations like the computer routing. If yes, could you please provide me with it

    Read the article

  • Find all A^x in a given range

    - by Austin Henley
    I need to find all monomials in the form AX that when evaluated falls within a range from m to n. It is safe to say that the base A is greater than 1, the power X is greater than 2, and only integers need to be used. For example, in the range 50 to 100, the solutions would be: 2^6 3^4 4^3 My first attempt to solve this was to brute force all combinations of A and X that make "sense." However this becomes too slow when used for very large numbers in a big range since these solutions are used in part of much more intensive processing. Here is the code: def monoSearch(min, max): base = 2 power = 3 while 1: while base**power < max: if base**power > min: print "Found " + repr(base) + "^" + repr(power) + " = " + repr(base**power) power = power + 1 base = base + 1 power = 3 if base**power > max: break I could remove one base**power by saving the value in a temporary variable but I don't think that would make a drastic effect. I also wondered if using logarithms would be better or if there was a closed form expression for this. I am open to any optimizations or alternatives to finding the solutions.

    Read the article

  • Finding whether a point lies inside a rectangle or not

    - by avd
    The rectangle can be oriented in any way...need not be axis aligned. Now I want to find whether a point lies inside the rectangle or not. One method I could think of was to rotate the rectangle and point coordinates to make the rectangle axis aligned and then by simply testing the coordinates of point whether they lies within that of rectangle's or not. The above method requires rotation and hence floating point operations. Is there any other efficient way to do this??

    Read the article

  • How would I use for_each to delete every value in an STL map?

    - by stusmith
    Suppose I have a STL map where the values are pointers, and I want to delete them all. How would I represent the following code, but making use of std::for_each? I'm happy for solutions to use Boost. for( stdext::hash_map<int, Foo *>::iterator ir = myMap.begin(); ir != myMap.end(); ++ir ) { delete ir->second; // delete all the (Foo *) values. } (I've found Boost's checked_delete, but I'm not sure how to apply that to the pair<int, Foo *> that the iterator represents). (Also, for the purposes of this question, ignore the fact that storing raw pointers that need deleting in an STL container isn't very sensible).

    Read the article

  • How can we find second maximum from array efficiently?

    - by Xinus
    Is it possible to find the second maximum number from an array of integers by traversing the array only once? As an example, I have a array of five integers from which I want to find second maximum number. Here is an attempt I gave in the interview: #define MIN -1 int main() { int max=MIN,second_max=MIN; int arr[6]={0,1,2,3,4,5}; for(int i=0;i<5;i++){ cout<<"::"<<arr[i]; } for(int i=0;i<5;i++){ if(arr[i]>max){ second_max=max; max=arr[i]; } } cout<<endl<<"Second Max:"<<second_max; int i; cin>>i; return 0; } The interviewer, however, came up with the test case int arr[6]={5,4,3,2,1,0};, which prevents it from going to the if condition the second time. I said to the interviewer that the only way would be to parse the array two times (two for loops). Does anybody have a better solution?

    Read the article

  • A data structure based on the R-Tree: creating new child nodes when a node is full, but what if I ha

    - by Tom
    I realize my title is not very clear, but I am having trouble thinking of a better one. If anyone wants to correct it, please do. I'm developing a data structure for my 2 dimensional game with an infinite universe. The data structure is based on a simple (!) node/leaf system, like the R-Tree. This is the basic concept: you set howmany childs you want a node (a container) to have maximum. If you want to add a leaf, but the node the leaf should be in is full, then it will create a new set of nodes within this node and move all current leafs to their new (more exact) node. This way, very populated areas will have a lot more subdivisions than a very big but rarely visited area. This works for normal objects. The only problem arises when I have more than maxChildsPerNode objects with the exact same X,Y location: because the node is full, it will create more exact subnodes, but the old leafs will all be put in the exact same node again because they have the exact same position -- resulting in an infinite loop of creating more nodes and more nodes. So, what should I do when I want to add more leafs than maxChildsPerNode with the exact same position to my tree? PS. if I failed to explain my problem, please tell me, so I can try to improve the explanation.

    Read the article

  • Heap Algorithmic Issue

    - by OberynMarDELL
    I am having this algorithmic problem that I want to discuss about. Its not about find a solution but about optimization in terms of runtime. So here it is: Suppose we have a race court of Length L and a total of N cars that participate on the race. The race rules are simple. Once a car overtakes an other car the second car is eliminated from the race. The race ends when no more overtakes are possible to happen. The tricky part is that the k'th car has a starting point x[k] and a velocity v[k]. The points are given in an ascending order, but the velocities may differ. What I've done so far: Given that a car can get overtaken only by its previous, I calculated the time that it takes for each car to reach its next one t = (x[i] - x[i+1])/(v[i] - v[i+1]) and I insert these times onto a min heap in O(n log n). So in theory I have to pop the first element in O(logn), find its previous, pop it as well , update its time and insert it in the heap once more, much like a priority queue. My main problem is how I can access specific points of a heap in O(log n) or faster in order to keep the complexity in O(n log n) levels. This program should be written on Haskell so I would like to keep things simple as far as possible EDIT: I Forgot to write the actual point of the race. The goal is to find the order in which cars exit the game

    Read the article

  • Question about permute-by-sorting

    - by davit-datuashvili
    In the book "Introduction to Algorithms", second edition, there is the following problem: Suppose we have some array: int a[] = {1,2,3,4} and some random priorities array: P = {36,3,97,19} and the goal is to permute the array a randomly using this priorities array. This is the pseudo code: PERMUTE-BY-SORTING (A) 1 n ? length[A] 2 for i ? 1 to n 3 do P[i] = RANDOM (1, n 3) 4 sort A, using P as sort keys 5 return A The result should be the permuted array: B={2, 4, 1, 3}; I have written this code: import java.util.*; public class Permute { public static void main (String[] args) { Random r = new Random(); int a[] = new int[] {1,2,3,4}; int n = a.length; int b[] = new int[a.length]; int p[] = new int[a.length]; for (int i=0; i<p.length; i++) { p[i] = r.nextInt(n*n*n) + 1; } // for (int i=0;i<p.length;i++){ // System.out.println(p[i]); //} } } How do I continue?

    Read the article

  • How to optimize this simple function which translates input bits into words?

    - by psihodelia
    I have written a function which reads an input buffer of bytes and produces an output buffer of words where every word can be either 0x0081 for each ON bit of the input buffer or 0x007F for each OFF bit. The length of the input buffer is given. Both arrays have enough physical place. I also have about 2Kbyte free RAM which I can use for lookup tables or so. Now, I found that this function is my bottleneck in a real time application. It will be called very frequently. Can you please suggest a way how to optimize this function? I see one possibility could be to use only one buffer and do in-place substitution. void inline BitsToWords(int8 *pc_BufIn, int16 *pw_BufOut, int32 BufInLen) { int32 i,j,z=0; for(i=0; i<BufInLen; i++) { for(j=0; j<8; j++, z++) { pw_BufOut[z] = ( ((pc_BufIn[i] >> (7-j))&0x01) == 1? 0x0081: 0x007f ); } } } Please do not offer any compiler specific or CPU/Hardware specific optimization, because it is a multi-platform project.

    Read the article

  • How to prove worst-case number of inversions in a heap is O(nlogn)?

    - by Jacques
    I am busy preparing for exams, just doing some old exam papers. The question below is the only one I can't seem to do (I don't really know where to start). Any help would be appreciated greatly. Use the O(nlogn) comparison sort bound, the theta(n) bound for bottom-up heap construction, and the order complexity if insertion sort to show that the worst-case number of inversions in a heap is O(nlogn).

    Read the article

  • R implementation of sorting by reversals

    - by user1357015
    I was wondering if there is an implementation in R where it sorts a permutation of n numbers into the original 1...n sequence and provides the number of reversals needed. Eg an implementation of the "sorting by reversals" or "sorting by translocation" as outlined in this ppt. Specifically, I have a permutation of a sequence of n elements, pi(n), and I want to figure out how close it is to the original sequence. The number of reversals seems a good metric. Thanks!

    Read the article

  • Finding the longest road in a Settlers of Catan game algorithmically

    - by Jay
    I'm writing a Settlers of Catan clone for a class. One of the extra credit features is automatically determining which player has the longest road. I've thought about it, and it seems like some slight variation on depth-first search could work, but I'm having trouble figuring out what to do with cycle detection, how to handle the joining of a player's two initial road networks, and a few other minutiae. How could I do this algorithmically? For those unfamiliar with the game, I'll try to describe the problem concisely and abstractly: I need to find the longest possible path in an undirected cyclic graph.

    Read the article

  • Count double palindromes in given int sequence

    - by jakubmal
    For a given int sequence check number of double palindromes, where by double palindrome we mean sequence of two same palindromes without break between them. So for example: in 1 0 1 1 0 1 we have 1 0 1 as a palindrome which appears 2 times without a break, in 1 0 1 5 1 0 1 we have 1 0 1 but it's separated (apart from the other palindromes in these sequences) Problem example test data is: 3 12 0 1 1 0 0 1 1 0 0 1 1 0 12 1 0 1 0 1 0 1 0 1 0 1 0 6 3 3 3 3 3 3 with answers 8 0 9 Manacher is obvious for the begging, but I'm not sure what to do next. Any ideas appreciated. Complexity should be below n^2 I guess. EDIT: int is here treated as single element of alphabet

    Read the article

  • question about tree

    - by davit-datuashvili
    i have question for example i want to implement binary tree with array i want understand what will indexes for left child and rigth child ?my array is 0 based i want implement searching in tree using array can anybody help me?

    Read the article

  • question on HyperOperation

    - by davit-datuashvili
    i am trying to solve following recurence program http://en.wikipedia.org/wiki/Hyper_operator here is my code i know it has mistakes but i have done what i could public class hyper{ public static int Hyper(int a,int b,int n){ int t=0; if ( n==0) return b+1; if ((n==1) &&(b==0)) return a; if ((n==2) && (b==0)) return 0; if ((n>=3) && (b==0)) return 1; t=Hyper(a,b-1,n); return Hyper (a,t,n-1); } public static void main(String[]args){ int n=3; int a=5; int b=7; System.out.println(Hyper(a,b,n)); } } please help

    Read the article

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