Giving a dynamic array, we want to pass the array elements from a file. The first number in the file N gives us the array length. They follow N numbers, the actual elements of the array.
Three brothers are going to work in the shop of their father for a time. The shop is doing well and every day generates profit which the three brothers may provide. The brothers agreed that they would divide the total time in three successive parts, not necessarily equal duration, and that each one will be working in the shop during one of these parts and collects the corresponding profit on his behalf. But they want to make a deal fairly, so that one received from three more profit someone else. Specifically, they want to minimize the profit the most favored of the three will receive.
I first created a program that WORKS! with complexity O(n3).
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int sum_array(int* array, int cnt){
int res = 0;
int i;
for ( i = 0; i < cnt ; ++i)
[Code] .....
Let's assume that we have the following input:
10
1 1 8 1 1 3 4 9 5 2
The ouptut should be 15 -> A = 1 + 1 + 8 + 1 + 1 + 3 = 15 , B = 4 + 9 = 13 , C = 5 + 2 = 7.
But the ouptut is 16!
How can I reduce the complexity of my first working! C code?
Code: int arr2d[rows][columns] ; // Not valid syntax of course ... let be arr2d rows * columns size for(int i=0; i<rows; i++) for(int j=0; j<columns; j++) arr2d[rows][columns] = some_value;
What is the complexity? I believe O(n) and not O(n^2) on this case because if you have 3*3 size you would put 9 elements (from 9 elements input of course)... for each input you have one insertion and that is the meaning. Same as 4*4 size 16 input times 16 insertions .. or 5*5 and so forth...
I'm working the 4th problem in chapter 14 of the Jumping into C++ book. In the book, he gives an example program for dynamically resizing an array while the program is running. It works fine for integer types but i need to do the same with a string type array. Right now my program is crashing because the string array is not resizing itself. Here's the part of the code im trying to figure out. The part for the int array has been ignored using // since it works fine and I'm trying to figure out whats wrong with the string array.
Code: #include <iostream> #include <string> //Write a program that lets users keep track of the last time they talked to each of their friends. //Users should be able to add new friends (as many as they want!) and store the number of days ago
What would the worst, average and best case space complexity be for a data structure of type map<string, vector<int> > in big O notation? I'm parsing through a document and storing each word as a key and im attaching an associated int (in a vector) to it as the value.
I want to change the complexity of the code from O(n) to O(1) . So I wanted to eliminate the for loop . But as the sum "s" stores values like (i-1)/2 or (2*n-i+1)/2 so eliminating the loop involves tedious calculation of floor value of each (i-1)/2 or (2*n-i+1)/2 . It became very difficult for me to do so as I might have derived the wrong formula in sums of floors . Need Changing complexity from O(n) to O(1). Is there any other way to reduce the complexity ? If yes ... then how ?
I have a very simple program the time complexity of the function that I used in this program is O(mn)because it has a nested loop, I really need to reduce the time complexity to O(n)
[code=c++] #include <iostream.h> #include<stdlib.h> int *char_count( const char* DNA, const int *starts, const int *ends, char letter); int main()
I was just going through Radix Sort algorithm. Though I got the logic and the concept used in it, I am still pretty much confused about the space complexity being O(k+n) for this algorithm. (where, k is the max no of digits in a number, and n is the no. of inputs to be sorted).
switch (parameter) { case ONE: case TWO: // ... other n-2 cases case N: doSomething(); break; default: somethingElse(); break; }
What is the complexity of the doSomething()? Is it still equal to the complexity of doSomething() , or the complexity of doSomething() plus the number of case statements? In other words, does the number of case statements a conditional piece of code has count towards the complexity?
define the time and space complexity of an algorithm and about what can i do when the time and space complexity are given and i should write the code corresponding to the restrictions , which i find very difficult.
We were discussing how to find average time complexity of different algorithms. Suppose I've a the following nested loop
for(int i=0;i<n;i++) { min = i;
[Code].....
Now the outer loop will iterate N times. the inner loop will always iterate 3 times no matter what the value of N is. so the worst case time complexity should be O(n^2) but what about the average case and the best case? I mean in terms of searching we can figure out and distinguish between the worst,best and average as it depends upon the number of comparisons. But here how can the average and best case be different then the worst case.
I have a COM exe which runs fine on all machines that I have used except one. On a particular machine, the COM exe does not start even after trying to execute it manually (do a double click on the file from explorer).
There are no error messages as well. what could be happening ?
i am writing a function that takes a delimited string and splits the strings into it's respective words according to the delimeter.
1) iterate through string and store delimeter position in vector array.
2) iterate through again and use substr to split into words and store again in a vector.
I then have a dictionary file, and am comapring each values in the string with each in the dictionary, problem is that it overruns the loop and obviously gives a subscript out of range error.
Code: #include <iostream>#include <fstream> #include <vector> using namespace std; //Start with string inputString //Find delimeters ::pos as ints and stores positions in vector <int> array //Run though string using 'find' and seperate string by positions of char32s //Build vector<string> array of individual words in string //Open dictionary file and loop though testing each words in vector string array against each word in dictionary
I have a service A, and an application B. Service A needs to launch application B only if it's not running currently. This can be easily done in Windows by calling GetExitCodeProcess function. I cannot find an equivalent method for doing so in Linux/Mac.
So my current code says:
system("open /Users/adsmaster/client/client &"); // to launch the application from the service in a new shell
I read that on a Linux-line machine you can use $ cal to get the exit value of the recently run process but I am not sure how can get the exit value of a particular process?
I am working on a parallel processing server/client app with a multi-threaded server and several data processing clients, each their own process. I am trying to optimize some of the parameters, such as the size of the chunks that are read, processed, and output, and also some of the timeout values and such. I can track the time to finish a given task well enough, but it would be really nice to be able to track the cpu use. When CPU use is near 100% (on all cores) for the entire run, that is a good sign. I have noticed that with some combinations of parameters, CPU drops quite a bit for long stretches, which is not such a good sign. This app process large input files (2.5GB-65GB so far) and needs to be stable for long periods of time.
Other than sitting and staring at the task manager all day, is there a good way to track/log the CPU usage over runs that take many hours? I know that there are some apps like Everest that chart CPU use, but it would be nice to have something that would write to the same log file I am already using for other program output.
since I didn't know how to type epsilon symbol temporarily I am using ^
char prod[20][20],T[20],NT[20],c[10][10],foll[10][10],fir[10][10]; int tt,tnt,tp,a; int follow[20][20],first[20][20]; void first_of(char); int count(int j); void rhs(int j);
I am trying to do single axis solar tracker with linear actuator /rtc/ UNO. I have already done with feedback sensor.
Now Here I am trying to without feedback. Linear actuator specification: 24v , 3.2mm/sec as speed , 600mm stoke.
Desired angle calculation: tracking start from 7am to 18PM, 11hours Assumed degree: 7AM as -45 deg , 12.30 as 0 degree and 18 pm as 45 degree. static float slope= 0.00227272727273; static float intercept=- 102.272727273;
[Code] ....
How can i put time here. Coding for calculating Ton time and solve above equation. below i posted my code . I need it has to be modified little bit. i need to implement ton time actuator here.
I need function takes desired and actual angle , where actuator try to move to its actual desired position.
Code below in arduino version
Code: double Desire_Degree; unsigned int TS; static float slope= 0.00227272727273; static float intercept=- 102.272727273; static int length; double Actual_Degree;
I ran into a problem while using while loop.T he declared and initiated local int variable works well with its specified value while running through the 1st run of a while loop. It is set zero while entering the 2nd run and the following unexpectedly. However, the variable still exits. The following is the code with problem.
Code:
#include <stdio.h> int main(void){ const int x=6; char c='y';
I have created an scientific calculator application and I have a VBS script that runs some of the files. I want to create a C program that runs that VBS script. however, a command window flashes before the application opens. So basically I need a short C (or C++) program that runs a VBS script without a command window popping up. I am on Windows 8 and my compiler is GCC/G++ under cygwin. Here is what I have now that DOES NOT work.
This code will read the running process from OS and display it (C++). Specifically, the OS here is Windows XP. The Problem(error) is in (i think) prototype. By the way, it displays following errors.
Error 1 : error LNK2019: unresolved external symbol _EnumProcesses@12 referenced in function _main Error 2 : error LNK2019: unresolved external symbol _GetModuleBaseNameA@16 referenced in function "void __cdecl DisplayProcessNameAndID(unsigned long)" (?DisplayProcessNameAndID@@YAXK@Z) Error 3 : error LNK2019: unresolved external symbol _EnumProcessModules@16 referenced in function "void __cdecl DisplayProcessNameAndID(unsigned long)" (?DisplayProcessNameAndID@@YAXK@Z) Error 4 : fatal error LNK1120: 3 unresolved externals C:Documents and SettingsWindowsMy DocumentsVisual Studio 2008ProjectsaDebuga.exe
#include <afxwin.h> #include <iostream> #include <string.h> #include "psapi.h" unsigned int i; using namespace std;