Search Results

Search found 1552 results on 63 pages for 'homework'.

Page 23/63 | < Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >

  • Theory of computation - Using the pumping lemma for CFLs

    - by Tony
    I'm reviewing my notes for my course on theory of computation and I'm having trouble understanding how to complete a certain proof. Here is the question: A = {0^n 1^m 0^n | n>=1, m>=1} Prove that A is not regular. It's pretty obvious that the pumping lemma has to be used for this. So, we have |vy| = 1 |vxy| <= p (p being the pumping length, = 1) uv^ixy^iz exists in A for all i = 0 Trying to think of the correct string to choose seems a bit iffy for this. I was thinking 0^p 1^q 0^p, but I don't know if I can obscurely make a q, and since there is no bound on u, this could make things unruly.. So, how would one go about this?

    Read the article

  • Unknown error in Producer/Consumer program, believe it to be an infinite loop.

    - by ray2k
    Hello, I am writing a program that is solving the producer/consumer problem, specifically the bounded-buffer version(i believe they mean the same thing). The producer will be generating x number of random numbers, where x is a command line parameter to my program. At the current moment, I believe my program is entering an infinite loop, but I'm not sure why it is occurring. I believe I am executing the semaphores correctly. You compile it like this: gcc -o prodcon prodcon.cpp -lpthread -lrt Then to run, ./prodcon 100(the number of randum nums to produce) This is my code. typedef int buffer_item; #include <stdlib.h> #include <stdio.h> #include <pthread.h> #include <semaphore.h> #include <unistd.h> #define BUFF_SIZE 10 #define RAND_DIVISOR 100000000 #define TRUE 1 //two threads void *Producer(void *param); void *Consumer(void *param); int insert_item(buffer_item item); int remove_item(buffer_item *item); int returnRandom(); //the global semaphores sem_t empty, full, mutex; //the buffer buffer_item buf[BUFF_SIZE]; //buffer counter int counter; //number of random numbers to produce int numRand; int main(int argc, char** argv) { /* thread ids and attributes */ pthread_t pid, cid; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); numRand = atoi(argv[1]); sem_init(&empty,0,BUFF_SIZE); sem_init(&full,0,0); sem_init(&mutex,0,0); printf("main started\n"); pthread_create(&pid, &attr, Producer, NULL); pthread_create(&cid, &attr, Consumer, NULL); printf("main gets here"); pthread_join(pid, NULL); pthread_join(cid, NULL); printf("main done\n"); return 0; } //generates a randum number between 1 and 100 int returnRandom() { int num; srand(time(NULL)); num = rand() % 100 + 1; return num; } //begin producing items void *Producer(void *param) { buffer_item item; int i; for(i = 0; i < numRand; i++) { //sleep for a random period of time int rNum = rand() / RAND_DIVISOR; sleep(rNum); //generate a random number item = returnRandom(); //acquire the empty lock sem_wait(&empty); //acquire the mutex lock sem_wait(&mutex); if(insert_item(item)) { fprintf(stderr, " Producer report error condition\n"); } else { printf("producer produced %d\n", item); } /* release the mutex lock */ sem_post(&mutex); /* signal full */ sem_post(&full); } return NULL; } /* Consumer Thread */ void *Consumer(void *param) { buffer_item item; int i; for(i = 0; i < numRand; i++) { /* sleep for a random period of time */ int rNum = rand() / RAND_DIVISOR; sleep(rNum); /* aquire the full lock */ sem_wait(&full); /* aquire the mutex lock */ sem_wait(&mutex); if(remove_item(&item)) { fprintf(stderr, "Consumer report error condition\n"); } else { printf("consumer consumed %d\n", item); } /* release the mutex lock */ sem_post(&mutex); /* signal empty */ sem_post(&empty); } return NULL; } /* Add an item to the buffer */ int insert_item(buffer_item item) { /* When the buffer is not full add the item and increment the counter*/ if(counter < BUFF_SIZE) { buf[counter] = item; counter++; return 0; } else { /* Error the buffer is full */ return -1; } } /* Remove an item from the buffer */ int remove_item(buffer_item *item) { /* When the buffer is not empty remove the item and decrement the counter */ if(counter > 0) { *item = buf[(counter-1)]; counter--; return 0; } else { /* Error buffer empty */ return -1; } }

    Read the article

  • Power function in prolog

    - by NHans
    Exactly what's the prolog definition for power function. I wrote this code and it give some errors I wanna know exact code for the power function. pow(X,0,1). pow(X,Y,Z):-Y1=Y-1,pow(X,Y1,Z1),Z1=Z*X. Anything wrong with this code?

    Read the article

  • cache-coherence MOESI protocol

    - by Yaron
    processor A owns a cache line which is shared with processor B. what happens when B tries to write to that line? also, if it was 'invalid' instead of 'shared' would it make any difference? thank you.

    Read the article

  • Java swing app can't find image

    - by KáGé
    Hello, I'm making a torpedo game for school in java with swing gui, please see the zipped source HERE. I use custom button icons and mouse cursors of images stored in the /bin/resource/graphics/default folder's subfolders, where the root folder is the program's root folder (it will be the root in the final .jar as well I suppose) which apart from "bin" contains a "main" folder with all the classes. The relative path of the resources is stored in MapStruct.java's shipPath and mapPath variables. Now Battlefield.java's PutPanel class finds them all right and sets up its buttons' icons fine, but every other class fail to get their icons, e.g. Table.java's setCursor, which should set the mouse cursor for all its elements for the selected ship's image or Field.java's this.button.setIcon(icon); in the constructor, which should set the icon for the buttons of the "water". I watched with debug what happens, and the images stay null after loading, though the paths seem to be correct. I've also tried to write a test file in the image folder but the method returns a filenotfound exception. I've tried to get the path of the class to see if it runs from the supposed place and it seems it does, so I really can't find the problem now. Could anyone please help me? Thank you.

    Read the article

  • Scaling up an image

    - by codefail
    How do I fulfill the condition "returns the entire scaled up image" If I am coding this correctly, scaleColor handles individual colors, getRed handles the red, etc. I am multiplying this by the input, numTimes, which will create a new image that is scaled up it. This scaled up (increase size) is to be returned. This is what I have. Image Image::scaleUp(int numTimes) const { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixelData[x][y].scaleColor(pixelData[x][y].scaleRed(pixelData[x][y].getRed()*numTimes)); pixelData[x][y].scaleColor(pixelData[x][y].scaleGreen(pixelData[x][y].getGreen()*numTimes)); pixelData[x][y].scaleColor(pixelData[x][y].scaleBlue(pixelData[x][y].getBlue()*numTimes)); } } //return Image(); }

    Read the article

  • Using recursion to to trim a binary tree based on a given min and max value

    - by Justin
    As the title says, I have to trim a binary tree based on a given min and max value. Each node stores a value, and a left/right node. I may define private helper methods to solve this problem, but otherwise I may not call any other methods of the class nor create any data structures such as arrays, lists, etc. An example would look like this: overallRoot _____[50]____________________ / \ __________[38] _______________[90] / \ / _[14] [42] [54]_____ / \ \ [8] [20] [72] \ / \ [26] [61] [83] trim(52, 65); should return: overallRoot [54] \ [61] My attempted solution has three methods: public void trim(int min, int max) { rootFinder(overallRoot, min, max); } First recursive method finds the new root perfectly. private void rootFinder(IntTreeNode node, int min, int max) { if (node == null) return; if (overallRoot.data < min) { node = overallRoot = node.right; rootFinder(node, min, max); } else if (overallRoot.data > max) { node = overallRoot = node.left; rootFinder(node, min, max); } else cutter(overallRoot, min, max); } This second method should eliminate any further nodes not within the min/max, but it doesn't work as I would hope. private void cutter(IntTreeNode node, int min, int max) { if (node == null) return; if (node.data <= min) { node.left = null; } if (node.data >= max) { node.right = null; } if (node.data < min) { node = node.right; } if (node.data > max) { node = node.left; } cutter(node.left, min, max); cutter(node.right, min, max); } This returns: overallRoot [54]_____ \ [72] / [61] Any help is appreciated. Feel free to ask for further explanation as needed.

    Read the article

  • how to link table to table

    - by Niño Seymour L. Rodriguez
    I am a comsci student and I'm taking up database now. I got a problem in or should I say I dont know how to link table to table. It is not like you'll just use a foreign key and connect it to the primary key. The outcome should be like this: In the table Course there are three fields namely "course_id", "Description" and "subjects". When you click the name field Subject, a table named Subject should appear. Can you help me with this? hope you understnd my grammar, hehe..im not good in english......it will be a big help if you can answer it.........thank you po..............

    Read the article

  • alternative to strdup

    - by Alexander
    I am using strdup here to copy the value of the parameter name into nm in the constructor... is there an alternative of achieving the same result without using strdup and without using the C++ STL library and using the keyword new instead? Book::Book(const char *name, int thickness, int weight):nm(NULL), thck(thickness), wght(weight){ if(name) nm = strdup(name); } class Book { private: char* nm; .......... ............ .......... ........... };

    Read the article

  • Dynamic programming: Find largest diamond (rhombus)

    - by Darksody
    I have a small program to do in Java. I have a 2D array filled with 0 and 1, and I must find the largest rhombus (as in square rotated by 90 degrees) and their numbers. Example: 0 1 0 0 0 1 1 0 1 1 1 0 1 0 1 1 1 1 0 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 Result: 1 1 1 1 1 1 1 1 1 1 1 1 1 The problem is similar to this SO question. If you have any idea, post it here.

    Read the article

  • Pros and cons of cloud computing?

    - by Vimvq1987
    After 3 months of research, my thesis is nearly complete. Now I'm writing the report. Interesting parts are finished, now the boring and hard-to-write parts. I need to write about pros and cons of cloud computing. What it gives us and what it take us. I've searched much but there's only list, no explains. So I need your helps, to list and explains all of pros and cons of cloud computing. Thank you so much for this.

    Read the article

  • String operations

    - by NEO
    I am trying to find the most repeated word in a string. My code is as follows: public class Word { private String toWord; private int Count; public Word(int count, String word){ toWord = word; Count = count; } public static void main(String args[]){ String str="my name is neo and my other name is also neo because I am neo"; String []str1=str.split(" "); Word w1=new Word(0,str1[0]); LinkedList<Word> list = new LinkedList<Word>(); list.add(w1); ListIterator itr = list.listIterator(); for(int i=1;i<str1.length;i++){ while(itr.hasNext()){ if(str1[i].equalsTO(????)); else list.add(new Word(0,str1[i])); } How do I compare the string from string array str1 to the string stored in the linked list and then how do i increase the respective count. I will then print the string with the highest count, I dont know how to do that either.

    Read the article

  • Relational algebra help?!

    - by Tom
    im new to relational algebra and finding it difficult. Ive answered a few questions, however they where relatively simple. Could do with help with these though. Database Patient (PatientCode, PatientSurname, PatientFirstname, PatientSex, PatientAge, PatientOccupation, PatientHeight, PatientWeight, PatientAddress) Doctor (DoctorCode, DoctorSurName, DoctorFirstName, DoctorPrivateAddress, MobileNo, Doctor Specilisim) Operation (Operation Code, PatientCode, DoctorCode, Date, Time, Result, OperationType) Is_Seen_By (PatientCode, DoctorCode, Date, Time). Q1. Find the surname and gender of the patients that have been operated on by doctor "DR333" and results have not been successful. Q2. Find the code of the operations that have been done on the 18th of November 2010 and have been successful, please also list the name of the doctors which were involved with the operation.

    Read the article

  • C# using the "this" keyword in this situation?

    - by Alex
    Hi, I've completed a OOP course assignment where I design and code a Complex Number class. For extra credit, I can do the following: Add two complex numbers. The function will take one complex number object as a parameter and return a complex number object. When adding two complex numbers, the real part of the calling object is added to the real part of the complex number object passed as a parameter, and the imaginary part of the calling object is added to the imaginary part of the complex number object passed as a parameter. Subtract two complex numbers. The function will take one complex number object as a parameter and return a complex number object. When subtracting two complex numbers, the real part of the complex number object passed as a parameter is subtracted from the real part of the calling object, and the imaginary part of the complex number object passed as a parameter is subtracted from the imaginary part of the calling object. I have coded this up, and I used the this keyword to denote the current instance of the class, the code for my add method is below, and my subtract method looks similar: public ComplexNumber Add(ComplexNumber c) { double realPartAdder = c.GetRealPart(); double complexPartAdder = c.GetComplexPart(); double realPartCaller = this.GetRealPart(); double complexPartCaller = this.GetComplexPart(); double finalRealPart = realPartCaller + realPartAdder; double finalComplexPart = complexPartCaller + complexPartAdder; ComplexNumber summedComplex = new ComplexNumber(finalRealPart, finalComplexPart); return summedComplex; } My question is: Did I do this correctly and with good style? (using the this keyword)?

    Read the article

  • Why does DataInputStream not support integers?

    - by Jason
    I need to read in a list of numbers from a file, none of which are larger than 32767. Originally I was going to use the Scanner class to pull in the data, then I read about DataInputStream. This would work well for me, except that according to the API, it supports all primitive variables EXCEPT ints! Listed are longs, shorts, bytes, chars, booleans, ect, but no ints. I have no need for double precision from the incoming data. Is this a deliberate or unintentional oversight?

    Read the article

  • Returning the element number of the longest string in an array

    - by JohnRoberts
    I'm trying to get the longestS method to take the user-inputted array of strings, then return the element number of the longest string in that array. I got it to the point where I was able to return the number of chars in the longest string, but I don't believe that will work for what I need. My problem is that I keep getting incompatible type errors when trying to figure this out. I don't understand the whole data type thing with strings yet. It's confusing me how I go about return a number of the array yet the array is of strings. The main method is fine, I got stuck on the ???? part. { public static void main(String [] args) { Scanner inp = new Scanner( System.in ); String [] responseArr= new String[4]; for (int i=0; i<4; i++) { System.out.println("Enter string "+(i+1)); responseArr[i] = inp.nextLine(); } int highest=longestS(responseArr); } public static int longestS(String[] values) { int largest=0 for( int i = 1; i < values.length; i++ ) { if ( ????? ) } return largest; } }

    Read the article

  • JAVA: storing input into array

    - by Jann
    I need to write a program where the program would generate random letter and i would need to store this random character into an array char[] arrayRandom = new char[10]; for (int i = 0; i < 8; i++) { randomNumLet = (generator.nextInt(20) + 1); System.out.print(arrayRandomLetter[randomNumLet] + " "); arrayRandomLetter[randomNumLet] = arrayRandom[i]; } is there anything wrong with my code? because when i run this and printed the array i get boxes for all the values in the array and there are some letter that this line of code cannot print System.out.print(arrayRandomLetter[randomNumLet] + " "); Thanks

    Read the article

  • Deleting from arraylist and exporting back to .buab file(Java)

    - by Dave
    Ive made an address book. I can currently write to the arraylist and save it back to the .buab file, but I cant delete from the arraylist and export it back to the .buab file? Im pretty much stuck on this. Im able to retrive contacts from the .buab and scroll through them using the JTextFields and buttons ive created. Any help will be dearly appreciated. Ive set up seprate classes for all operations (newcontacts, nextcontact etc). If you need the code posted let me know.. Cheers Dave

    Read the article

  • implement SIMD in C++

    - by Hristo
    I'm working on a bit of code and I'm trying to optimize it as much as possible, basically get it running under a certain time limit. The following makes the call... static affinity_partitioner ap; parallel_for(blocked_range<size_t>(0, T), LoopBody(score), ap); ... and the following is what is executed. void operator()(const blocked_range<size_t> &r) const { int temp; int i; int j; size_t k; size_t begin = r.begin(); size_t end = r.end(); for(k = begin; k != end; ++k) { // for each trainee temp = 0; for(i = 0; i < N; ++i) { // for each sample int trr = trRating[k][i]; int ei = E[i]; for(j = 0; j < ei; ++j) { // for each expert temp += delta(i, trr, exRating[j][i]); } } myscore[k] = temp; } } I'm using Intel's TBB to optimize this. But I've also been reading about SIMD and SSE2 and things along that nature. So my question is, how do I store the variables (i,j,k) in registers so that they can be accessed faster by the CPU? I think the answer has to do with implementing SSE2 or some variation of it, but I have no idea how to do that. Any ideas? Thanks, Hristo

    Read the article

  • Problem in finalizing the link list in C#

    - by Yasin
    My code was almost finished that a maddening bug came up! when i nullify the last node to finalize the link list , it actually dumps all the links and make the first node link Null ! when i trace it , its working totally fine creating the list in the loop but after the loop is done that happens and it destroys the rest of the link by doing so, and i don't understand why something so obvious is becoming problematic! (last line) struct poly { public int coef; public int pow; public poly* link;} ; poly* start ; poly* start2; poly* p; poly* second; poly* result; poly* ptr; poly* start3; poly* q; poly* q2; private void button1_Click(object sender, EventArgs e) { string holder = ""; IntPtr newP = Marshal.AllocHGlobal(sizeof(poly)); q = (poly*)newP.ToPointer(); start = q; int i = 0; while (this.textBox1.Text[i] != ',') { holder += this.textBox1.Text[i]; i++; } q->coef = int.Parse(holder); i++; holder = ""; while (this.textBox1.Text[i] != ';') { holder += this.textBox1.Text[i]; i++; } q->pow = int.Parse(holder); holder = ""; p = start; //creation of the first node finished! i++; for (; i < this.textBox1.Text.Length; i++) { newP = Marshal.AllocHGlobal(sizeof(poly)); poly* test = (poly*)newP.ToPointer(); while (this.textBox1.Text[i] != ',') { holder += this.textBox1.Text[i]; i++; } test->coef = int.Parse(holder); holder = ""; i++; while (this.textBox1.Text[i] != ';' && i < this.textBox1.Text.Length - 1) { holder += this.textBox1.Text[i]; if (i < this.textBox1.Text.Length - 1) i++; } test->pow = int.Parse(holder); holder = ""; p->link = test; //the addresses are correct and the list is complete } p->link = null; //only the first node exists now with a null link! }

    Read the article

  • Graph - strongly connected components

    - by HardCoder1986
    Hello! Is there any fast way to determine the size of the largest strongly connected component in a graph? I mean, like, the obvious approach would mean determining every SCC (could be done using two DFS calls, I suppose) and then looping through them and taking the maximum. I'm pretty sure there has to be some better approach if I only need to have the size of that component and only the largest one, but I can't think of a good solution. Any ideas? Thanks.

    Read the article

< Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >