

Hiya. I am not requesting answers, Nor is it my " homework ", all i'm enquiring about is just brief guidance on how to logically approach the question. All the tutorials on you tube seem irrelevant to this type of scenario. Does anyone know any GOOD sources that may aid me in this question?





Perhaps you should think "a little bit" logical.
The answer to the question comes from the difference of the both codesnippets.
Perhaps you try to imagine what the both doubleloops are doing in the codepart 1 and what the difference is to codepart 2.
One part of "your" solution is to realize how much total loops are done in each codepart (and of course the understanding how to find it out) ...
So ... if you want further help : give me/us the answer to my last sentence ...





Pick an arbitrary time to complete operation "sum = sum + 1" and proceed from there.
It's all relative.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal





I worked out the answers to be O(N) for A and 0(N^2) For B. Any ideas how i could use this to now to calculate how long it would take the algorithm to solve a problem with the size of 1 million operations






Update: the answer to A was wrong and i changed it.
All i know is that it's capped at 1 million operation per second, the rest is unknown to me.





Member 13133031 wrote: All i know is that it's capped at 1 million operation per second, the rest is unknown to me. You stated in the original question that "size" becomes one million "operations".
SET sum TO 0
FOR i=1 to 10
FOR j=1 to size
sum=sum +1
In that case, the word "operation" is confusing. If you increase the iterations, you'll be executing more instructions.
Since you can count the instructions, you can calculate how long it takes if you know the instructions per second. Shouldn't be too hard to implement this in a BASIClanguage and simply see what happens if you change the "size".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]





i have script for encrypt dan decrypt...
Public Shared Function Decrypt(ByRef Msg As String, ByRef Key As String) As String
Dim str As String
Dim builder As New StringBuilder
Try
Dim num5 As Integer = (Msg.Length  1)
Dim i As Integer = 0
Do While (i <= num5)
Dim num3 As Integer = Strings.Asc(Conversions.ToChar(Msg.Substring(i, 1)))
Dim num2 As Integer = Strings.Asc(MFunction.GetKey(Key, i))
Dim charCode As Integer = (num3  num2)
builder.Append(Strings.Chr(charCode))
i += 1
Loop
str = builder.ToString
Catch exception1 As Exception
ProjectData.SetProjectError(exception1)
Dim exception As Exception = exception1
Throw New Exception(("Public Function Decrypt(ByRef Msg As String, ByRef Key As String) As String Error : " & ChrW(13) & ChrW(10) & exception.Message.ToString & ChrW(13) & ChrW(10)))
Finally
builder.Length = 0
End Try
Return str
End Function
Public Shared Function Encrypt(ByRef Msg As String, ByRef Key As String) As String
Dim str As String
Dim builder As New StringBuilder
Try
Dim num5 As Integer = (Msg.Length  1)
Dim i As Integer = 0
Do While (i <= num5)
Dim num3 As Integer = Strings.Asc(Conversions.ToChar(Msg.Substring(i, 1)))
Dim num2 As Integer = Strings.Asc(MFunction.GetKey(Key, i))
Dim charCode As Integer = (num3 + num2)
builder.Append(Strings.Chr(charCode))
i += 1
Loop
str = builder.ToString
Catch exception1 As Exception
ProjectData.SetProjectError(exception1)
Dim exception As Exception = exception1
Throw New Exception(("Public Function Encrypt(ByRef Msg As String, ByRef Key As String) As String Error : " & ChrW(13) & ChrW(10) & exception.Message.ToString & ChrW(13) & ChrW(10)))
Finally
builder.Length = 0
End Try
Return str
End Function
what algorithm is used?
Please advise...





91191109 wrote: what algorithm is used? It's your code, you tell us.





Look at MFunction.GetKey(Key, i)  that's what encrypts a single byte.





91191109 wrote: Dim num3 As Integer = Strings.Asc(Conversions.ToChar(Msg.Substring(i, 1)))
Dim num2 As Integer = Strings.Asc(MFunction.GetKey(Key, i))
Dim charCode As Integer = (num3 + num2)
builder.Append(Strings.Chr(charCode))
Even without seeing the implementation of MFunction.GetKey , it's obvious that this is a variant of the Caesar cipher[^]  possibly a Running key cipher[^].
In other words, an extremely poor algorithm, which will be broken in seconds by a determined hacker.
Unless you are a team of encryption specialists, each with multiple PHDs in the field, then you should never try to implement your own encryption algorithm. There are plenty of perfectly good builtin encryption algorithms; pick one of those instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
 Homer





... and now you've done his homework.
Actually, not sure about the joke icon.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012





How can a find a minimum in right sub tree using recursion





I'm sorry ... what do you mean ...?
You should give an Example ...
modified 22Mar17 9:14am.





Just recursively trace down the left branches in the right sub tree. The left element is always lowest.





To begin, I have the set of K values S={v_1, ..., v_K}. I want to pick the smallest value, replace it with another value, and again pick the smallest  do this K times. So, initially, my best set B is empty, and I want to perform :
Step 1. Find minimum of S. Say it has index n. B=[B, v_n] (i.e., append v_n to B)
Step 2. Update S by replacing v_n with another value (not important how that other value is computed).
Repeat Steps 1 and 2 till B has K values.
I believe a reasonable way to do this is to first construct a minheap from the initial S (KlogK complexity), and then I can (take out the root + insert new element) for (K1) times. Assuming taking out root and insertion both are logK complexity, total complexity would be KlogK + 2(K1)log(K) = (3K2)logK.
As a next step, once I have the set B, I want to compute some function f(b) for each b in B, and repeat the above procedure with the set {f(b)} instead of the set S. In other words, taking the set {f(b)} as S now, I would like to perform the above described procedure. Brute force way  I could first use up (3K2)logK units of time to find B, then compute the set {f(b)}, and then use another (3K2)logK units of time on {f(b)}. But, it is quite apparent I can do better by pipelining. Essentially, as soon as I start getting entries of B, I can compute f(.) for the available entries, and do some of the sorting operations.
Can you suggest a good/optimal way for the overall problem ?





i need cooccurrence matrix algorithm in any language. plz share ur results with me.






If you google for it, you will find many examples. Try googling for co occurence matrix python to get started.
This space for rent





Pete O'Hanlon wrote: co occurence matrix python That's just the Nokia snake game.






My wife still has an old phone that she keeps powered up just for that.





can't able to fine exact code. its confusing





Part of the art of becoming a programmer is knowing how to search. Paste your search link in as a reply so I can see how you searched.
This space for rent






The search terms I used. Google[^]
This space for rent






thanks but i dont know how to run it. its not giving an error but dont know how to compile it. not giving any output





The links I found are just to point you to the information that may help you. It is up to you to work out how to use it and, if necessary, find out why it does not work.





We are not a free search service!
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





how rude ur ans





I don't think it was rude. He was trying to give you some genuine advice that will stand you in good stead in the years to come... as have the others that are suggesting that you actually need to put some of your own effort into this exercise.





In some cities, the sewage system does not work properly and every time it rains, water accumulates on the streets and in between buildings, blocking traffic and causing distress.
You have an N number of buildings and an array with the height of every building.
You want to find out what is the maximum volume of water that would hypothetically accumulate after heavy rain, in between 2 buildings.
Input: N > 0 on the first line, array of N integer elements on the second line.
Output: integer positive X units of water.
Example: The following sequence of heights will generate the structure below:
Sequence: 1 2 1 5 2 4 1 0 1 2 6 4 5 2 3 4 1 2
The biggest block of water would contain 20 units of water.
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace heavy_rain{
class Program{
static void Main(string[] args){
System.IO.StreamReader sr;
int n = 0, i = 0, result = int.MaxValue;
int[] buildingHeights = null;
try {
sr = new System.IO.StreamReader(args[0]);
String[] lines = new String[2];
String line = null;
while ((line = sr.ReadLine()) != null) {
lines[i++] = line;
}
n = int.Parse(lines[0]);
buildingHeights = new int[n];
String[] heights = lines[1].Split(' ');
for(int j = 0; j < heights.Length; j++) {
buildingHeights[j] = int.Parse(heights[j]);
}
Console.WriteLine(result);
}
catch (Exception e) {
System.Diagnostics.Trace.WriteLine(e.Message);
}
}
}
}





I don't think you'll find anyone here to do your homework for you. You'll have to do it yourself. But if you get stuck and have a specific question, come back and ask.
The difficult we do right away...
...the impossible takes slightly longer.





Member 13003743 wrote: The biggest block of water would contain 20 units of water. That does not make much sense. Ask your professor what is the connection is between height of building and amount of water.





Always assume that your teacher is reading this site, and will notice your attempt to cheat on your homework.
Expecting other people to do your work for you will not end well. How do you think that would go down in the real world, when you've got a real job and a mortgage to pay?
If you don't know how to start, then talk to your teacher.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
 Homer





Your main effort was to copy your assignment.
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Before we start, my textbook declares lgn as base two.
I only have one question, how did log2 become n (both highlighted in yellow in the picture)? Is it because log2 = 1, which is too small to even matter? Below is a link of the equations.
/Users/conrados/Desktop/20170207_091636000_iOS.jpg





The link to the picture won't work as that's your local Windows file (and it would have to be a proper web anchor).
This space for rent





Member 12986878 wrote: how did log2 become n Ask the person who wrote the textbook.





Member 12986878 wrote: how did log2 become n
when a log2 and an exp(n, 2) love each other very much...





What we read is meaningless.
Do not reformulate the question.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Hello all,
I do need to send a motor from position A to B accelerating and decelerating accordingly to the defined allowed acceleration.
Constant acceleration.
Different starting speeds.
Different starting positions.
Different ending positions.
0 end speed.
I've tried to make my own which works perfectly when the values allow the motor to reach the maximum speed "plateau" but it is not working well when is not possible to achieve this and v0 (initial speed) and vf (end speed) are different.
Previous notes:
vmax = maximum allowed speed for the movement.
x0 = initial position.
xf = destination position.
v0 = initial speed.
vf = end speed (final).
ta = acceleration time from v0 to vmax.
da = distance to accelerate from v0 to vmax.
tf = braking time from vmax to vf.
df = braking distance from vmax to vf.
dist = total distance I want to move the motor xfx0
The code I've used is:
LimitIterations = 1000
ta = Abs((vmax  v0) / a)
da = (v0 * ta) + (0.5 * a * ta * ta)
tf = Abs((vmax  vf) / a)
df = (vf * tf) + (0.5 * a * tf * tf)
If (da + df > dist + 0.000000001) Then
DistTotal = xf  x0  da  df
RelAccDec = da / (da + df)
dist_corr_acc = DistTotal * RelAccDec
da = da + dist_corr_acc
dist_corr_dec = DistTotal * (1  RelAccDec)
df = df + dist_corr_dec
taux = Sqr(da / (0.5 * a))
taux = (Sqr((2 * a * da) + (v0 * v0))  v0) / a
vmax = v0 + (a * taux)
Do
ta = Abs((vmax  v0) / a)
da = (v0 * ta) + (0.5 * a * ta * ta)
tf = Abs((vmax  vf) / a)
df = (vf * tf) + (0.5 * a * tf * tf)
If (da + df > dist + 0.000000001) Then
vmax = vmax  1
iterations = iterations + 1
If (iterations > LimitIterations) Then
ErrorID = 1
Exit Do
End If
Else
Exit Do
End If
Loop
End If
WRONG APPROACH EXPLANATIONS
The idea of that code was to find the maximum speed that can be reached given the specified conditions.
When the da + df are bigger than the total distance I'm doing a proportional reduction which approximates the vmax to it's desired/needed value.
The problem here I think is that part: I don't have to make a proportional reduction, I do need to find the position in which the acceleration movement and the deceleration movement are coincident once I will have this position then I should check the speed any of the movements has in that position. And that one should be vmax.
Now the issue is doing that...
I could use 0 as the starting position for the acceleration and xf as the starting position for the deceleration.
Both accelerations are the same (different signs).
I've seen examples of that when movements are not accelerated (the typical problem with two trains that leave the station) but nothing when the movements have constant acceleration.
Any hint, example, resource, formula that could solve it...
The solution
OK, at the end I've done it by algebra:
vp = v0 + (a0 * t0)
vp = v1 + (a1 * t1)
v0+(a0*t0) = v1+(a1*t1)
t1=((v0v1)+(a0*t0))/a1
d0 = (v00 * t0) + (0.5 * a0 * t0 * t0)
d1 = (v01 * t1) + (0.5 * a1 * t1 * t1)
D = (v00 * t0) + (0.5 * a0 * t0 * t0) + (v01 * t1) + (0.5 * a1 * t1 * t1)
And solve the quadratic equation to get the positive value (as we are speaking of time).
So.. this previous code substitutes the wrong approach method.
Thank you all,
modified 12Feb17 9:01am.





So at first you need to calculate the distance between both Points. That will be normally the Hypothenuse of a rightangled triangle.
Now you have to calculate the distance you need for speeding up your Motor. This could be calcuated with the final Speed (the Speed when you have finished the accelaration) and the acceleration itself.
The same you do for the decelaration.
If the distance for speeding up and the distance for speeding down is less than your complete distance then the difference is the way you drive with your final Speed and you will get a Trapezoid.
If the distance for speeding up and the distance for speeding down equal your complete distance then you will get a Triangle.
If the distance for speeding up and the distance for speeding down is more than your complete distance then you have to calculate the Point where both triangles meet. In this case your Motor doesn't reach the final Speed and your hullcurve will also be a triangle  but with a lower edge.
But you don't need to do an Interpolation ...





Hello Ralf,
Everything works.
I was simply trying to use a too high speed for a too short movement (totally obfuscated trying to get something impossible).
The only problem that I do still have is that I don't know how to efficiently find the maximum available speed.
What I'm doing is simple as:
Do
ta = Abs((vmax  v0) / a)
da = (v0 * ta) + (0.5 * a * ta * ta)
tf = Abs((vmax  vf) / a)
df = (vf * tf) + (0.5 * a * tf * tf)
If (da + df > dist) Then
If (v0 = vf) Then
taux = (Sqr((a * dist) + (v0 * v0))  v0) / a
vmax = v0 + a * taux
Else
vmax = vmax  1
End If
End If
Loop While (da + df > dist)
This works "perfectly":
 Avoiding the fact the maximum used speed will not be the purest maximum available.
 Avoiding the fact that it takes "ages" to find the maximum allowed speed for the current movement.
Any suggestion on how to find the maximum allowed speed in a faster way when v0 <> vf?
The initial data I do have is:
vmax (the one entered by the user it could be too high for what is possible).
x0 (initial position).
v0 (initial speed).
a (acceleration).
xf (end position).
vf (end speed (now we consider it always 0)).
Thank you.
modified 7Feb17 6:27am.





Perhaps this could be a Solution for you : (PseudoCode)
distance_with_v = x1  x0  s_Acc  s_Dec
if Distance_with_v < 0 then
Relation_Acc_Dec = s_Acc / (s_Acc + s_Dec)
DistanceCorrecting_Accelaration = Distance_with_v * Relation_Acc_Dec
da = s_Acc  DistanceCorrecting_Accelaration
DistanceCorrecting_Decelaration = Distance_with_v * (1  Relation_Acc_Dec)
df = s_Dec  DistanceCorrecting_Decelaration
end if





Hello Ralf,
I can't see how this will help on calculating the vmax...
I understand that at the first line you are testing if the constant speed will be possible or not.
Then you go inside the if clause only if that constant (vmax) is not possible to reach.
So we are at my "(da + df ) > dist" if clause.
But from now on I can't see how this can help me... I'm after the vmax and here I can't see anything like that...
s_Acc and s_Dec are da and df respectively?
Thank you...





Hello Joan,
you are right  s_Acc is equal to your da and s_Dec is equal to your df.
Now I calculate the distance which would be driven with the wanted Speed (vMax).
If this distance is negative I calculate the Relation from the original calculated da to the sum of da + df.
Now the correctingvalue for da is da multiplied with this relation.
If you now reduce da with this value you get the new Point for da with the same Accelaration. Behind this Point (where you haven't reached your wanted Speed) you have to decelarate the Speed. The second calculation is not necessary but it confirms the first calculation.
I hope it helps you with this explaining ...





Hi again,
I've tried it and ported it into the code.
It looks promising as the newly calculated da + df are always the distance to run and moreover in the graphs I can see the numbers are what they should.
But I'm still having problems calculating the time and therefore the maximum speed:
ta = Abs((vmax  v0) / a)
da = (v0 * ta) + (0.5 * a * ta * ta)
tf = Abs((vmax  vf) / a)
df = (vf * tf) + (0.5 * a * tf * tf)
If (da + df > dist + 0.000000001) Then
If (v0 = vf) Then
taux = (Sqr((a * dist) + (v0 * v0))  v0) / a
vmax = v0 + a * taux
Else
DistTotal = xf  x0  da  df
RelAccDec = da / (da + df)
dist_corr_acc = DistTotal * RelAccDec
da = da + dist_corr_acc
dist_corr_dec = DistTotal * (1  RelAccDec)
df = df + dist_corr_dec
taux = (Sqr((a * dist) + (v0 * v0))  v0) / a
vmax = v0 + (a * taux)
End If
End If
For a data set of
vmax = 6000
v0 = 500
a = 2000
x0 = 200
xf = 1200
I should get a vmax of 1457 but I'm getting a vmax of 1500. as a first approximation this is ok, but I would like to get the right one from start.
Can you see something wrong with the approach?
Thank you very much Ralf.
PS: I'm sorry to annoy you.





Hola Joan,
I can't understand in the Moment from where the formula for taux comes.
I would work with the formula s = 0,5 * a * t² which is for t=(s / (0,5 * a))^0,5  you have the Acceleration and also the new calculated distance (s = da or df).
Would you give this approach a try ?
If it also fails I will tomorrow look and try something else.
PS : don't think about it  you're welcome  de nada



