homework

How to compare 2 files lexicographically using C

Hey guys, I'm currently trying to implement a function using C that takes in two file names as command line arguments and compare them lexicographically. The function will return -1 if the contents of the first file are less than the contents of the second file, 1 if the contents of the second file are less than the contents of the firs...

java ( how the program find and print that sum and product. Ex.4)

Exercise #3: Write a program that reads 3 integer values and then the user may input the sorting order preference in small or capital letters (i.e., a or A for ascending order, d or D for descending order). Sample input/output: Input 3 number: 7 8 3 Input sort order (a or A for ascending, d or D for descending): d 8 7 3 Exercis...

Java - how to get the "try again (j/n)" to work.

package myProg; import java.util.Scanner; public class oving4a { /** *Øving 4a. Aleksander Pettersen */ public static void main(String[] args) { Scanner scan = new Scanner (System.in); int i; int count = 0; String another = "y"; double symbol =(1+Math.random()*100); in...

solution to towers of Hanoi problem

how do i solve for running time in the towers of Hanoi problem. I get a recurrence realation like t(n) = 2t(n-1) + 1. After drawing the recursion tree i get at every step values like 1+2+4+8... the height of the tree will be lg(n). how do i calculate the sum of the series? when do i stop? ...

Matlab, graphing functions

Hello! I have a homework problem, I think I did it correctly but need to make sure 100%. Can anyone check for me, before I hand it in? Thank you. Question: Plot the function given by f (x) = 2 sin(2x) − 3 cos(x/2) over the in- terval [0, 2π] using steps of length .001 (How?). Use the commands max and min to estimate the maximum and mi...

How to output the Binary value of a variable in C++

I've got a homework assignment in my C++ programming class to write a function that outputs the binary value of a variable's value. So for example, if I set a value of "a" to a char I should get the binary value of "a" output. My C++ professor isn't the greatest in the whole world and I'm having trouble getting my code to work using th...

Finding the maximum-sum sub=rectangle within a matrix

Possible Duplicate: Getting the submatrix with maximum sum? Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the largest sum. The sum of a rectangle is the sum of all the elements in that rectangle. In this problem the sub-rectangle with the largest sum is referred to as the maximal su...

Seg Fault when initializing array

Hi guys, I'm taking a class on C, and running into a segmentation fault. From what I understand, seg faults are supposed to occur when you're accessing memory that hasn't been allocated, or otherwise outside the bounds. 'Course all I'm trying to do is initialize an array (though rather large at that) Am I simply misunderstanding how to ...

How should I objectively test my program results?

I have developed two differing methods in MATLAB which aim to analyse a pop song and then automatically create a 30 second audio thumbnail (a preview clip) containing part of the chorus section. Both methods have varying results: The first method can create a thumbnail for each track, managing to find a chorus section in 40 out of 50...

Help with asymptotic analysis

Hi, I'm rather new to programming and have recently been introduced to the topic of asymptotic complexity. What I'm curious about is how to figure out the asymptotic complexity of a sorting method, given the number of elements and the time taken to sort them. Here is an example of what I mean. Time for 'sortArray' to sort sorted arra...

What is the difference between a liveness and a progress property?

Hi all.. I know this is a very academic question, but I was hoping someone here could help me get an answer. I'm taking a concurrency class in which we use LTS'es and FLTL's. In one of our assignments a question is given: "Give an example of a liveness property, expressed as an FLTL formula, that cannot be expressed as a progress prope...

Java Counter Problems

For the public void setValue(int newcount) how do I make it so the value the other program sends is used to set the newcount? Also I have to do this "If the newcount < zero or > maxValue, do nothing." private int maxValue; private int count; /** * Constructor for objects of class Counter */ public Counter(int ma...

Java Generics 'Incompatible Type' Compile-Time Error

For a CS class I am writing a linked list implementation of a linked list interface created by my professor. The assignment requires us to use generics for the list. What I have created, I think, is pretty standard. public class MyLinkedList<T> implements ADTListInterface { ... private class Node<T> { Node<T> head; ...

Dumb 8 Queens problem in C++ using goto and backtrack

I have been working on multiple 8 queens problems in my C++ class. I got the bazic 8 queens problem. Now I am having an issue printing out the solutions using the goto and backtrack statements. // Queens2.cpp.cpp : Defines the entry point for the console application. // 8 Queens problem using goto and backtrack. #include "stdafx.h" #...

embedded programming in C

Hi, I am a newbie as far as it comes to embedded systems programming. I have to write lots of simple C or C++ programs like atoi, itoa, oct_to_dec, etc., which would have been easy to write in normal C. But my hardware unit does not have the usual header functions and hence I cannot use standard library functions. :( Could someone hel...

How to count the number of operations in a loop and give a theta characterization

I just want to make sure if I am doing this correct. I am trying to count the number of operations performed for the worst case scenario in java int sum = 0; for (int i = 0; i < n; i++ ) sum++; Is the number of operations 2+3n or 3+3n? I got the answer from counting int sum = 0 and int i = 0 for the "2" and i < n, i++, and su...

Generating Large Prime Numbers for Diffie-Hellman in Ruby

I'm writing an implementation of a diffie-hellman key exchange in ruby for a project for one of my university classes. I need to generate large (secure) prime numbers of at least 500 bits length. Any ideas? Should I use the OpenSSL library? If so, what functions would you recommend? ...

Newbie cant see why code is erroring, but knows where it is erroring

I have a problem with my code, good news is I actually pinpointed the problem, bad news is I do not understand why it is a problem. Also should this be return or exit? This is my getNums() function,...so far. first my code calls getLine() which gets the line and returns its character length. Then get nums is given, the line, length o...

Squaring n-bit int vs. multiplying two n-bit ints

Disclaimer: Homework question. I'm looking for a hint… Professor F. Lake tells his class that it is asymptotically faster to square an n-bit integer than to multiply two n-bit integers. Should they believe him? I believe that multiplying two n-bit ints via shift/add is an O(n) operation, but I can't see why squaring an n-bit int would...

Code to solve determinant using Python without using scipy.linalg.det

Description(this is a hwk question): I am not sure where to start here. I plan to use Laplace's Expansion but I am not sure how to implement it for nxn matrices. Any help would be appreciated. Note: I already have a function to generate random matrices for a nxn matrix. Also the timing the calculation isn't a problem. The only thing I...