homework

Calling a global Array

Hi, I'm currently trying to draw shapes with 2D Arrays. In my class there is a global array defined with public char canvas[][]; Up until now, I have only declared arrays with char canvas[][] = new char[height][width]; If this Array has already been declared, and I'm not supposed to amend the code I've been given, how do I call an in...

Print space after each word

Hi, what is an easy/effective way to combine an array of words together with a space in between, but no space before or after? I suppose it is possible to remove the space after combining everything in a loop (something like sum += (term + " "))...I don't like it though. Preferably code in Java, Python, or Ruby. Thanks! ...

How to compute optimal paths for traveling salesman bitonic tour?

UPDATED After more reading, the solution can be given with the following recurrence relation: (a) When i = 1 and j = 2, l(i; j) = dist(pi; pj ) (b) When i < j - 1; l(i; j) = l(i; j - 1) + dist(pj-1; pj) (c) When i = j - 1 and j > 2, min 1<=k<i (l(k; i) + dist(pk; pj )) This is now starting to make sense, except for part C. How would ...

LanMessenger Tutorial

Could someone please provide me with the link to the code of a lan-messenger preferably in c#?? Thanks Guys ...

Does this multithreaded program perform better than the non-multithreaded one?

A colleague of mine asked me to write a homework for him. Although this wasn’t too ethical I did it, I plead guilty. This is how the problem goes: Write a program in C where the sequence 12 + 22 + ... + n2 is calculated. Assume that n is multiple of p and p is the number of threads. This is what I wrote: #include <pthread.h> #include <...

Binary Search Trees

Hi there! I have a question with regards to the Binary Search Tree Implemetation in C++. Here is the question below Implement a simple (non-templated) BST which stores integers. Provide the following operations: Insert, Remove, inOrder traversal, preOrder traversal, postOrder traversal. Use recursive routines for dealing with the tree....

Prime divisors of a number in ML

In ML i want to get the prime divisors of a number. How can I do this, I am beginner. ...

switch structures with structs and arrays?

I had an earlier question about organizing some inputs by name, ID, and then Amount. Now that I have figured out how to get them organized, I need to have 3 outputs; the first by name, the second by ID, and the last by amount. can i use case and switch statements? Every time i tried to, all three outputs were by name. this is what i hav...

how do i remove an element of an array and shift the reamining elements down

hi guys how do i remove an element of an array and shift the reamining elements down so if i have an array array[]={1,2,3,4,5} and want to delete 3 and shift the rest so i have array[]={1,2,4,5} how would i go abot this in the least amount of code! ...

Java: Search in HashMap keys based on regex?

I'm building a thesaurus using a HashMap to store the synonyms. I'm trying to search through the words based on a regular expression: the method will have to take a string as parameter and return an array of results. Here's my first stab at it: public ArrayList<String> searchDefinition(String regex) { ArrayList<String> results = new ...

Java: find 'connected components' in graph as HashMap

Ok, so here goes: I'm building a thesaurus using a HashMap <String,ArrayList<String>> to hold words and their synonyms (this data structure is required). For the purpose of the assignment, the synonymity relation is considered transitive. (We can imagine the thesaurus as a graph). What I'm trying to accomplish is to print this graph in ...

How to solve symbolic equation with double coefficients in matlab?

I have quadratic equation 1/x = 1/(a-x) + 1/(3*a -x) I want to solve it in matlab: solve('1/x=1/(a-x)+1/(3*a-x)', 'x') ans = (4/3+1/3*7^(1/2))*a (4/3-1/3*7^(1/2))*a Is there any way to solve equation with float coefficient? Like ans = 2.215250437021530*a 0.451416229645136*a ...

read text from file

I want to read text from file. For example: "HHEEHEHHEEHHHEEEHHHEEHEHHEHEEEEEEHHHHEEE". And I want to count how many "E" at every 5th symbol? ...

How do I build this finite automaton?

I'm studying for a Discrete Mathematics test and I found this exercise which I can't figure out. "Build a basic finite automaton (DFA,NFA,NFA-lambda) for the language in the alphabet Sigma = {0,1,2} where the sum of the elements in the string is even AND this sum is more than 3" I have tried using Kleene's Theorem concatenating two lan...

Fermat's Little Theorem

How do you compute the following using Fermat's Little Theorem? 2^1,000,006 mod 101 2^-1,000,005 mod 11 Yes, this is homework which is completely allowed in SO! ...

Difference between association, aggregation and composition

What is the difference between association, aggregation and composition? Please explain in terms of implementation. ...

Recognizing tetris pieces in C

Hello!! I have to make an application that recognizes inside an black and withe image a piece of tetris givem by the user. I read the image to analyze into an array. How can I do something like this using C? Thanks and best regards. ...

Search image pattern

Hi people!! I need to do a program that do this: given an image (5*5 pixels). I have to search how many images like that exists in another image, composed by many other images. That is, i need to search a given pattern in an image. The language to use is C. I have to use paralell computing, to search in the 4 angles (0º, 90º, 180º and ...

Need help understanding code

I am taking a C# class and I need help understanding the following code. The code has an array which represents responses to a survey, with values 1 thru 10. The output displays these ratings and the frequency of how many times a value was selected. The following code is from my book, but I have modified it to just a basic example. i...

Partition sort programming problem

I need an algorithm to select the kth largest or smallest value. The values will be ints. My instructor told me to use a modified partition algorithm to find the kth largest or smallest value. Any thoughts? ...