# algorithm 3 « algorithm « Java Collection Q&A

Home
Java Collection Q&A
 1 algorithm 2 array 3 Array Byte 4 Array Char 5 Array Convert 6 Array Dimension 7 Array Integer 8 Array Object 9 Array String 10 ArrayList 11 collection 12 comparator 13 Development 14 Garbage Collection 15 Generic 16 hash 17 HashMap 18 HashTable 19 iterator 20 LinkedList 21 List 22 Map 23 queue 24 Set 25 Sort 26 tree
 Java Collection Q&A » algorithm » algorithm 3

### 1. Java Algorithm Question    stackoverflow.com

Problem Statement :: In Java ,Given an array of ints, is it possible to choose a group of some of the ints, such that the group sums to the given target, ...

### 2. Levenshtein to Damerau-Levenshtein    stackoverflow.com

I'm sitting here and programmnging some algorithms for my main program in Java (well the first one so far). I programmed the levenshtein algorithm just fine thanks to wiki being so ...

### 3. Java grouping algorithm    stackoverflow.com

Given an array of ints, is it possible to choose a group of some of the ints, such that the group sums to the given target, with this additional constraint: if ...

### 4. How to generate MFCC Algorithm's triangular windows and how to use them?    stackoverflow.com

I am implementing MFCC algorithm in Java. There is a sample code here: http://www.ee.columbia.edu/~dpwe/muscontent/practical/mfcc.m at Matlab. However I have some problems with mel filter banking process. How to generate ...

### 5. java help need big help    stackoverflow.com

In the following code we can add 6 times. I want to to reduce it to three times.

``````package dsa;

import javax.swing.JOptionPane;

/**
*
* @author asda
*/
public class myQueue
{
...``````

### 6. Library of optimzation algorithms in java    stackoverflow.com

I'm looking for some library(open source will be perfect) that have realization of different optimizaion algorithms in java. Actually I need a dual simplex method. It will be good if it ...

### 7. Forward chaining and Backward chaining in java    stackoverflow.com

What will be the best approach to implement forward chaining and backward chaining for reasoning process in java? We have been given Horn-form knowledge base which has set of statements. I have tried ...

### 8. Will this algorithm generate a cryptographically-secure bitstream?    stackoverflow.com

I'm in the rough stages of creating a Spades game and I'm having a hard time thinking up a cryptographically-secure way to shuffle the cards. So far, I have this:

• Grab 32-bit ...

### 9. Stuck implementing Wikipedia's A* ("A star") algorithm    stackoverflow.com

I'm implementing the A* search algorithm from this pseudo on wikipedia's article:

``````function A*(start,goal)
closedset := the empty set    // The set of nodes ...``````

### 10. Generate a infinite line with the help of markov chain theory    stackoverflow.com

So let me explain my problem a little better now (please reopen this question). I heard of markov chain theory when thinking about a method to generate procedural lines to build ...

### 11. Java code to implement hitting set algorithm    stackoverflow.com

Suppose F is a collection of sets. An edge-labeled and nodelabeled tree T is an HS-tree for F iff it is a smallest tree with the following properties: (1) Its root is ...

### 12. What are the differences between MFCC and BFCC?    stackoverflow.com

I have implemented MFCC algorithm and want to implement BFCC. What are the differences between them and is it enough just to use another function instead of frequency to mel (2595 ...

### 13. How to decrease the size of SHA1?    stackoverflow.com

I have a problem, maybe a silly question, I want to store data in a database after I hash with the SHA1 algorithm. However, at a future time, the size in ...

### 14. Reducing the granularity of a data set    stackoverflow.com

I have an in-memory cache which stores a set of information by a certain level of aggregation - in the Students example below let's say I store it by Year, Subject, ...

### 15. What is incorrect with my Voronoi generator?    stackoverflow.com

``````import java.awt.Color;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;

import javax.imageio.ImageIO;

public class Voronoi
{
public static void main(String args[])
{
Random ...``````

### 16. Algorithm for Parsing an XML    stackoverflow.com

I was reading one of the interview question about parsing an XML: http://www.glassdoor.com/Interview/One-of-the-interviewers-asked-me-to-write-two-algorithms-for-parsing-xml-one-that-was-as-memory-efficient-as-possible-the-QTN_22756.htm I wrote a very high level and incomplete skeleton of the algorithm , and was looking for some ...

### 17. How can I make this backtracking stop without using System.exit(0)?    stackoverflow.com

``````static void LasVegas(int []tablero, int f, int ultimaReina){

...``````

### 18. Routing algorithm for pipelines    stackoverflow.com

I have to create an algorithm for routing purposes in pipeline industry. Like we have 4 pipelines available and in between there can be either injection of oil or it can ...

### 19. What is the algorithm OR mathematics for Fisher's Exact Test?    stackoverflow.com

I need a Fisher's Exact Test for a matrix n x m. I've been searching for hours and I've only found one example code, but it's written in Fortran. I've been ...

### 20. HmacSHA1 generates different signatures on different systems using same secret    stackoverflow.com

I have a jersey oauth provider that uses HmacSHA1 for signing/verifying requests. This works for my development & test platforms where client & server are both different physical systems. However, when ...

### 21. Pattern-Matching Algorithm    stackoverflow.com

This is slide from class at my University, it about Pattern-Matching Algotithm.. And I try to code it in Java below;

``      ...``

### 22. Runtime error in UVA Online Judge    stackoverflow.com

I'm doing problem 10003 "cutting sticks" of the UVa online judge, I'm pretty sure my code works and I think I' correctly exiting the problem. But still I get a runtime ...

### 23. Need an algorithm for square root that provides a "remainder"    stackoverflow.com

I'm writing a calculator without using decimals (supports only Rational numbers), but I'd like to be able to do a version of square root. When a square root function is ...

### 24. Java code to find the area of a circle which is inside a rectangle    stackoverflow.com

I'm writing a .NET program for an engineering company. Their specification is to find the number of holes (either of same or different radius) on a rectangular plate and then to ...

### 25. The efficeient approach to calculate the interaction or union of two sets    stackoverflow.com

I have two arraylists, where each of which stores a set of elements. I would like to obtain and output the intersection of these two sets. Is there any efficient and ...

### 26. Java implementation of Long.numberOfTrailingZeros()    stackoverflow.com

``````/**
* Returns the number of zero bits following the lowest-order ("rightmost")
* one-bit in the two's complement binary representation ...``````

### 27. how to actually get the nearest neighbor in weka using java    stackoverflow.com

so I've been trying to use the Ibk nearest neighbor algorithm that goes together with the weka machine learning library..... I know how to classify instances, but I want to implement the ...

### 28. how to check if curves are similar    stackoverflow.com

How to compare two black curves on a white background? How to do it as fast? For example this and this are similar, but this BPF expressions. I also need to implement mechanism for detecting equivalent BPF expressions. Building ...

### 41. Algortithm to store Item-to-Item-Associations    stackoverflow.com

I need some help to store some data efficiently. I have a large list of objects (about 100.000) and want to store associations between this items with a coefficient. Not all ...

### 42. bouncycastle provider can't find classes needed for algorithm    stackoverflow.com

I'm trying to use bouncycastle to encrypt a file using a public key. I've registered the provider programatically:

``````Security.addProvider(new BouncyCastleProvider());
``````
I created the public key object successfully. when i get to encrypting the file using ...

### 43. Versioning of domain model    stackoverflow.com

I implement versioning for my own domain model (tracking of differences in objects during update operations). Domain model has a tree structure. E.g. (-> is reference)

``````A
|-> B
|-> C -> A
...``````

### 44. How can I prove that one algorithm is faster than another in Java    stackoverflow.com

Is there anything in Java that would allow me to take a code snippit and allow me to see exactly how many "ticks" it takes to execute. I want to ...

### 45. A* Algorithm Bug    stackoverflow.com

I tried creating the A* algorithm in java and I have this strange bug. I know the A* doesn't always find the best path, but here it seems to go against ...

### 46. Problem with a challenging algorithm    stackoverflow.com

I'm stumped. I need to access the next `nth row` in a query loop to show version differences between posts. I'm using `<cfquery>` to output the revisions by group, and this is ...

### 47. Problem with Divide and Conquer Maximum Consecutive Subarray (MCS)    stackoverflow.com

I want to find a nonempty, contiguous subarray for a given input array of integers, that can have duplicate values. I tried the divide and conquer method to find the maximum ...

### 48. There is a entity recognizer classifier algorithm that doesn't needs entire texts for training data?    stackoverflow.com

I want to recognize some entities on texts that I have and I found a lot of algorithms (NaiveBayes, Hidden Markov Models, Conditional Random Field, etc.), but seems that almost all ...

### 49. Java - algorithm to find executable lines of code    stackoverflow.com

I wrote a java program which scans and finds Executable lines of codes (ELOC), blank lines of codes(BLOC) and comments (CLOC) for only java and c++ codes. Following is my code:

`` ...``

### 50. Circle In Rectangle Packing Algorithm    stackoverflow.com

I need a packing algorithm that fits a set of circles of varying radii, if the circles fit, in a rectangle. I've seen various pages on Wikipedia ...

### 51. What's the equivalent 'nth_element' function in Java?    stackoverflow.com

I don't want get a sorted array, just nth element's value. For example, given the array

`````` a = [20, 5, 1, -3]
``````
I'd like to be able to ...

### 52. Java - How to build unique object tuples (n-dimension)?    stackoverflow.com

I have the following challenge that I need to create unique object tuples out of object lists. The speical challenge is here how I can do it for dynamic list sizes ...

### 53. Java Algorithm to solve vendor machine 'change giving' problem    stackoverflow.com

As a graduate I went for an interview for a java development role and was doing pretty well in the technical examinations until i came up against this question. If i was ...

### 54. Elegent way to write criteria based if statements    stackoverflow.com

I'm trying to find an object in a list based on a set of criteria. The basic logic looks like this

``````for (objectx obj : list)
{
if (object.property1 > ...``````

### 55. Theory behind Implementation of a Challenge 24 Solver    stackoverflow.com

As an introduction to Java and android development I decided to write a Challenge 24 (given 4 numbers, must add, multiply, divide or subtract in order to create the product 24) ...

### 56. HMAC-SHA256 Algorithm for signature calcualtion    stackoverflow.com

I am trying to create a signature using the HMAC-SHA256 algorithm and this is my code. I am using US ASCII encoding.

``        final Charset asciiCs ...``

### 57. First Come First Serve Algorithm Implementation    stackoverflow.com

This is a project given to us by our professor. The requirements are to implement 3 pre-picked algorithms of CPU Scheduling in JAVA. our group was given FCFS(First Come First Serve),Round Robin,and MFQ(Multi-feedback ...

### 58. Parsing Tree-structure into Relational-style data-store    stackoverflow.com

Would someone be able to help with how I could implement this, or at least the algorithm to use for this. What I am trying to do is parse a a hierarchical/tree ...

### 59. Keeping data in memory, Design approach    stackoverflow.com

I have a problem where in I need to process some files with size in the range of few kbs up to 1 GB max. The use case is such that ...

### 60. Missing Date Ranges    stackoverflow.com

I need to find all the missing date ranges from the rest of the year given a collection of date ranges. All the date ranges fall within the same year. And ...

### 61. The Bankers Algorithm for Deal or No Deal    stackoverflow.com

I am going to make a game called Deal or no deal using Java. Can anyone give me the idea or the algorithm of how banker offers? Or the algorithm for ...

### 62. Mondrian Olap drilldown algorithm    stackoverflow.com

I didn't found but may be someone could me explain - OLAP cube is a combination of all possible aggregation, so related to Mondrian - leaf level is data in fact ...

### 63. How to implement trim exceptional data like this?    stackoverflow.com

I have a `List<Data>` that contains random objects: `i` and `o` characters. The Data has two types, i and o (`Data.type`). I want to write a function in Java that can arrange the ...

### 64. kadane algorithm in java    stackoverflow.com

I have the following implementation of Kadane's algorithm in java. It is basically to find the maximum sum of contiguous subarray.

``````String[] numbers = string.split(",");
...``````

### 65. Moving average/total algorithm    stackoverflow.com

I need to keep track of the last 7 days work hours in a flat file reading loop. It's being used to measure 'fatigueability' of work rosters. Right now I have something ...

### 66. Converting dungeon algorithm from java to javascript not working    stackoverflow.com

I am trying to convert this dungeon algorithm from java into javascript, however, my script works 70% of the time. When it works, the problems are: the rooms ...

### 67. How can I build an algorithm to classify an HTML page based on keywords?    stackoverflow.com

I'm trying to create an algorithm that set some relevance to a webpage based on keywords that it finds on the page. I'm doing this at the moment: I set some words and ...

### 68. Java backtraking problem    stackoverflow.com

Hey guys. I've been strugling with a backtraking problem for hours. Can anyone lend me a hand? Here is the problem: `n` camels numbered from 1 to `n` are the arranged order. ...

### 69. Any ideas of what more web page meta information I can use to classify a page relevance for some theme?    stackoverflow.com

I'm doing an algorithm to classify the relevance of a page for some theme like 'movies' using all meta information as possible, but excluding the textual content of the body. I want ...

### 70. Algorithm for software keystone correction    stackoverflow.com

As part of my software I'm looking to write a keystone correction filter to avoid the tombstone / keystone effect you can get when projectors are displayed at an angle not ...

### 71. k combinations from n    stackoverflow.com

Possible Duplicate:
Algorithm to return all combinations of k elements from n
The combination can be formed with 3 digits from 1,2,3,4 such a way that ...

### 72. Coding Kata : What is the optimal algorithm to solve this    stackoverflow.com

I was trying to solve random coding kata's and found this one, my question here is what is the optimal algorithm and best design approach for solving this kata? Given a sequence ...

### 73. need help in designing algorithm for syntax analyzer    stackoverflow.com

I want to create a program for syntax analyzer for java, but I'm confusing in what way I should design the algorithm? can you please elaborate...

### 74. How to find the base10 of (x:g)?    stackoverflow.com

I am at the end of my homework, and a little confused on the right way to go for this algorithm. I need to find the base10 of a number:base that ...

### 75. Looking for resources for moving around in grids/cells    stackoverflow.com

I'm making a simple enough game that involves using a grid, very much like a sudoku style grid, but I am having an extremely tough time figuring some seemingly simple things ...

### 76. Locate triangle containing arbitrary point in Delaunay-triangulated surface    stackoverflow.com

I'm looking to do a linear interpolation of a irregularly sampled function `z(x,y)` based on a Delaunay triangulation. Say I have a hill for which I have obtained a Delaunay triangulation: ...

### 77. Script for Dropbox to make a automatic process    stackoverflow.com

Hope you all know about Dropbox. In Dropbox, we can drag the files to drop box folder then it will be stored in the cloud. I need to do this ...

### 78. How obtain first/last day of an incomplete week in Java    stackoverflow.com

and thanks for reading me. I have a little problem that is that I need to Know the first/last day of a week in a month and a year, so:

``public String getFirstDayOfWeekAndMonth(int ...``

### 79. Where/how can I allow non-numeric values in my program?    stackoverflow.com

I am making this little program using command line arguments, I have like 90% of the work done. But I am trying to allow the user to enter non numerical values ...

### 80. How can i make sound in Java? Which exactly sounds like my voice, clone my pronounciation    stackoverflow.com

I mean by "make sound" which sound never exist, its completely made in Java. I am trying to make a very simple very basic hello real world code in Java, but cant ...

For an issue tracking system I need to calculate the response time for a request. The timer for response time should only be running during business hours. What algorithm/library should I ...

### 82. How to validate Battleship field?    stackoverflow.com

I am trying to validate battleship field with these rules:

• Ships don't touch with sides or corners;
• Ships are straight;
• There are 1×4-deck ship, 2×3-deck, 3×2-deck, 4×1-deck ships.
The field is represented as ...

### 83. Finding a particular Set of SubSets of a PowerSet in an efficient way    stackoverflow.com

I'm trying to find an efficient way to grab a Set of Subsets of a PowerSet. For example, this works when the set sizes are small:

``````Set<Integer> set = new HashSet<Integer>();

Set<Integer> set2 ...``````

### 84. How to create your own security provider with some crypto algorithm?    stackoverflow.com

Using official tutorial i understood the main principles of Java Cryptography Architecture. But neither the officials nor internet gives me anything distinct about creating my own provider and implementing some crypto algorithms. I ...

### 85. Algorithm to find all possible 'StringPairGroups' in Java?    stackoverflow.com

Mathematics/algorithms was never my strong point (!) so requesting help on this one. What is the most efficient implementation for a method with the following signature:

``````/*
* pairParts.size() > 0
* pairParts.size() ...``````

### 86. Java vs. JavaScript(HTML5), The Distributed Algorithm Animator    stackoverflow.com

In my final year project I have to build an Algorithm animator. It would be done to show how the algo works using nodes(PCs) and edges(connections). For example, how the leader ...

### 87. Open Source implementation of a Spaced Repetition Algorithm in Java    stackoverflow.com

I work on a project where Spaced Repetition is essential, however I am not a specialist on the subject and I am afraid to reinvent the square wheel. My research pointed ...

### 88. Algorithm to output the initials of a name    stackoverflow.com

I have just started the java programming and at the moment I am doing the basic things. I came across a problem that I can't solve and didn't found any answers ...

### 89. Finding Duplicates of a set of millions    stackoverflow.com

Possible Duplicate:
Algorithm: efficient way to remove duplicate integers from an array
I would like to know what is the best, efficient approach for finding a ...

### 90. How to scan hundreds of log files containing SSN, and change the files to mask out the SSNs without changing the reset of the contents    stackoverflow.com

I was asked this question on an interview and I couldn't came up with an efficient idea to solve this problem. "How to scan hundreds of log files containing SSN, and ...

### 91. Assigning a value for each day for the past 2 weeks using 14 buckets to store them    stackoverflow.com

This is kind of hard to explain but I need to come up with an algorithm that will use these 14 value buckets to move through it based on the day ...

### 92. Java algorithm to track parts of aggregated values    stackoverflow.com

My program have evaluate hundreds of millions of records. So the question of memory and performance are important. Lets each record has key - ticketID. Also record has field value and field ...

### 93. How to count identical bytes    stackoverflow.com

I have two long arrays of bytes and I need to compute how many bytes on corresponding positions are identical. My solution (in JAVA) is as follows:

``    int ...``

### 94. Gift Wrapping Algorithm not working properly    stackoverflow.com

I am trying to implement this Gift Wrapping Algorithm (yoshihitoyagi!) done in java, in VB6. I'm pretty sure I have done this properly, but for some reason, it will ...

### 95. RLE sequence, doing a tailReplace    stackoverflow.com

If I'm constructing a tail replace method for an RLE sequence, is the best way to decompress the sequence, append the new sequence at the given index, and then recompress or ...

### 96. Brute-Force language detection    stackoverflow.com

I need an algorithm (any programming language) to test the vitality with an hill climbing algorithm for breaking a cipher for a crypto challenge. The algorithm should test how likely it ...

### 97. Updated: subsetSum    stackoverflow.com

Trying to write algorithm for subsetSum... It should find all possible subsets of a given vector, then find which ones add up to a target value. However, I keep getting nullpointerexceptions, ...

### 98. algorithm, in java?    stackoverflow.com

I need help with an algorithm to search for query words, in isolation and/or in combination, assign a score to each match and sort the matches by score. The returned results ...

### 99. Absolute newbie to java    stackoverflow.com

Hi i have been given a task for my course and it is to create an algorithm to make a 5 by 5 square like below:

``````*****
*****
*****
*****
*****
``````
Ive spent hours attempting to do ...

### 100. Outputing a square to console in java    stackoverflow.com

Hi i am doing my coursework and i have been given the task is to make an algorithm for a square that's 5x5 using "*" but has to be filled in ...