homework

Balancing the tree

How to balance this tree structure 13 / \ 8 18 / \ 14 19 \ 15 ...

Creating a "crossover" function for a genetic algorithm to improve network paths

Hi, I'm trying to develop a genetic algorithm that will find the most efficient way to connect a given number of nodes at specified locations. All the nodes on the network must be able to connect to the server node and there must be no cycles within the network. It's basically a tree. I have a function that can measure the "fitness"...

Basic home work question what am I doing wrong.

/* Method: findName() */ /** * Finds the name of the entry and sets it to the name variable. */ private void findName(String line){ end = line.indexOf(" "); name = line.substring(0,end); } /* Method: findDecades() */ /** * Finds the name of the entry and sets it to the name variable. */ private void findD...

Multiplayer Networked Anagram game

Hello! I need some help about this little project. I'm begginer in java and it seems to me too hard to make it by myself. So please Help me. I will apperciate any help... A waiter delivers a sequence of letters to various players who are connected. Each player proposes a server anagrams he discovered from the sequence of letters: the...

How to count words in java

Hi All, I am looking for an algorithm, hint or any source code that can solve my following problem. I have a folder it contains many text files. I read them and store all text in STRING. Now I want to to calculate, if any of the word appeared in other files or no. ( I know its not clear let me give an example) For example i have two do...

Accessing instance variables from objects in a list

I'm working on a self-assigned project over break, and am running into one major sticking point. This is a basic line-recognition program in Java. I have a Points class which creates the Point from the ordered pairs & sends it to the Line class for slope & intercept calculation. The results are sent back to the Points class which dep...

How to write data to a file through java?

I want to make a GUI application that contains three functions as follows: Add a record Edit a record Delete a record A record contains two fields - Name and Profession There are two restrictions for the application You can't use database to store info. You have to use a flat file. Total file should not be re-written for every add...

How to delete a data from a file through java?

I want to read a file in java. And then, I want to delete a line from that file without the file being re-written. How can I do this? Someone suggested me to read/write to a file without the file being re-written with the help of RandomAccessFile. http://stackoverflow.com/questions/1984534/how-to-write-data-to-a-file-through-java Spec...

Plane equation for 3D vectors.

Hi, all.I want to find a 3D plane equation given 3 points.I have got the normal calculated after applying the cross product. But the equation of a plane is known to be the normal multiply by another vector which what i am taught to be as P.OP. I substitute my main reference point as OP and i want P to be in (x, y, z) form. So that i can ...

coin changing problem

suppose i have a set of coins having denominations a1, a2, ... ak. one of them is known to be equal to 1. i want to make change for all integers 1 to n using the minimum number of coins. any ideas for the algorithm. eg. 1, 3, 4 coin denominations n = 11 optimal selection is 3, 0, 2 in the order of coin denominations. n = 12 optimal ...

unbiased random number generator using a biased one

you have a biased random number generator that produces a 1 with a probability p and 0 with a probability (1-p). you do not know the value of p. using this make an unbiased random number generator which produces 1 with a probability 0.5 and 0 with a probability 0.5. Note: this problem is an exercise problem from Introduction to Algorith...

Declaring array variables

Hey guys, got a problem with a question. Question : Write a declaration for a variable people that could be used to refer to an Array of objects of type Person My answer: public people[]; people = new Person [100]; But I am getting an error saying it is wrong. What am I doing wrong? PS. I also tried public people[] = new Person [10...

Initialising Array Variables

I got a problem with a question. Question: an Array instance variable called people has been set up by the line: public Person[] people; Write the line that will initialise/instantiate it to take 100 objects of type Person. My answer: public Person[] people; double []people = new Person [100];` The error that I am gettin...

Array Instantiation

Can you help me out with this question please. Question: Given the following array declarations double readings[]; String urls[]; TicketMachine[] machines; write assignments that accomplish the following tasks: make the readings variable refer to an array that is able to hold sixty double values make the urls variable refer to an ...

counting float digits (hw) C

i need to count digits from a float number and keep the number. i can use scanf for %f or %c but not %s, and i can use getchar(). i can use getchar but ill loose the number ...

Variables and function

Hey all, is it possible to call a function value instead of calling the whole function?As, if i call the whole function, it will run unnecessarily which i do not want. For example: def main(): # Inputing the x-value for the first start point of the line start_point_x_1() # Inputing the x-value for the 2nd end point of the li...

How To write comments ...

Hi I have like 50 pages of code that I should write comments to it ... Can you guys show me the best way. I meant I need you to write me a sample ... the comments should contain nearly everything (classes, constructors, attribute, methods, events, functions) ...

Reading values with raw_input in Python

I am trying to do integration in Python but whenever I key in a value my outputs always results in 0. What the reason? E.g.: def main(): eq_of_form() value_of_a() value_of_b() value_of_c() value_of_m() value_of_n() value_of_x() area_under_graph() def eq_of_form(): print "Eq of the form y = ax^m + bx^n + c ...

Vectors for 3D plane

anyone knows how to write: ( x - 2 ) ( y - 3 ) ( z - 5 ) in python? Given Point P = (x, y, z) and Point OQ = (2, 3, 5) I tried defining Point P with a variable and subtract it with Point OQ.But the problem seem to lie with the x, y, z. The error i keep getting is that x is not defined etc. Anyone got any idea? ...

Find the closest number in a list of numbers

I have a list of constant numbers. I need find the closest number to x, in the list of the numbers. Any ideas on how to implement this alogrithm? Thank You. ...