homework

Ocaml - Iterative to Recursion

For an assignment, i have written the following code in recursion. It takes a list of a vector data type, and a vector and calcuates to closeness of the two vectors. This method works fine, but i dont know how to do the recursive version. let romulus_iter (x:vector list ) (vec:vector) = let vector_close_hash = Hashtbl.create 10 in...

How to fill a binary tree from a string, java.

Hi, I'm suppose to fill a binary tree with integers based upon a string like this. [int](LT)(RT) LT is an expression of the same form for the left part of the tree. Same with RT. A valid string would be something like this: 4(2(1)(3))(6(5)(7). How can I fill this tree? This is not a sorted tree of any kind. So it can just fill every...

C++ Abstract base class array of ptrs to ptrs

I have an abstract base class (Comparable) with Date and Time virtually inheriting from it and a DateTime class v-inheriting from Date and Time. My problem is this: I was tasked with dynamically allocating an array of Comparables. Comparable ** compArray; compArray = new Comparable *[n]; // where n is user specified number of elements ...

Question on Scheme with Best First Search algorithm

Okay this is a homework question, and I just don't have a clue how I suppose to start. Some help and hints will be much appreciated. I need to use a heuristic function to solve a maze type problem. Suppose I have a 5x5 grid, and a robot in position (1,5) and my goal is to move the robot to (5,1). Along the way there are few obstacles...

Scheme How To Test 2 Conditions in one Clause ?

I need to create a sub-function that will return me all the adjacent node, which I needed for this question in Scheme. I'm new to scheme, not sure how I can combine two conditions into one test case ? Basically my algorithm is to test if the node is on the edge or not. This case I use a 5x5 grid. If both node is on the corner meaning ...

Adding item to array PHP

I'm building a shopping cart for a school assignment. I'm pretty much there except for adding the items to the cart variable. I've set up my cart session with: $_SESSION['temp_session'] = array(); and then, when a item is added to the cart, this code is executed if (isset($_POST['addtocart'])) { $item_name = $_POST['item_name']...

In regex, what does \w* mean?

In Python. r^[\w*]$ whats that mean? ...

What does this function do?

def fun1(a): for i in range(len(a)): a[i] = a[i] * a[i] return a ...

How do I execute this function?

def fun1(a,x): z = 0 for i in range(len(a)): if a[i] == x: z = z + 1 return z ...

Is there any trick to handle very very large inputs in C++?

A class went to a school trip. And, as usually, all N kids have got their backpacks stuffed with candy. But soon quarrels started all over the place, as some of the kids had more candies than others. Soon, the teacher realized that he has to step in: "Everybody, listen! Put all the candies you have on this table here!" Soon, ther...

How to Assign Mulitpule Caulated Value Into List in Scheme

Okay this is my 4th question today on Scheme, still pretty new to Scheme, as I needed for one of my sub-function I asked earlier in the day. Basically this will return me the difference of 2 lists. Say you've got (1,5) and (5,1) this function should return me 8. As that's the distance between l to w Here is what I have. Note: if I cha...

Java OO Questions

1) If i define a java method: void ChangeObject (Object o) { o = new Object(); } And in my main program, i instantiate an object o and call ChangeObject with o passed in. Will o remain intact after this method is run? 2) If i have two class: Child and Parent. And child is a subclass of parent. Which of these two statements will comp...

Longest common substring with constant memory?

Given two strings -- how can you find the longest common substring using only constant memory? UPDATE: The time constraints are to solve it in O(len1 * len2), like the standard dynamic-programming solution. ...

ANSI C: Creating an Array of Jobs

So, we have this homework assignment that builds off of last weeks. We are supposed to create separate arrays that hold pointers to all the people of a certain job type. Here is the code I have so far. I was wondering if any one can help me out. Thanks! #include <stdio.h> #include <stdlib.h> #include "Person.h" #include "data.h" #define...

What does out[i] = *(a_mat + i) do in C?

while( i < a_rows * a_cols ) { out[i] = *(a_mat + i); // this line i++; } What does the marked line do? ...

Complexity of a given function

When I analyzed the complexity of the code segment below, I found that it is O(n/2). But while searching the internet I discovered that it is probably O(n). I'd like to know who's correct. void function(int n) { int i = 1, k = 100; while (i < n) { k++; i += 2; } } ...

java chat application

I want to devlop java chat application. I am looking for any java framework that will help me in devloping chat application. So that i can easliy devlop the chat application using the framework. The application needs to run only in LAN. I want the chat application like yahoo chat (with only one main room). Please suggent me any open s...

Virtual Machines and Handling Memory and System Calls

This is a homework problem that I have. I have been doing some research and couldn't find much. I did find a powerpoint but could not make much sense of it due to lack of text. http://xen.org/files/xensummit_tokyo/19_KoichiOnoue_en.pdf (Specifically, what is gPa and hPa?) I was wondering if anyone could point me in the correct directi...

Selection , Finding the largest of a set with Ternary comparator.

Let S be a set of n>0 distinct integers.Assume that n is a power of 3. A ternary comparison can compare three numbers from the set S and order them from the largest to the smallest. Describe an efficient algorithm that uses as few as possible ternary comparisons to find the largest number in the set S.Explain why your algorithm is corr...

Converting an input word number (like seven) into a character (like @)

so if the user types down seven with Scanner, @@@@@@@ (7) will be the output. I'll have to use a for loop statement but I can at least figure out that much. Just need help with figuring out a way to convert word numbers into a numerical number and finally into a random character. ...