Is there a way to geometrically compute the intersection points of a line and an arbitrary graphics path? I know where all of the lines and curves are in the path, and I am using the HTML5 canvas element if that helps any. Basically, I have access to all of the canvas drawing commands and their arguments. For instance, if the API was c...
Hi!
This is a counting sort algorithm. I want to change the last for loop of it to for j<---1 to n.
I know that this will be correct, but I want to show this for one of my friends. How can I write my reason for it? Please help me! Thanks.
Counting Sort(A[1,..n]) //C[1,...k] is the temporary memory and k is the range of integers
...
I'm wondering what the consensus is on the definition of "ancestor" in a computer science context.
I only ask because in Introduction to Algorithms, Second Edition, p. 259 there is a description of the algorithm Tree-Successor(x) that seems odd. In finding the successor of node x,
[...] if the right subtree of node x is empty and x ...
Hi All,
I have to implement an algorithm that generates a timetable for a university. I've searched and found a lot of algorithms. But here is the problem. I need an algorithm that generates a timetable for the whole semester, not on a weekly base. It should also consider the predefined order of the course's parts, e.g. exercise 1 shou...
Hi
I have found this question in the one site which was about counting sort algorithm and this question was an exercise ! I solved this and I want to know that is this correct?
Exercise:
Use The idea of Counting Sort algorithm and provide an algorithm with n integer in the range 0 to k, in time O (1) replied that how many of these n ele...
class Node:
'''represents a new node in the BST'''
def __init__(self,key):
self.key=key
self.disconnect()
def disconnect(self):
self.left=None;
self.right=None;
self.parent=None;
def __str__(self):
return 'node with kay %s'%self.key
class BST:
def __init__(self):
...
I know some programming. I know little bit of Java, I know some C#, I know some GW Basic. I've followed those 30 minute Ruby, Python tutorials and so on. I took some computer courses in college but didn't take them very seriously at that time. After I finished school, I got an IT job but my luck (or bad luck) I ended up doing non-coding ...
I am working on an algorithm to score individual players in a team-based game. The problem is that no fixed teams exist - every time 10 players want to play, they are divided into two (somewhat) even teams and play each other. For this reason, it makes no sense to score the teams, and instead we need to rely on individual player ratings....
I know some programming. I know little bit of Java, I know some C#, I know some GW Basic. I've followed those 30 minute Ruby, Python tutorials and so on. I took some computer courses in college but didn't take them very seriously at that time. After I finished school, I got an IT job but my luck (or bad luck) I ended up doing non-coding ...
I would like to genrate a random permutation as fast as possible.
The problem: The knuth shuffle which is O(n) involves generating n random numbers.
Since generating random numbers is quite expensive.
I would like to find an O(n) function involving a fixed O(1) amount of random numbers.
I realize that this question has been asked before...
If I have an integer in Java how do I count how many bits are zero except for leading zeros?
We know that integers in Java have 32 bits but counting the number of set bits in the number and then subtracting from 32 does not give me what I want because this will also include the leading zeros.
As an example, the number 5 has one zero bi...
This a question I found in the Wikipedia site (I want to learn sort algorithms very well). Anyway, this is a question - could you explain to me how I can show it?
Exercise: Show that Algorithm Insertion Sort (A) runs in time O(n + I) given that I is the number of inversions in the array A.
...
Hi
this is my question and I write an algorithm for it I want to know that this algorithm is correct??
thanks!!
Question:
*a numbers of arrays are given to me and I should sort them based on "they are ordered" , for example an array that is in the right order comes at first, and an array that it elements are in the reverse order comes...
I have a task to create a crossword, a specific one. All the answers are given, but their places are unknown. Program must read a file with board scheme like this :
0 1 0 0 0 0 0 0 1 0 0
0 1 0 1 1 1 1 1 1 1 1
0 1 0 1 0 0 1 0 1 0 1
0 S 1 1 0 1 1 1 1 0 1
0 1 0 0 1 0 1 0 1 0 0
1 1 1 1 1 1 1 S 1 1 0
0 0 0 0 1 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0...
To test if an unsigned integer is of the form 2^n-1 we use:
x&(x+1)
What is that supposed to equal? That is,
x&(x+1) == ?
...
I need to read from a dataset which is very large, highly interlinked, the data is fairly localized, and reads are fairly expensive. Specifically:
The data sets are 2gigs - 30gigs in size, so I have to map sections of the file into memory to read. This is very expensive compared to the rest of the work I do in the algorithm. From pr...
I have a set of given integers:
A[] = { 2, 3, 4, 5, 6, 7, 8, 10, 15, 20, 25, 30, 40, 50, 100, 500 }
I want to check if a given integer T can be written as a multiple of the numbers in A[];
EDIT CLARIFICATION:
any number in A[] can be used.If used can be used only one time.
EX 60 is a valid T.60=30*2.
AlSO 90 is valid . 90=3*5*6
Check...
Given two arrays A[n] and B[m], how can I find the smallest window in A that contains all the elements of B.
I am trying to solve this problem in O(n) time but I am having problem doing it. Is there any well know algorithm or procedure for solving it.
...
I have a std::vector of function objects. Each object can take an int, so I can say obj(4) and get an int result. How can I use the algorithm for_each to work on each element of the vector?
...
I have a time represented as a floating-point number (in seconds). I need a function to convert this representation to string format. Somethins like this:
/// <summary>
/// Get time from a float representation.
/// </summary>
/// <param name="f">Time in a floating-point number.</param>
/// <returns>Time in a string f...