I'm looking to use a rolling hash function so I can take hashes of n-grams of a very large string.
For example:
"stackoverflow", broken up into 5 grams would be:
"stack", "tacko", "ackov", "ckove",
"kover", "overf", "verfl", "erflo", "rflow"
This is ideal for a rolling hash function because after I calculate the first n-gram ha...
Hey,
I am trying to implement a red-black tree in C#. I already created an object called sRbTreeNode which has a String key, Color, Left, Right and Parent properties.
I successfully managed implementing the methods Insert, InsertFixUp, LeftRotate, RightRotate, Delete, and now im having trouble with the method DeleteFixUp.
DeleteFixUp i...
Hi,
I've been playing around with Scala recently and was thinking about how to implement a generic version of quicksort in it (just to get a better feeling for the language)
I came up with something like this
object Main {
def qs[T](a: List[T], f: (T, T) => Boolean): List[T] = {
if (a == Nil) return a
val (l, g) = a drop 1 ...
To be up front, this is homework. That being said, it's extremely open ended and we've had almost zero guidance as to how to even begin thinking about this problem (or parallel algorithms in general). I'd like pointers in the right direction and not a full solution. Any reading that could help would be excellent as well.
I'm working on ...
I've been reading up on Decision Trees and Cross Validation, and I understand both concepts. However, I'm having trouble understanding Cross Validation as it pertains to Decision Trees. Essentially Cross Validation allows you to alternate between training and testing when your dataset is relatively small to maximize your error estimation...
I'm stumped by the following homework question for an algorithms class:
Suppose that we are given a sequence
of n values x1, x2 ... xn, and seek to
quickly answer repeated queries of the
form: given i and j, find the smallest
value in xi... xj
Design a data structure that uses O(n)
space and answers queries in O(log n)...
Hi everyone,
I was wondering if anyone could suggest to me how to implement this loop in the following pseudocode:
8: loop
9: while f[0] = 0 do
10: for i = 1 to N do
11: f[i ¡ 1] = f[i]
12: c[N + 1 - i] = c[N - i]
13: end for
14: f[N] = 0
15: c[0] = 0
16: k = k + 1
17: end while
18: if deg(f) = 0 then
19: go...
I have the following Quicksort that always chooses the first element of the subsequence as its pivot:
void qqsort(int array[], int start, int end) {
int i = start; // index of left-to-right scan
int k = end; // index of right-to-left scan
if (end - start >= 1) { // check that there are at least two elements to sort
...
Hello everybody.
My question regards the existence of a search algorithm for searching source code. In my project, I will have to implement an application that will search through a repository of source code (through a lot of source code files). All the files are from previous projects done within the company. We think that implementing...
In my application I have a variety of date sequences, such as Weekly, Monthly and Annually. Given an arbitrary date in the past, I need to calculate the next future date in the sequence.
At the moment I'm using a sub-optimal loop. Here's a simplified example (in Ruby/Rails):
def calculate_next_date(from_date)
next_date = from_date...
I am working on an AI bot for the game Defcon. The game has cities, with varying populations, and defensive structures with limited range. I'm trying to work out a good algorithm for placing defence towers.
Cities with higher populations are more important to defend
Losing a defence tower is a blow, so towers should be placed reasonabl...
First off, let me say that this is not homework (I am an A-Level student, this is nothing close to what we problem solve (this is way harder)), but more of a problem I'm trying to suss out to improve my programming logic.
I thought of a scenario where there is an array of random integers, let's for example say 10 integers. The user will...
Hi, I'm curious if there is a specific graph algorithm that traverses an unweighted acyclic directed graph by choosing a start node and then proceeding via DFS. If a node is encountered that has unsearched predecessors then it should back track the incoming paths until all paths to start have been explored.
I found a wikipedia category...
Here's a breakdown on the union/find algorithm for disjoint set forests on wikipedia:
Barebone disjoint-set forests... (O(n))
... with union by rank ... (now improved to O(log(n))
... with path compression (now improved to O(a(n)), effectively O(1))
Implementing union by rank necessitates that each node keeps a rank field for com...
What technology goes in behind the screens of Amazon recommendation technology? I believe that Amazon recommendation is currently the best in the market, but how do they provide us with such relevant recommendations?
Recently, we have been involved with similar recommendation kind of project, but would surely like to know about the in a...
Hello I am trying to get the efficiency for Strassen's algorithm but need some help.
The recurrence relation for the algorithm is the following:
A(n) = 7A(n/2)+18(n/2)^2, for n>1, A(1) = 0.
I've solved it to the point where I have
a(n) = 6( 7^(log base(2) n) - 4^(log base(2) n) )
Does this mean the efficiency of the algorithm is...
Imagine you have a set of five elements (A-E) with some numeric values of a measured property (several observations for each element):
A = {100, 110, 120, 130}
B = {110, 100, 110, 120, 90}
C = { 90, 110, 120, 100}
D = {120, 100, 120, 110, 110, 120}
E = {110, 120, 120, 110, 120}
First, I have to detect if there are significant differen...
a BST(binary search tree) T is given.
how to find the nth smallest element of T ?
...
Say n = 100; How do I generate 100 visually distinct colors? Is this mathematically possible?
...
Hi,
I need to find the kth smallest element in the binary search tree without using any static/global variable. How to achieve it efficiently?
The solution that I have in my mind is doing the operation in O(n), the worst case since I am planning to do an inorder traversal of the entire tree. But deep down I feel that I am not using the ...