algorithm

Bit count in array

I know that to count the number of set bits in a number, the following code can do it: int t; // in which we want count how many bits are set // for instance, in 3 (011), there are 2 bits set int count=0; while (t > 0) { t &= (t - 1); count++; } Now an array example: int x[] = {3, 5, 6, 8, 9, 7}; I have the followi...

What kind of search does ID3 perform?

What kind of search does ID3 perform? ...

Big Oh Notation - formal definition.

I'm reading a textbook right now for my Java III class. We're reading about Big-Oh and I'm a little confused by its formal definition. Formal Definition: "A function f(n) is of order at most g(n) - that is, f(n) = O(g(n)) - if a positive real number c and positive integer N exist such that f(n) <= c g(n) for all n >= N. That is, c g(n) ...

Job Shop Scheduling: Shifting Bottleneck

Hello I'm currently looking into quick graph because I need to implement Job Shop Scheduling. I have been researching and found the shifting bottleneck algorithm very promising. As I'm not really proficient in math and search algorithm I wanted to ask you guys if shifting bottleneck would fit into my problem domain and how this could be...

Multiplication algorithm for abritrary precision (bignum) integers.

Hi, I'm writing a small bignum library for a homework project. I am to implement Karatsuba multiplication, but before that I would like to write a naive multiplication routine. I'm following a guide written by Paul Zimmerman titled "Modern Computer Arithmetic" which is freely available online. On page 4, there is a description of an a...

Merging and splitting overlapping rectangles to produce non-overlapping ones

I am looking for an algorithm as follows: Given a set of possibly overlapping rectangles (All of which are "not rotated", can be uniformly represented as (left,top,right,bottom) tuplets, etc...), it returns a minimal set of (non-rotated) non-overlapping rectangles, that occupy the same area. It seems simple enough at first glance, but ...

Diamond square algorithm.

I'm trying to write the Diamond-Square algorithm in Java to generate a random map but can't figure out the implementation... Anyone with some Java code (or other language) so i can check how the loop is made would be greatly appreciated! Thanks! ...

Affine transformation algorithm.

Does anyone know of any standard algorithms to determine an affine transformation matrix based upon a set of known points in two co-ordinate systems? ...

Haskell Binary Tree Function (map)

How can i define a Haskell function which will apply a function to every value in a binary tree? So i know that it is similar to the map function - and that its type would be: mapT :: (a -> b) -> Tree a -> Tree b but thats about it... ...

Word frequency problem

In "Programming Pearls" I have met the following problem. The question is this: "print words in order of decreasing frequency". As I understand problem is this. Suppose there is a given string array, let's call it s (words I have chosen randomly, it does not matter), String s[]={"cat","cat","dog","fox","cat","fox","dog","cat","fo...

longest string in texts

I have meet following problem too for example there is given two text find longest string that occur in both i think we should create string array where we should put common srings and then compare their length and which length will be largest print it is there fast method? ...

Determining the maximum stack depth

Imagine I have a stack-based toy language that comes with the operations Push, Pop, Jump and If. I have a program and its input is the toy language. For instance I get the sequence Push 1 Push 1 Pop Pop In that case the maximum stack would be 2. A more complicated example would use branches. Push 1 Push true If .success Pop Jump ....

public (static) swap() method vs. redundant (non-static) private ones...

I'm revisiting data structures and algorithms to refresh my knowledge and from time to time I stumble across this problem: Often, several data structures do need to swap some elements on the underlying array. So I implement the swap() method in ADT1, ADT2 as a private non-static method. The good thing is, being a private method I don't ...

longest string in texts

I have following code in Java: import java.util.*; public class longest{ public static void main(String[] args){ int t=0;int m=0;int token1, token2; String words[]=new String[10]; String word[]=new String[10]; String common[]=new String[10]; String text="saqartvelo gabrwyindeba da gadzlierdeba aucileblad "; String text1="...

Find cheapest price for X number of days

Hey 'FLow. I have a technical challenge for you regarding an algorithm. Lets say I have this list of days and prices: List<ReservationPrice> prices = new List<ReservationPrice>(); prices.Add(new ReservationPrice { NumberOfDays = 1, Price = 1000 }); prices.Add(new ReservationPrice { NumberOfDays = 2, Price = 120...

What is the time complexity of TreeSet iteration?

In my code, Java TreeSet iteration is the dominant time factor. In looking at the system I believe that it is O(n) complexity. Can anyone verify this? I am thinking that by providing links backward from child node to parent node I could improve the performance. ...

Pseudo LRU tree algorithm.

A lot of descriptions of Pseudo LRU algorithms involve using a binary search tree, and setting flags to "point away" from the node you're searching for every time you access the tree. This leads to a reasonable approximation of LRU. However, it seems from the descriptions that all of the nodes deemed LRU would be leaf nodes. Is there a ...

Determining the chances of an event occurring when it hasn't occurred yet

A user visits my website at time t, and they may or may not click on a particular link I care about, if they do I record the fact that they clicked the link, and also the duration since t that they clicked it, call this d. I need an algorithm that allows me to create a class like this: class ClickProbabilityEstimate { public void r...

Dot Game and Dynamic Programming

I'm trying to solve a variant of the dot game with dynamic programming. The regular dot game is played with a line of dots. Each player takes either one or two dots at their respective end of the line and the person who is left with no dots to take wins. In this version of the game, each dot has a different value. Each player takes a...

Level Order Successor of node in BST

How can we find level order successor of a node in bst if parent pointer is given(with out using Queue ) ? ...