# algorithm 5 « 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 5

### 2. Need help with Algorithms    coderanch.com

Hi All, I am not sure if this is the right place for this. I hope if its not, it would be moved to its appropriate place. I am digging in to the "data Structures and Algorithms in java by Adam Drozdek"....and i am at a loss as to where i can get the solutions for the programming assignments. If anyone ...

### 3. Tower of Hanoi algorithm    coderanch.com

1. What is Stream IO? I know it is like input and output, but what exactly is it? What's the difference between IO.stdout.print and System.out.print? 2. The following is a code that my teacher did in class about a game called The tower of Hanoi. I didn't really understand how it works: public class Hanoi { private static void hanoi (int ...

### 5. Good book to understand the Analysis and Design of Algorithm    coderanch.com

Analysis of algorithms is really all math. How heavily do you want to get into the topic? The math is usually straight forward, but it uses calculus heavily. If you don't understand calculus, its going to appear opaque. For years, Stanford University used Donald Knuth's Concrete Mathematics as a prerequisite for analysis of algorithms. Any university bookstore will have the textbook ...

### 6. Extended Euclidean Algorithm    coderanch.com

Hi all, I am doing an encryption program, and need to find the x and y in this formula: gcd(a,b)=a*x+b*y; I know the idea is to follow the steps of the actual Euclidean algorithm, and then just doing everything backwards, but I don't know how to put that in code. One thing to note, gcd (a, b) will be 1 in ...

### 7. How to write a rescursive algorithm?    coderanch.com

So I'm whizzing through the practice competitions on TopCoder, and come across this 600-pointer. I didn't have a clue how to solve it, but checking some other people's code it seems they use a recursive solution. However since other people's code is written against the clock it's not exactly readable and nicely annotated, so I wasn't much the wiser. My question ...

### 8. Algorithms.    coderanch.com

I would recommend picking up a textbook on algorithms and trying to work through it. The book "Introduction to Algorithms" by Cormen, Leiserson, Rivest, and Stein is a standard text for an undergraduate-level algorithms course. You should be able to find older editions available used for not too much money. This should give you a good sense of how much you ...

### 9. algorithm in java    coderanch.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, with this additional constraint: if there are numbers in the array that are adjacent and the identical value, they must either all be chosen, or none of them chosen. For ...

### 10. help with developing a basic java program and algorithm for a program i am working on    coderanch.com

I want to develop an executable java program that, when opened, floats over a web-page; a GUI with tabs combo boxes and the like. The purpose of this program is to fill a webpage TEXT-BOX OR MESSAGE-BOX with any information you want, similiar to autofill in Google Chrome. I'll figure out how to hammer out the code in the coming days, ...

### 11. Algorithm for static binding    coderanch.com

Hi there, in the Java Language Spec, chapter 15.12, there is a rather exhausting description of the compile-time steps which are done to bind a method invocation to a declaration. This description might be precise and complete, but I find it quite difficult to use as a starting point for implementing a static binding algorithm. In the JustAddJ compiler, I found ...

### 13. Johnson Trotter Algorithm help    coderanch.com

**Overview:** I am trying to implement the Johnson Trotter Algorithm in Java so that I can solve a problem on Project Euler. I have looked and looked but as far as I can see I have everything implemented right, which you know is wrong, otherwise I wouldn't be asking this question The basic algorithm goes like this: Johnson Trotter(n) //Input: A ...

### 14. How to write an algorithm for an average of values?    coderanch.com

Hi, I'm trying to write a method that uses a sentinel loop that repeatedly asks a user for input until a negative number is entered, and then prints the average. I wrote the following code so far, but I can't figure out how to write an algorithm for the average? Any help is appreciated, thanks! public static void printAverage() { Scanner ...

### 15. Algorithm not working?    coderanch.com

Hi, my algorithm (wins/numberOfGames)*100 is not working; it's printing out 0 every time, even though all four other variables are working fine. Is my algorithm itself not correct? I just assumed win% means the percentage of games won. Thanks as always! public static void stats(int numberOfGames, int wins, int losses, int ties) { System.out.println("total games = " + numberOfGames); System.out.println("wins = ...

### 20. Let's Check My Collision Detection Algorithm    java-forums.org

Hello everyone. I need a bit of help with a collision detection algorithm I'm working on. It's kind of a complicated mess at the moment. What we have here is a tile-based side scrolling thing. I want my sprite to not pass through tiles, and I have a method that finds a tile that's been collided with and can return it, ...

### 21. Help with an Algorithm    java-forums.org

Date implements Comparable so it would be a good starting point. You could use the TableRowSorter class (j2se 1.6+). Click column headers to sort. Java Code: import java.awt.*; import java.text.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; public class DateSorting { DateFormat df = new SimpleDateFormat("HH:mm"); JTable table; private JScrollPane getContent() { DefaultTableModel model = getModel(); table = new JTable(model); TableRowSorter sorter ...

### 22. Algorithm Problem    java-forums.org

Can someone look at this algorithm for me and tell me why it does not compile and if it actually makes sense. /** * Creates a loop to determine how many frogs will take part in the race. */ public int Members(); //1 public int selected(); public int frogNumber(); public int Members = 0; { while(this.Members < 2) this.frogNumber1 = false; ...

### 23. need help with Java coding for North West Corner algorithm    java-forums.org

:confused:Hi, I wrote a code to generate a table that reflects the supply of factory and demand of warehouse. here's the data Factory Supply warehouse demand Factory 1 100 Warehouse 1 150 Factory 2 200 Warehouse 2 180 Factory 3 300 Warehouse 3 270 I am suppose to write a program that would generate a table which looks like this 100 ...

### 24. help with rc5 algorithm implementation    java-forums.org

help with rc5 algorithm implementation can any one help me with this code... import javax.swing.*; import java.util.io.*; public class Rc5 { private int[] s; private int[] l; private int b, u, t, c; private byte[] key; private int rounds; public Rc5() { String str = "tallwalkers"; key = GetKeyFromString(str); rounds = 16; b = (int)key.length; u = 4; t ...

### 25. Need some help in an algorithm    java-forums.org

hello I have prepare to codes: 1) a timer that returns every sec the date 2) A simple program that returns some infos What I want to do (and I cant) is: every sec that the date is returned from prog 1, to return also the infos of prog 2 Prog 1 ---------------------------- import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; ...

### 27. Algorithm help? :)    java-forums.org

I have managed to achieve this task using 10 different variables (one for each row) since the grid is 10 by 10. The steps are: 1. picks up and counts beepers in first column, assigns the number to variable "a" 2. moves to the second column 3. picks up and counts beepers in second column, assigns the number to variable "b" ...

Hey everyone! So i just got out of my first java programming class, and i've got my first homework assignment. I just want to know if my logic is heading in the right direction, maybe get some tips, any help would be greatly appreciated. heres my problem. i need to write an algorithm for a program that can do the following ...

### 29. A* algorithm    java-forums.org

Hi, I am trying to create a program which uses the A* pathfinding algorithm, and I really don't know what is wrong with my code. At the moment, is set up to just print the x y co-ordinates of the path it produces. Here is my code: Java Code: public void goTo (int x, int y){ List openList = new ArrayList(); ...

### 30. Algorithm for converting binary/hex to decimal    java-forums.org

We were asked to convert hex/bin to dec without using the parseInt parseDouble through the Scanner class. I started using the switch statement. My problem is that I don't know how to loop the number of inputs in the scanner class, since every input out of 6 inputs would have to undergo the process of conversion. I'm trying a while loop ...

### 31. Algorithm problems..    java-forums.org

import math import random def simulator(alpha, beta): ta = 0 ts = 0 c = 0 Q = 1 while(c<=480): if ta

### 34. Algorithm Design    java-forums.org

Hey guys I am new to java and wanted to start doing algorithm design. I really do not have any clue on where to start and wanted to see if someone could point me in the right direction. My goal is to be able to design an algorithm for tic tac toe and Connect Four. Thanks and any hep will be ...

### 37. My A* Algorithm(code), How can I make it faster?    java-forums.org

My A* Algorithm(code), How can I make it faster? I have been learning java for about a week now. Started doing things with path finding. Making a game to test out the code. Anyways, it doesn't sound like a lot but finding a path from a 2d map from 2,2 to 90, 90 where the map is 100x100 takes ...

### 38. Prompt algorithm    java-forums.org

We aren't going to think of it for you, that's not really how this works. Think about it logically- write this out on a piece of paper, and solve it. How did you do it? How did you come up with the expected output in your original post? Think about it step by step.

### 40. StableMatch - Gale Shapley algorithm aka the Stable Marriage    java-forums.org

I'm having some trouble getting my StableMatch program to work. Any advice is welcome. Here's the code in question: I'm getting Type mismatch: cannot convert from Person to E. Java Code: // sets the name of the match for the Person provided public void setMatch(Person name){ match = name; } and here's the class code Java Code: public abstract class Person ...

### 41. Need help in Designing and implementing bucket-sort algorithm    java-forums.org

/** Fill in bucketSort and entry.java for 100% * OR * Fill in bucketSortGeneric and genericEntry.java for 120% */ import java.util.LinkedList; // import java.util.ArrayList; class sortMethods { public static void bucketSort(LinkedList List, int maxKey) throws IllegalKeyException { } public static void bucketSortGeneric(LinkedList List, int maxKey) throws IllegalKeyException { } }

### 42. need help figuring out algorithm    java-forums.org

For my comp sci class I'm making a program that a library would use. Part of it has to be able to calculate the late fee for a book. I've figured how to get the current day/month and all that stuff, but for the life of me I can figure out an equation to calculate how late the book is. To ...

### 45. How to differentiate two algorithm?    forums.oracle.com

Let me make my question more clearly: See below code, I have call algorithm two times, one is for command OK, one is for command Interpolate. else if (command.equals("OK")) { callAlgorithm(); } else if (command.equals("Interpolate")) { callAlgorithm(); } When I implement algorithmPerformed method, I use sampleAlgo for 'OK' command, extractVOIAlgo for 'Interpolate'. My question is how to let java know which ...

### 46. HELP REGARDING SHORTEST ROUTE ALGORITHM    forums.oracle.com

I HAVE CREATED A GRAPHICAL USER INTERFACE FOR THIS SHORTEST ROUTE ALGORITHM Using Netbeans all i need to know is how to add the code for some specific functions that it does there about 4 to 5 issues i am struggling with i creatted two buttons and two text boxes The First Text box followed by an ok Button and the ...

### 48. bankers algorithm problem need help!!!!    forums.oracle.com

i have a problem..will someone willing to help me.. ii'm an IT student but im not really good to programming language...do you a code ffor bankers algorithm problem..i need your reply..please have mercy i need to pass this on may 15, 2008.. i really dont know how to make programs.. tanks alot ..

### 51. Need help! Algorithm java implementation    forums.oracle.com

Sounds like you have all the information you need. Start with step 1. Write code to make copyStack and sAux empty stacks. Verify that it does what you want (System.out.println() may be useful here). Once step 1 is working correctly, move to step 2 and repeat. When you reach the end, you're done!

### 53. Need help writing new car algorithm***    forums.oracle.com

carCost gets inputted by the user. The values it cannot find are ones being returned from the methods. I cant figure out why its not returning the values...maybe im not calling them correctly? When i initialized monthlyPayment in the main to 0.0 it just printed 0.0 not the value returned by the method.

### 55. How to solve this algorithm?    forums.oracle.com

ps: lets say we have number n = 12 decimal = 1100 binary, v = 0 and position p = 2 (positions start from 0,1,2...), . We change bit on position 2 from 1 to v=0 so the number n becomes 1000 = 8. Edited by: Spyro on Dec 28, 2007 10:26 AM

### 56. How to make this simple algorithm?    forums.oracle.com

Can u give me some hints how to make this without using arrays, or loops. (im making it now with manual conversion of decimal to binary value and assigning each bit to variable but dont know how to insert the comparement ). Write boolean expression that returns true if the bit at position "p" in given integer "v" is 1. Example: ...

### 57. Luhn Algorithm validation code    forums.oracle.com

1. Starting with the rightmost digit (which is the check digit) and moving left, double the value of every second digit. For any digits that thus become 10 or more, add the digits together. For example, 8762 becomes 7732 (the second digit from the right is 6, 2 ? 6 = 12, and 1 + 2 = 3, so 6 is ...

### 58. Algorithm to find out checkdigits    forums.oracle.com

The String Array c contains the "stringified" individual elements (including hypens) of a ten-digit ISBN. (In the above example, the contents of c would be "0", "-", "2", "0", "1", "-", "5", "3", "0", "8", "2", "-", "1", in that order.) Complete the following code to store in the boolean variable good the value true if and only if the ISBN ...

### 61. Confusion Algorithm... Help    forums.oracle.com

yes.. but 'f' is in the second box since size of each box is 4. inorder to get the value node from the list.: First, you have to jump to the box that has the value. In this case second box. and 'E' is the boxheader. Next, you run from boxheader to the value node inside that box and return that ...

### 62. connect four algorithm    forums.oracle.com

Step back and think about design. A major concept is the board. Concepts become classes. What operations does the board expose? How will you test them to see if they work? consider the user interface later. This same board class should be able to work with an application that uses console output, Swing, a web application, human players/algorithms, etc...

### 63. Algorithms    forums.oracle.com

Hello, I was wondering about the best way to implement the cousin chart algorithm in java. My idea was to have a main method with a vector for auxiliary methods of the algorithm, ie, for each of the equations: x = min (Ga,Gb) y = |Ga-Gb| If x=0 and y=0 then they are the same person. If x=0 and y=1 then ...

### 66. need java algorithm that runs forever with heavy cpu usage    forums.oracle.com

Hello @ all, i am trying to create a program that starts some threads depending how many cpu cores are installed in the computer. these threads should bring up the cpu usage to 100% on every single core (without ending). why i am doing this? i want to run this program on notebooks to check how long the battery will work ...

### 68. Algorithm for arranging people according the choices of food    forums.oracle.com

i am creating a program that does the following: There is a banquet with 6 food items, labeled F1-F6 Given n number of people, each of which arrange the preference of F1-F6 into P1-P6 (preference 1 to preference 6) There are limited number of tables(t), and limited number of food on each table (3). How can I arrange the people so ...

### 69. Help to do a simple algorithm    forums.oracle.com

I wanted some help for coding for two different logic below.I am just learning java, and have to make a command base program. 1> Calculate minimum change in nearest cents and dollars as in change can be \$2, \$1, 50c, 20c, 10c, 5c so if change returned is \$2.30 2>a 5 digit alpha numeric no is calculated in such a way ...

### 72. Hierholzers Algorithm    forums.oracle.com

the graph is represented as a matrix of integers, i have printed one out to show you. As far as i understand each index of the array at the top is equal to a node and the integer values are the number of connections between the node at the top and the value at the side?

### 74. the best compression algorithm to use    forums.oracle.com

Hello Suners, I have a 7 GB file and i need to compress it to be 2 GB at most in order to upload it and download it faster. What is the best compression algorithm to use in this case? can i get the desired size and if i do how could i decompress it?

### 75. Duplicating wincrypt algorithm in JAVA    forums.oracle.com

Here is the background on this project: I am creating an automated licensing system for a company that sells telco products. Until now, they have been manually generating the activation keys using an exe program developed in house. I have been hired to remove some of the manual interaction required from the employees, one of which is to automatically generate these ...

### 76. Euclid's algorithm for greatest common divisor!!!    forums.oracle.com

Lol, i just like to get to the conclusion more quickly when doing programming, my brain was not working at all a while ago but the way you have explained me each and every bit in detail, im feeling quite better now Thankyou very much for your precious time, and for sharing your programming tips on how can i improve and ...

### 77. Jsapi Algorithm    forums.oracle.com

Does Any body know the algorithm that is used by JSAPI? I developed my final year project using JSAPI. Inorder to submit my Project report, i want the algorithm that is used for Speech Synthesis and Speech recognition. I searched in google and i some algorithms like HMM etc. But i dont know which one i should submit. If anybody help ...

### 78. Make algorithm faster    forums.oracle.com

I have an algorithm that gives the first million prime numbers. The problem, is its very slow. How can I speed it up and how do I print the first ten prime numbers and the last ten? I want to stop checking when I reach the square root of the number. Do I put that in my for loop or in ...

### 79. Efficient algorithm for getting grid neighbors?    forums.oracle.com

If you want a grid with width X and height Y, then you could use a indexed approach by utilizing a single array beginning at the 1st element. Given an index i, to find the surrounding neighbors: - N = i - X - S = i + X - E = i + 1 - W = i - 1 ...

### 82. Noob Needs Help Making Algorithm !!    forums.oracle.com

This is the first question: (I think I just need a helping hand to get me started) Write an algorithm to compute the arrival time of a train, if you know the starting time and the distance to destination (in km). Assume that the average speed of the train is 60km/h. The start time is given as the hour (using 24h ...

### 83. Help with checkerboard algorithm    forums.oracle.com

I'm not sure if there is a most correct or elegant way to do this, but the algorithm is solvable by the pencil and paper method, that is by solving how you'd explain to someone how to do this with a pencil and paper and without the use of a computer. So if you can solve the pencil and paper algorithm, ...

### 84. O(log n) algorithm    forums.oracle.com

Hi, I have a problem at hand and i kinda need a head start in the same. I have an array with some values inside and basically i need to check if the array (index value+1) == the actual value in that index and if so, i need to increase a counter. int a[] = {-1, 0, 2, 4, 5, 6, ...

### 85. Folder syncronization algorithm    forums.oracle.com

Hey I'm working on a Swing app that lets you synchronize 2 folders over the internet, and I'm interested to know your thoughts on synchronization methods. So the algorithm/method should: 1) decide whether a file should be sent/received based on its existence or modification date 2) handle file deletions. i.e. if i use windows explorer/nautilus/whatever to delete a file, that deletion ...

### 86. Need help with a algorithm type thing    forums.oracle.com

The business of condensing is then entirely based on the disk data, and can be done at any time (eg, when the amount of "deleted" space exceeds some percentage). My suggestion would be something like this: 1. Read the values from your old file, writing out any that aren't "deleted" (or whose length is not negative) to a new one. 2. ...

### 87. Implementing mathematic algorithms for convertion    forums.oracle.com

public void actionPerformed(ActionEvent e) { String source = input.getText(); double value = Double.parseDouble(source); String option1 = leftBox.getSelectedItem().toString(); String option2 = rightBox.getSelectedItem().toString(); String destination; if (option1.equals("Fahrenheit") && option2.equals("Celsius")) { double result = (5/9)*(value -32); destination = Double.toString(result); } else if (option1.equals("Kelvin") && option2.equals("Celsius")) { double result = value + 273; destination = Double.toString(result); } else if (option1.equals("Kelvin") && option2.equals("Fahrenheit")) { double result ...

### 88. Politically Safe Algorithm ???    forums.oracle.com

It might mean that people are less likely to claim you chose the wrong algorithm. If you use an algorithm that people are familiar with and is commonly used, you are less likely to be asked to defend your decision than if you choose an algorithm you found on a shady website (even if the shady algorithm is indeed better).

### 90. n-Tree rendering algorithm.    forums.oracle.com

It's not homework, it's a personal project. I don't need help with my homework, I'm a semester away from graduating with a Computer Science Masters, thanks. The reason I ask is that I know tree algorithms are usually available around the net for common operations like searching, inserts, etc, but I can't seem to find an algorithm to render a tree ...

### 91. Fast Pattern Replacement Algorithm    forums.oracle.com

Hi there ! I was wondering if there's any already implemented fast pattern matching algorithm. This is my usecase:There's a String (e.g. "aaabbbaaaabbbccccbbbaaaakkkkaaaaaaa" ) and I want to replace all kkkks (matched by a regular expresssion, no string equality!). However, i have to replace them with the result of a cipher-function f( pattern ). The main problem is, that I need ...

### 93. Knights Tour algorithm problem    forums.oracle.com

Adamski wrote: Problem is, for it to work correctly, it needs the 5th jump to be at the far bottom left. Instead it's two spots to the right. Are you expecting to hard-code a solution to the Knights Tour problem? I don't think that it works that way, and you may want to interject a component of randomness to your program. ...

### 96. Rotational Algorithm    forums.oracle.com

For 3D graphics, points are normally represented as vectors, and transformations as matrices. Instead of moving the camera around, you can think of moving the points around a static camera (the points move in the opposite direction to the camera). If you represent a point as a 3D vector (x,y,z), then you can multiply it by a rotation matrix to get ...

### 97. How to get the algorithm?    forums.oracle.com

All you can do is get as many examples as possible and try to see what's happening. A first guess might be that: 31 represents the initial 0 of the month, 2;. is padding, that 32 to 33 would represent 6 to 7 in the units position of the month, and possibly that 26+x would represent x; ) is padding or ...

### 98. Fastest algorithm to append a id to an ipaddress depending upon the net id    forums.oracle.com

Thanks for your reply. But, don't you think this might have performance issue in worst case scenario or even in not so worst case scenarios. Suppose, I have million records and half of them do not have corresponding ID and net ID's in the list. Then if the list has 1000 entries but nothing for the source IPs received, the map ...

### 100. Greedy Algorithm - Java    forums.oracle.com

Hi I have a few questions about the greedy algorithm. This is my code: private Array[] result; public void makeGreedyPath(Vertex v) { int smallestPath = 999999999; Vertex temp = null; for(int i=0; i