Here's a brain teaser that's been on my mind for a few days.
We have a sequence S of n elements. Each element is an integer in the range [0, n^2-1]. Describe a simple method for sorting S in O(n) time.
Probably something obvious that I am just missing, but I'd appreciate any insight.
...
int handleCommand(char *command) {
pid_t pid;
pid = fork();
if (pid > 0) {
sleep(0.5);
} else if (pid == 0) {
execCommand(command);
//strcat(path[0], command);
//printf("%s", path[0]);
//execve(path[0], path, NULL);
//printf("\n");
} else {
printf("ERROR");
...
Hi everyone.
I've been following this forum for sometime now but officially registered today.
I'm a Java guy learning C++ now.
As an exercise I'm started to rewrite some of the Java code I had written (while I was learning it ) now in C++.
There are several questions here that helped me a lot. But I'm stuck now and need some help.
Th...
Firstly I would like to accept that it is a homework question , but then I know how to code AB-pruning from the algorithm of it . The problem is how to apply it on a grid of numbers where the game can go on in any direction (right , left , up and down ) , thus how will be the tree formed .
Sorry for being a bit vague here , if more inf...
I have written the parser that reads the string input. That works. I have also written the evaluator that spits out the result. But there is one small detail that I'm having trouble implementing. Look at the following example:
+(sw+(2,2),sr)
The sw construct of this tiny language is suppose to evaluate "+(2,2)" and store it somewhere...
#include<stdio.h>
int main(void)
{
static int i=i++, j=j++, k=k++;
printf("i = %d j = %d k = %d", i, j, k);
return 0;
}
Output in Turbo C 4.5 :
i = 0 j = 0 k = 0
In gcc I'm getting the error:
Initializer element is not constant
Which one is logically correct ? I'm in bit confusion..
...
The kth quantiles of an n-element set are the k - 1 order statistics that divide the sorted set into k equal-sized sets (to within 1). Give an O(n lg k)-time algorithm to list the kth quantiles of a set.
The straight forward solution would be to select every k, 2k, 3k .. ik the smallest element, whose running time is O(kn) (k calls t...
If you're unfamiliar with the problem, it's something like this.
I didn't come to ask for an answer, I have actually finished all of my coding. I have just found that my solution doesn't solve it the best way possible, because my solution only allows one car at a time on the bridge. I was hoping I could get some tips about how to go ab...
Given n segments of line (into the X axis) with coordinates [li; ri]. You are to choose the
minimum number of segments that cover the segment [0;M]. Design a greedy algorithm to
solve this problem.
Here what I did:
sorting them by starting points in increasing order, then I choose the longest one, second longest.... But here is a probl...
Hello all,
I have a producer/consumer concurrency problem that I'm working on. The problem is that I'm getting a segfault thrown immediately after trying to create my first thread.
Relevant code:
customer is a struct declared as:
struct pr2_customer
{
pthread_t customer_id;
};
typedef struct pr2_customer customer;
customers i...
I have a class called Coordinate, and am building a vector of these coordinate objects. Here's what the Coordinate class looks like - it's pretty simple:
class Coordinate {
public int x;
public int y;
// constructor
public Coordinate(int x, int y) {
this.x = x;
this.y = y;
}
}
My que...
I have code for a Range class like this:
class Range:
def __init__(self, start, end):
self.setStart(start)
self.setEnd(end)
def getStart(self):
return self.start
def setStart(self, s):
self.start = s
def getEnd(self):
return self.end
def setEnd(self, e):
self.end = e
def getLength(se...
I'm using try on my code and it says illegal start of type. I'm using switch statements but default: continue; do not agree with each other I keep getting continue outside of loop. With the else statement it says illegal start type. So what can I do about try, continue, and the else statement.
public class Menu {
private Inve...
Hi,
I have to make an application as a homework for my course for interactive tv using osmosys (implementation of mhp) as middleware.
I'm trying to read an xml file using:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
When I run it wi...
One of my homework questions is to search using grep an lines that contain the word 'death' or 'breath'.
I know the [] operator acts as an or, but how do I use it to specify 'd' or 'br' ?
This won't work:
egrep [dbr]eath test_file
...
For the matrix alpha described below, write a script to perform the following computations. Use a complete sentence to describe every number you display. Only use the fprintf() function for displaying answers.
Compute and display the maximum and minimum values in alpha.
Compute and display largest odd number in each row.
Compute and ...
Possible Duplicate:
Can we solve this using matlab
For the matrix alpha described below, write a script to perform the following computations. Use a complete sentence to describe every number you display. Only use the fprintf() function for displaying answers.
*Compute and display the maximum and minimum values in alpha.
*C...
This Program works fine with exception for one aspect of smarthistory(). I cannot figure out why when I enter a command number from the smarthistory array why it doesn't execute. After entering the command to execute from the list nothing happens not even the printf statement right after. I am using the gcc compiler.
const int MAX_HI...
I am having a bit problem on how to extract inside a list of a list.
(defun delete (a l)
(cond
((null l) nil)
((eq (car l) a) (delete a (cdr l)))
(t (cons (car l) (delete a (cdr l))))))
it deletes whatever is 'a' in a list l but if l consists of another list and a is in that inner list then my program cudnot ...
I've got a list like
[(1, 2), (1, 8), (2, 3), (2, 7), (2, 8), (2, 9), (3, 1), (3, 2), (3, 5), (3, 6), (3, 7), (3, 7), (3, 9)]
I want to make it looks like
[('1',' ', '2', '8'), ('2', ' ', '3', '7', '8', '9'), ('3', " ", '2', '5', '6', '7', '7', '9')]
How can I code this loop? Really tried times, and nothing came up. Please help~~
...