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 ?
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.
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 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()
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?
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 was talking to someone earlier about how to change the value of something from a function, and they said what was needed was to use a ** to change something, and was wondering if I could get a walk - through of what happens. I understand a single pointer well enough, but a pointer through a pointer is kind of confusing to me. Here is a simple example.
Code: #include <stdio.h> #include <stdlib.h> #define SIZE 5 int add(int ** TOP, int * stack);
int *stack = NULL;
[Code] ....
Why is it that when the program prints the address of TOP in main, it is different than the address of TOP in the function? Is it because it is a different instance of TOP because it is in the function? When I put the number on *TOP, and come out of the function back to main, it then says the address of TOP is the number entered into *TOP, and am not sure why. And the **TOP ++ at the end I am thinking it increments malloc by 1, therefore bringing the pointer TOP up to point at the next element, or am I completely off base there?
I use miracle library to work with big numbers. I defined a number for example X with 192 bit. at first X= 0 ;I want to change for example 3 bit of it to 1 randomly.as a example:
assume that X has 10 bit : X=0000000000 random numbers should be : 1000010001 1010100000 1100000100
I have this code which previously used the BigInteger library, however now I have GMP installed and I want to use that instead.
I have read the manual but I cannot figure out how to use GMP in this function without getting errors.
Here is the function:
Code: int lucas(long p){ //p is a number in the range of 2 up to 50,000,000, possibly bigger int s = 4; //previously assigned as a big integer int z; //used in the for loop below int M = 2; //previously assigned as a big integer for(z = 1; z < p; z++){ //this accomplishes the same as 2 to the power of p, and is stored in M M *= 2; } M--;
[code]....
I can initialize variables using the gmp library, but when I'm trying to use the mpz_pow_ui() function I get errors because it wants me to use long integers, which are too small for the numbers I want to work with.
I was wondering if there was a possible way to change my c program into an application so that i can send the application to another person and not let the other person have access to my codings?
My reasons for asking this question: For the application i want to send there are secrets that are meant to be unraveled by gameplay but i dont want people to look at the codes and know everything.
If I have an array of two columns that have the same values and I want to change only the third column how can I go about doing this. The values of the third column will change based on the values in one of the columns which I plug into a math equation. Also how come I can't show a double value in the array?
#include <iostream> #include <math.h> #include<iomanip> #include <vector> using namespace std;
I have a problem with my code which I can't work out:
double Mi = 200*pow(10,30); cout << " Enter accreted mass increment in solar masses "; cin >> dm; cout << "
[Code] ....
Basically the loop works, but gives the wrong results.
I need, at the end of the loop, to sort of "redefine" Mi as "Mi + Macc". I then need it to repeat the loop, and at the end add another Macc so that Mi becomes "Mi + Macc + Macc", etc.
For the past couple days I've been making small improvements on a program I made to keep track of a battle count while playing a game. Mainly to reduce the chore of keeping track yourself while you're playing. But it still becomes a hassle to switch back and forth between the program and your game and I was hoping to be able to set focus to the game after the BattleCount method is called.
Currently I am importing a DLL that somebody recommended I use to make a ActiveProcess method that accepts a integer as a parameter which would set the PID but it doesn't seem to be working. The two methods are as follows.
private void countDownClick(object sender, RoutedEventArgs e) { //Calls a method within my class that subtracts and adds battle values. counter.CalculateBattles();
//These two change text on my WPF forms with accessor values from my class. battlesWonText.Text = counter.BattlesWon.ToString(); battlesLeftText.Text = counter.BattlesLeft.ToString();
[Code] ....
This is the C++ code they told me to use to set focus to another application using a PID.
[DllImport("user32.dll")] static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); const UInt32 SWP_NOSIZE = 0x0001; const UInt32 SWP_NOMOVE = 0x0002; const UInt32 SWP_SHOWWINDOW = 0x0040;
[Code] ....
I'm simply trying to figure out how to set focus to a foreign program using their PID and a button click event in WPF. I'm using Visual Studio 2012 on Windows 7.
I'm working on a project where we access a tiny premade database in order to log into and access another page. I got the log in part working right, but the last part of the project asks me to lock out the account after a certain number of failed attempts. I'm not sure if I need a method to do this or if I can do it right there in the button handler. I tried creating a method to use on the object that was already there, but I'm not sure if that's the right way to go about it. It says it locks the account, but the value in the database never changes, and I don't know why.
//from the login button handler protected void btnLogin_Click(object sender, EventArgs e) { bool IsFound = false; clsDataLayer dl = new clsDataLayer(); IsFound = dl.GetUser(Server.MapPath("~/AddressBook.mdb"), txtUserID.Text, txtPassword.Text); if (IsFound) { Response.Redirect("~/frmUpdateAddress.aspx");