algorithm 2 « algorithm « Java Collection Q&A

Java Collection Q&A
3.Array Byte
4.Array Char
5.Array Convert
6.Array Dimension
7.Array Integer
8.Array Object
9.Array String
14.Garbage Collection
Java Collection Q&A » algorithm » algorithm 2 

1. Ultra symmetrical line algorithm?

I ran into special case where I need to produce ultra symmetrical line or ray in 2D grid in order from (x0, y0) through (x1, y1) like this:

void drawSymmetricalLine(int x0, int ...

2. How to detect the "likeness" of data

Generally speaking, can you suggest an approach which would let me test objects to make sure they are alike. Accept that objects are alike if over 'n%' worth of content of ...

3. Java Implementation of Rectangle Intersection Algorithm..?

I am interested in this algorithm: but unable to implement it myself lacking even basic mathematical skills. I think I could understand it better once I can read the code. ...

4. Problem 9 (Project Euler) with Java - is it perfect program?

I am new to Java and even OOP, but I tried to write program for this task:

A Pythagorean triplet is a set of three natural numbers, a < b < c, ...

5. A* implementation always returns same value

I seem to be either losing my mind or misimplementing the A* algorithm: Below is my code, it seems that no matter what values I enter it will always return ...

6. How to calculate that no sub range overlap each other and all sub range covers whole range in java?

I have a range in java implemented as a class which is divided into sub-ranges. The implementation is roughly as follows:

public class Range
   static public class Key implements Comparable<Key>

7. Crossover algorithm implementation

I started to delve into GA a bit here for study and I cannot seem to find an answer to crossover generation break points. For instance if I start with ...

8. Transforming 'X' to 1 or 0, if its > 0 or == 0

Currently, my algorithm is someValue + x. I am trying to figure out how I can transform x to 1 if its greater than 0, or to 0 if its equal ...

9. General DFS on River Crossers

I'm trying to write a DFS to solve multiple river crossing problems (Fox Goat Cabbage, Jealous Husbands, Mercenaries and Cannibals, etc.). I've written the puzzle classes, but I'm having trouble structuring ...

10. algorithm to find complementary solution to this problem

I had this coding question in an interview.I couldnt find an optimum solution to this. what I did was,

if(a[i]+a[j]==k) print a[i], a[j]
But that would give rise to a O(n2) complexity. Is there a ...

11. Example of O(n!)?

What is an example (in code) of a O(n!) function? It should take appropriate number of operations to run in reference to n; that is, I'm asking about time complexity. ...

12. Calculating Percentiles on the fly

I'm programming in Java. Every 100 ms my program gets a new number. It has a cache with contains the history of the last n = 180 numbers. When I get a new ...

13. Can anyone explain how this code generates combinations?

I found some Java code for generating combinations on, but I can't understand what it is doing as it does some strange operations with bits.

import java.util.Collections;
import java.util.LinkedList;

public class Comb{


14. Can someone please explain how this implementation works? Also, can it be made better? How?

public class Main { 
    public static void main(String args []){ 
        long numberOfPrimes = 0; //Initialises variable numberOfPrimes to 0 ...

15. Group most similar elements together

I have a two-dimensional array of ints, for example:

int [][] board=
I don't want to change the columns of this array at all; however, I would like to swap the rows so ...

16. How to give each object in a document a unique ID?

I'm making a bitmap editor where a document consists of several layers where each layer represents a bitmap. Each layer must have a unique ID compared to all other layers that ...

17. Help In Solving Algorithm

Am suppose to return the number of character comparisons. In the while() loop i compare the index of the characters and update the counter. My question is, is it right to ...

18. Theory and algorithm behind Java garbage collection

I read at many places, but did not find a place where I can learn about : What is java garbage collection all about? How is it implemented? When and ...

19. Java algorithm to make a straight pyramid

__________1 2 1
_________1 2 3 2 1
________1 2 3 4 3 2 1
______1 2 3 4 5 4 3 2 1
_____1 2 3 4 4 4 4 4 3 2 1
___1 ...

20. Non-blocking algorithm and mutual exclusion

Wikipedia says that:

Non-blocking algorithm ensures that threads competing for a shared resource do not have their execution indefinitely postponed by mutual exclusion.
How can one ensure ...

21. Problems with DCT and IDCT algorithm in java

Here I have my DCT algorithm class with "applyDCT" and "applyIDCT" methods. Technically after doing a forward DCT (discrete cosine transform) on a 2x2 table of random integers between 0 and ...

22. help for compeleting an algorithm

I have creating the blindSearch method so as to write the convexHull Algorithm. but it doesnt work right, and doesnt remove the internal points. would you please help me?

public Point pnt[] ...

23. How to count possible combination for coin problem

I am trying to implement a coin problem, Problem specification is like this Create a function to count all possible combination of coins which can be used for given amount.

All possible combinations ...

24. find Combinations of all sets - set cover?

Can someone please share a program in java which does the following. if given the following sets as inputs,

the program will find all the combinations of the set and find out the ...

25. Is there an easy way to output a column-wise CSV?

I'm trying to output multiple lists of data, of varying length, to a CSV file. Each list should be a column in the output CSV file. Is there a straight-forward way ...

26. Branch and bound algorithm for the Set Cover problem?

Can someone pleas share with me a java program that uses the Branch and bound method to solve the Set Cover problem? Following is what I have so far. So at ...

27. Looking for combinations that add up to 15 in a card of hands

I am writing a program that deals with cards and a hand. A hand has 5 cards. I want to know whats a good algorithm for deciding which combination of cards ...

28. Java - Big result difference when benchmarking an algorithm in ms and ns

I was performing some test performance on an algorithm and noticed something weird. Maybe I am missing something here. I first measure the time in milliseconde:

long startTime = System.currentTimeMillis();
long endTime = System.currentTimeMillis();
and ...

29. help for writing an algorithm

I am doing designing an algorithm for an assignment, and I am not sure that I have written a correct algorithm, would you please guide me? The question is: There are n ...

30. Convert Data to sound and back

Are there libraries out there that can convert data (text files, etc) to sound and back to the original data? The sound can be transmitted any medium I wish, whether radio, etc. ...

31. Java algorithms

I am a server side Java programmer. In my recent job search, I have come across a few postings where they mention : ' Candidates with expereince in algorithm development will ...

32. Download acceleration

I have Google'd my butt off, and I can't find anything on this topic. I am trying to create a download client using Java, and I have figured out how to download ...

33. Traveling salesman library using approximation algorithm

I'm currently doing a project that requires some fast TSP solving (about 50-100 nodes in 2 seconds). There are a lots of approximation algorithms out there, but I don't have time ...

34. Bloom Filter Implementation

Using Bloom filter , we will be getting space optimization.But in reality, how it is achieved. The cassandra framework is such kind of frame work,if I am correct.

35. Would it be acceptable to place bounds around my pathfinding area?

I'm currently using the A* pathfinding algorithm to calculate a path on an infinite grid (using an UnboundedGrid in Gridworld, the AP CS case study, if that helps anyone). Everything works ...

36. Project euler problem 45

I'm not yet a skilled programmer but I thought this was an interesting problem and I thought I'd give it a go.

Triangle, pentagonal, and hexagonal numbers are generated ...

37. Implementation of A Star (A*) Algorithm in Java

Disclaimer: I have little background in Java, since I am predominantly a C# developer. Would like to have the java implementation of A* algorithm.
Yes, I saw many versions of the same online ...

38. Java Algorithm fundamentals

Possible Duplicate:
Best book to pick up algorithms and data structures?
I am a fairly new Java developer. I understand most of the syntax ...

39. Branch And Bound Implementation for TSP in Java

I wonder if there is a useful Java implementation of a Branch And Bound algorithm for the TSP or in general a OR framework which includes a BnB for TSP. Thanks for ...

40. Branch And Bound Implementation for TSP in Java

Possible Duplicate:
Branch And Bound Implementation for TSP in Java
Hey folks, I wonder if there is a useful Java implementation of a Branch And Bound algorithm ...

41. implementing debounce in Java

For some code I'm writing I could use a nice general implementation of debounce in Java.

public interface Callback {
  public void call(Object arg);

class Debouncer implements Callback {

42. Days Between Dates Java

so, this is a couple days off when I run the program. any advice? and yes, i know there is a simpler way to do it, but for this i'm trying to ...

43. RGB to CMYK and back algorithm

I am trying to implement a solution for calculating the conversion between RGB and CMYK and vice versa. Here is what I have so far:

  public static int[] rgbToCmyk(int red, ...

44. location based data grabbing algorithm

I have this programming project i have to develop an algorithm for location based data grabbing and displaying it on the mobile. i'm just a regular web programmer knowing some php ...

45. Can anyone help me create a simple machine learning algorithm for a 'pet' application

I'm creating an organism simulator for Android, so I guess the algorithm would ideally be in Java. I realize that there is a whole Stanford course on Machine Learning available on ...

46. Frank-Wolfe Algorithm

Do you know any implementation, (java) to solve non linear programming with this algorithm? Could you explain that algorithm, or the code?

47. OCR in java algorithm or code

I need to do OCR in java for final year prject. i have tried many APIS but dint work for me ...any one who can help or can provide code or ...

48. FishEye Picture Effect (Barrel Distortion) Algorithm (with Java)?

I'm looking for the algorithm (bitmap pixel manipulation) to simulate the fisheye lens (Barrel Distortion) from normal pictures. So far I've found implementation involving external libraries like OpenCV, OpenGL or jhlabs. ...

49. Lattice Multiplication Java

I need help, I am trying to make use of Lattice Multiplication in java for use in a BigInt class I am having to write for a class. Right now I ...

50. How to get frequency of multi-word terms in Lucene?

I'm using Lucene to get frequency of terms in documents, i.e. number of occurrences of some term in each document. I use IndexReader.termDocs() for this purpose, and it works ...

51. How to do Combinatorics on the Fly

I have a very weird problem which has some constrains that make it difficult to solve. I have a list of lists and I want to do the combinations of all ...

52. TF-IDF algorithm in java

Possible Duplicate:
Any tutorial or code for Tf Idf in java
can anyone provide me an insight on how to calculate TF-IDF in java ? i ...

53. Why does cache use Most Recently Used (MRU) algorithm as evict policy?

I know the algorithms of MRU and its reversed one Least Recently Used (LRU). I think LRU is reasonable, as LRU element means it will be used at least possible in future. ...

54. Calculating tax owed with thresholds and rates in java

for a part of my revenue program I am making as an assignment for school I have to calculate a number which is the Total Tax Owed from a citizen. I ...

55. 2 Java methods java.lang.NullPointerException

I"m getting an error java.lang.NullPointerException error on the following code.

The algorithm:

  1. If n ? 3 find the closest points by brute force and stop.
  2. Find a vertical line V such that divides the ...

56. Problem with Prim's Algorithm implementation

I've implemented the following Prim's Algorithm method. It returns the MST weight. However it seems not to be working for some cases. Can anyone please tell me what I'm doing wrong?

private static int ...

57. How to effectively monitor change on a remote location?

We have to monitor the change on a remote system file, that we acces throught FTP, SMB. We do not have any SSH access to the remote system / os. Our only ...

58. Pathfinding in Java

Let's say I use arrays to plot out my game map using this:

{ 1,  1,  1,  1,  1,  1,  1,  1,  1,  ...

59. Boruvka MST Algorithm

Help me please with Boruvka algorithm for creating a minnimum-spanning tree. I wrote code of an algorithm looking on example given by Sedgwick but apparently had done a bunch of nonsense, ...

60. Problems with a shunting yard algorithm

I have successfully implemented a shunting yard algorithm in java. The algorithm itself was simple however I am having trouble with the tokenizer. Currently the algorithm works with everything I want ...

61. Why do people say that Java can't have an expression evaluator?

I am aware that by default Java does not have the so-called eval (what I pronounce as "evil") method. This sounds like a bad thing—knowing you do not have something ...

62. java code for sift algorithm

Possible Duplicate:
Implementing SIFT in Java
Hi I need to compare an image with images in database using sift algorithm Can anyone tell where I can get java ...

63. simulated annealing template java

Do you know any template for the simulated annealing in java?

64. Simple hill climbing algorithm? [UPDATED]

I'm trying to use the Simple hill climbing algorithm to solve the travelling salesman problem. I want to create a Java program to do this. I know it's not the best ...

65. Help with my MinMax Implementation

I've been trying to implement a minMax Algorithm (will try alphabeta pruning later) for a simple game....I've seen many pseudo codes and tutorials but i just can't get it to work... A ...

66. Finding a mode with decreasing precision

I feel like there should be an available library to more simply do two things, A) Find the mode to an array, in the case of doubles and B) gracefully degrade ...

67. How to calculate the angle between a place on Earth and the Sun?

For my application I need to calculate an angle between two different lines: 1) The first line is between a point on the earth which is defined by longitude and latitude and ...

68. Handling ZIP content in Java that uses the SHRINK algorithm

Anyone know of a way to handle ZIP files produced using the SHRINK algorithm? This doesn't appear to be supported by the standard Java ZIP functionality. We're receiving ZIP files from ...

69. Venn diagram generation software from RCC(8) specification or similar

Please note: While the bounty is no longer available, I'm still keen for anyone with a good answer to this question to contribute; I'm still watching it, and will award upvotes ...

70. How to get the cut-set using the Edmonds–Karp algorithm?

I implemented the Edmonds–Karp algorithm using the Pseudocode that I found in the Edmonds–Karp algorithm wiki page: It works great, yet the algorithm output is the max flow value(min ...

71. Five Digit Primes in a 5x5 Grid

| 1 | 1 | 3 | 5 | 1 |
| 3 | 3 | 2 | 0 | 3 |
| 3 | 0 | 3 | 2 | 3 |
| ...

72. Extract human sound from a wav file using java

I am working on a project where I have to extract the human sound from a audio .wav file using java. The audio .wav file may have 3 to 4 sounds ...

73. Algorithm for implementing parking space reservation for generic parking lots

Hey I'm trying to implement reservation system for parking lots registered at my website. I have a hardware that detects the presence and absence of car at a parking space. So ...

74. Java Simulated Annealing from Pseudocode

I am currently working on a project (TSP) and am attempting to convert some simulated annealing pseudocode into Java. I have been successful in the past at converting pseudocode into ...

75. Paul octopus algorithm

I'm looking for an algorithm using java that similar to Paul's prediction. It looks like if we give two numbers to the algorithm, it will give one number randomly from those ...

76. Quiz algorithm question

I'm writing a a multiple-choice quiz program for Android, and would like to add a randomization feature to it, that is, the questions will come from a list, and the order ...

77. Pre-computing large table of values

I have a mathematical formula in my program that takes in two values, both between 0 and 1, and does a lot of work to find an answer. I also want ...

78. Need help with calendar algorithm

I am trying to create a gag calendar app and need some help getting the algorithm correct to create a calendar like this:

Jan Feb .. Dec
  2   6 ...

79. Example of a O(2^N) algorithm

I've been told that

O(2^N) denotes an algorithm whose growth will double with each additional element in the input data set
Can someone provide an example that behaves like this?

80. Solving Singly Even Magic Square (Lux Problem)

Hey guys I am trying to implement a method for solving singly even magic square, but it seems to generating the wrong results. Result generated by the following code Enter in size ...

81. How to distinguish between labels?

I built a hexagonal table, each hexagonal I put on a label ... Now I noticed that there is overlap between the hexagons because the shape of the label is ...

82. Learn backtracking algorithm

I want to learn the backtracking algorithm. Can someone please teach me some of it? I tried learning from some websites, but it didn't work. So can someone please teach me. ...

83. Repetition algorithm problem, Java

Set an algorithm that reads a undetermined number of values to m, all positive ints, one at a time. If m is even, verify how many divisors there is and write ...

84. Minimum set difference

i came across this question on this website called codility, but i cant really figure out how to solve it, would appreciate the help Given an array A of n integers, and ...

85. codility question absolute distinct count

so i took the codility interview test yesterday and was informed today that i failed, unfortunately i wasnt given any other information by either codility nor the employer as to where ...

86. Using parallel algorithms when reading documents

Possible Duplicate:
Improving performance of preprocessing large set of documents
Hi, I have a document set contain about 100 documents. I have to preprocess each of these ...

87. Different outputs for same algorithm in different languages

Java Source Code:

package n1_problem;

 * @author nAwS
public class loop {

    int loop(long i)
        long n=i;

88. Is that java algorithm correct?

 import java.util.Scanner;

public class doisExercicio {

  public static void main(String[] args) {

  int n, fat=1,c=1, aux;

 Scanner leia=new Scanner(;

 System.out.println("Digite um numero inteiro");






89. Library/Framework for Generalized Sequential Pattern Discovery?

I have a CSV file of the following format: session_id,time,item where the possible amount of items is huge. Which framework/library fits best for that problem (Generalized Sequential Pattern Discovery)?

90. Trying to figure out what algorithm to use

You have an input a n games. Each game has a fame (which can be negative) and prerequisite games (these games must be played before you play the current game). You want to ...

91. Any idea what algorithm I could use to help me with this in Java?

Your second challenge is to implement bots that can find the shortest path to an exit. In the maze shown in figure 1 A20% ? E10% ? D0% is not an acceptable ...

92. Debugging/fixing a BFS algorithm

I'm solving this BFS homework problem, I believe the logic I'm following is right, but I got stuck in an implementation error I can't pinpoint. I'm looking for help debugging this ...

93. How can I improve this 2D collision detection algorithm?

I remember my 2D collision detection algorithm to be more scalable... However, I feel that I may have sacrificed performance. In order for this scalability to work I had to this:

  1. Created ...

94. Java : Summation of `multiples of 5` in a group to a given target

I'm struggling to get the below problem working with no approach in right direction. Write a java function such that given an array of ints, is it possible to choose a group ...

95. Algorithm and Java

how can we build a directed graph representing the adjacency structure of the words, and run BFS on it. the program should take two file names as arguments. The first ...

96. summation of multiples of 5 to a given target

Possible Duplicate:
Java : Summation of multiples of 5 in a group to a given target
Hi SO People, I'm struggling to get the below problem working ...

97. Dataflow Diagram or Pseudo Code for Fast Fourier Transform?

I have an ArrayList that has Double elements. I want to implement FFT(Fast Fourier Transform) on it. However I don't want to take a Java code somewhere else and copy it. ...

98. Points in plane are square?

There are: A set of points in a plane, Counts of points can be big (1 Bilion). I need to find algorithm to find all square that can be created ...

99. How does the Euclidean Algorithm work?

I just found this algorithm to compute the greatest common divisor in my lecture notes:

public static int gcd( int a, int b ) {
    while (b != 0) ...

100. Keyword based nearest neighbour algorithm or library

I want to find a library or an algorithm (so I write the code myself) for identifying the nearest k neighbours of a webpage, where the webpage is defined as being ...  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.