Search Results

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

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

  • determine if line segment is inside polygon

    - by dato
    suppose we have simple polygon(without holes) with vertices (v0,v1,....vn) my aim is to determine if for given point p(x,y) any line segment connecting this point and any vertices of polygon is inside polygon or even for given two point p(x0,y0) `p(x1,y1)` line segment connecting these two point is inside polygon? i have searched many sites about this ,but i am still confused,generally i think we have to compare coordinates of vertices and by determing coordinates of which point is less or greater to another point's coordinates,we could determine location of any line segment,but i am not sure how correct is this,please help me

    Read the article

  • How to calculate the state of a graph?

    - by zcb
    Given a graph G=(V,E), each node i is associated with 'Ci' number of objects. At each step, for every node i, the Ci objects will be taken away by the neighbors of i equally. After K steps, output the number of objects of the top five nodes which has the most objects. Some Constrains: |V|<10^5, |E|<2*10^5, K<10^7, Ci<1000 My current idea is: represent the transformation in each step with a matrix. This problem is converted to the calculation of the power of matrix. But this solution is much too slow considering |V| can be 10^5. Is there any faster way to do it?

    Read the article

  • generate k distinct number less then n

    - by davit-datuashvili
    hi i have following question task is this generate k distinct positive numbers less then n without duplication my method is following first create array size of k where we should write these numbers int a[]=new int[k]; //now i am going to cretae another array where i check if (at given number position is 1 then generate number again else put this number in a array and continue cycle i put here a piece of code and explanations int a[]=new int[k]; int t[]=new int[n+1]; Random r=new Random(); for (int i==0;i<t.length;i++){ t[i]=0;//initialize it to zero } int m=0;//initialize it also for (int i=0;i<a.length;i++){ m=r.nextInt(n);//random element between 0 and n if (t[m]==1){ //i have problem with this i want in case of duplication element occurs repeats this steps afain until there will be different number else{ t[m]=1; x[i]=m; } } so i fill concret my problem if t[m]==1 it means that this element occurs already so i want to generate new number but problem is that number of generated numbers will not be k beacuse if i==0 and occurs duplicate element and we write continue then it will switch at i==1 i need like goto for repeat step or for (int i=0;i<x.length;i++){ loop: m=r.nextInt(n); if ( x[m]==1){ continue loop; } else{ x[m]=1; a[i]=m; continue;//continue next step at i=1 and so on } } i need this code in java please help

    Read the article

  • Given a 2d array sorted in increasing order from left to right and top to bottom, what is the best w

    - by Phukab
    I was recently given this interview question and I'm curious what a good solution to it would be. Say I'm given a 2d array where all the numbers in the array are in increasing order from left to right and top to bottom. What is the best way to search and determine if a target number is in the array? Now, my first inclination is to utilize a binary search since my data is sorted. I can determine if a number is in a single row in O(log N) time. However, it is the 2 directions that throw me off. Another solution I could use, if I could be sure the matrix is n x n, is to start at the middle. If the middle value is less than my target, then I can be sure it is in the left square portion of the matrix from the middle. I then move diagnally and check again, reducing the size of the square that the target could potentially be in until I have honed in on the target number. Does anyone have any good ideas on solving this problem? Example array: Sorted left to right, top to bottom. 1 2 4 5 6 2 3 5 7 8 4 6 8 9 10 5 8 9 10 11

    Read the article

  • Weakly connected balanced digraph

    - by user1074557
    How can I prove that if a balanced digraph is weakly connected, then it is also strongly connected? (balanced digraph means that for every node, it's indegree and outdegree is the same and weakly connected means the non-directed version of this graph is connected). What I can think of so far is: if the graph is balanced, it means it is a union of directed cycles. So if I remove any cycle, it will stay balanced. Also each vertex in the cycle has one edge coming into it and one edge leading out of it.. Then I guess I need to use some contradiction or induction to prove that the graph is strongly connected.. That's where I confused.

    Read the article

  • C# compare algorithms

    - by public static
    Hi, Are there any open source algorithms in c# that solve the problem of creating a difference between two text files? It would be super cool if it had some way of highlighting what exact areas where changed in the text document also.

    Read the article

  • How to find the largest power of 2 less than the given number

    - by nazar_art
    I need to find the largest power of 2 less than the given number. And I stuck and can't find any solution. Code: public class MathPow { public int largestPowerOf2 (int n) { int res = 2; while (res < n) { res =(int)Math.pow(res, 2); } return res; } } This doesn't work correctly. Testing output: Arguments Actual Expected ------------------------- 9 16 8 100 256 64 1000 65536 512 64 256 32 How to solve this issue?

    Read the article

  • Special simple random number generator

    - by psihodelia
    How to create a function, which on every call generates a random integer number? This number must be most random as possible (according to uniform distribution). It is only allowed to use one static variable and at most 3 elementary steps, where each step consists of only one basic arithmetic operation of arity 1 or 2. Example: int myrandom(void){ static int x; x = some_step1; x = some_step2; x = some_step3; return x; } Basic arithmetic operations are +,-,%,and, not, xor, or, left shift, right shift, multiplication and division. Of course, no rand(), random() or similar staff is allowed.

    Read the article

  • i have question about job

    - by davit-datuashvili
    hi i will explain my situation i am study algorithms and data structures and i know many thing practical and others most thoereticaly and trying to implement in practise i want to get job where i will study more quickly i am interested if i have chance to start job when i have not expierence? thanks please advise what to do

    Read the article

  • How to implement Pentago AI algorithm

    - by itsho
    Hi, i'm trying to develop Pentago-game in c#. right now i'm having 2 players mode which working just fine. the problem is, that i want One player mode (against computer), but unfortunately, all implements of minimax / negamax are for one step calculated. butin Pentago, every player need to do two things (place marble, and rotate one of the inner-boards) I didn't figure out how to implement both rotate part & placing the marble, and i would love someone to guide me with this. if you're not familiar with the game, here's a link to the game. if anyone want's, i can upload my code somewhere if that's relevant. thank you very much in advance

    Read the article

  • Algorithms after load-balancer?

    - 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

  • Java: Efficient Equivalent to Removing while Iterating a Collection

    - by Claudiu
    Hello everyone. We all know you can't do this: for (Object i : l) if (condition(i)) l.remove(i); ConcurrentModificationException etc... this apparently works sometimes, but not always. Here's some specific code: public static void main(String[] args) { Collection<Integer> l = new ArrayList<Integer>(); for (int i=0; i < 10; ++i) { l.add(new Integer(4)); l.add(new Integer(5)); l.add(new Integer(6)); } for (Integer i : l) { if (i.intValue() == 5) l.remove(i); } System.out.println(l); } This, of course, results in: Exception in thread "main" java.util.ConcurrentModificationException ...even though multiple threads aren't doing it... Anyway. What's the best solution to this problem? "Best" here means most time and space efficient (I realize you can't always have both!) I'm also using an arbitrary Collection here, not necessarily an ArrayList, so you can't rely on get.

    Read the article

  • All possibilities in 2d array

    - by valli-R
    I have this array: $array = array ( array('1', '2', '3'), array('!', '@'), array('a', 'b', 'c', 'd'), ); And I want to know all character combination of sub arrays.. for example : 1!a 1!b 1!c 1!d 1@a 1@b 1@c 1@d 2!a 2!b 2!c 2!d 2@a 2@b ... Currently I am having this code : for($i = 0; $i < count($array[0]); $i++) { for($j = 0; $j < count($array[1]); $j++) { for($k = 0; $k < count($array[2]); $k++) { echo $array[0][$i].$array[1][$j].$array[2][$k].'<br/>'; } } } It works, but I think it is ugly, and when I am adding more arrays, I have to add more for. I am pretty sure there is a way to do this recursively, but I don't know how to start/how to do it. A little help could be nice! Thanks you!

    Read the article

  • longest increasing subsequent

    - by davit-datuashvili
    i have write this code is it correct? public class subsequent{ public static void main(String[] args){ int a[]=new int[]{0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15}; int a_b[]=new int[a.length]; a_b[0]=1; int int_max=0; int int_index=0; for (int i=0;i<a.length;i++){ for (int j=0;j<i;j++){ if (a[i]>a[j] && a_b[i]<(a_b[j]+1)){ a_b[i]=a_b[j]+1; } } if (a_b[i]>int_max){ int_max=a_b[i]; int_index=i; } } int k=int_max+1; int list[]=new int[k]; for (int i=int_index;i>0;i--){ if (a_b[i]==k-1){ list[k-1]=a[i]; k=a_b[i]; } } for (int g=0;g<list.length;g++){ System.out.println(list[g]); } } }

    Read the article

  • Interview Q: given an array of numbers, return array of products of all other numbers (no division)

    - by polygenelubricants
    I was asked this question in a job interview, and I'd like to know how others would solve it. I'm most comfortable with Java, but solutions in other languages are welcome. Given an array of numbers, nums, return an array of numbers products, where products[i] is the product of all nums[j], j != i. Input : [1, 2, 3, 4, 5] Output: [(2*3*4*5), (1*3*4*5), (1*2*4*5), (1*2*3*5), (1*2*3*4)] = [120, 60, 40, 30, 24] You must do this in O(N) without using division.

    Read the article

  • Programmatically determine the relative "popularities" of a list of items (books, songs, movies, etc

    - by Horace Loeb
    Given a list of (say) songs, what's the best way to determine their relative "popularity"? My first thought is to use Google Trends. This list of songs: Subterranean Homesick Blues Empire State of Mind California Gurls produces the following Google Trends report: (to find out what's popular now, I restricted the report to the last 30 days) Empire State of Mind is marginally more popular than California Gurls, and Subterranean Homesick Blues is far less popular than either. So this works pretty well, but what happens when your list is 100 or 1000 songs long? Google Trends only allows you to compare 5 terms at once, so absent a huge round-robin, what's the right approach? Another option is to just do a Google Search for each song and see which has the most results, but this doesn't really measure the same thing

    Read the article

  • Minimizing distance to a weighted grid

    - by Andrew Tomazos - Fathomling
    Lets suppose you have a 1000x1000 grid of positive integer weights W. We want to find the cell that minimizes the average weighted distance.to each cell. The brute force way to do this would be to loop over each candidate cell and calculate the distance: int best_x, best_y, best_dist; for x0 = 1:1000, for y0 = 1:1000, int total_dist = 0; for x1 = 1:1000, for y1 = 1:1000, total_dist += W[x1,y1] * sqrt((x0-x1)^2 + (y0-y1)^2); if (total_dist < best_dist) best_x = x0; best_y = y0; best_dist = total_dist; This takes ~10^12 operations, which is too long. Is there a way to do this in or near ~10^8 or so operations?

    Read the article

  • question about permut-by-sorting

    - by davit-datuashvili
    hi i have following question from book introduction in algorithms second edition there is such problem suppose we have some array A int a[]={1,2,3,4} and we have some random priorities array P={36,3,97,19} we shoud permut array a randomly using this priorities array here is pseudo code P ERMUTE -B Y-S ORTING ( A) 1 n ? length[A] 2 for i ? 1 to n do P[i] = R ANDOM(1, n 3 ) 3 4 sort A, using P as sort keys 5 return A and result will be permuted array B={2, 4, 1, 3}; please help any ideas i have done this code and need aideas how continue import java.util.*; public class Permut { 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]); //} } } please help

    Read the article

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