Is log(n^c) equal O(log(n)) - algorithm

Does log(n^c)=O(log(n)) such that c is a constant?
I think this is true as log(n^c)/log(n)<=C2
so c<=C2. Is this true? If not what is true?

Yes, because you can convert it to

log(n^c)=clog(n)
log(n^c)/log(n)=c(log(n)/log(n))=c

Related

How can this integral be solved?

In the maple:
In the WolframAlpha:
What it is wrong? Could you explain me?
In WolframAlpha testing the two results to see if they are the same or not
Simplify[-1/2 x(cos(log(34 x))-sin(log(34 x)))==
(x tan(log(34 x)/2)-x/2+x tan(log(34 x)/2)^2/2)/(1+tan(log(34 x)/2)^2)]
(all done on a single line) returns
True
Link to WolframAlpha result
so the result from WolframAlpha and from Maple are equivalent, they are just expressed in different forms.
Ah, a simpler way to get the same result, doesn't even need the Simplify
-1/2 x(cos(log(34 x))-sin(log(34 x)))==
(x tan(log(34 x)/2)-x/2+x tan(log(34 x)/2)^2/2)/(1+tan(log(34 x)/2)^2)
returns
True
Another link to WolframAlpha
They are different representations of the same thing.
It is quite straightforward to demonstrate this in Maple itself.
restart;
A1 := int(sin(ln(34*x)),x):
lprint(A1);
(x*tan(1/2*ln(34*x))-1/2*x+1/2*x*tan(1/2*ln(34*x))^2)
/(1+tan(1/2*ln(34*x))^2)
A2 := combine(combine(simplify(A1))):
lprint(A2);
1/2*x*sin(ln(34*x))-1/2*x*cos(ln(34*x))
simplify(A1 - A2);
0

Xquery for determining all nodes are unique

Assuming a document such as:
<a>
<b>TEST1</b>
<b>TEST2</b>
<b>TEST1</b>
</a>
Is there any Xquery one liner you can use to check that all values of b are unique without having to run a for-each of on the doc? So for example in the above document it would return false, whereas in the below document it would return true
<a>
<b>TEST1</b>
<b>TEST2</b>
<b>TEST3</b>
</a>
Similar approach but using empty() might be a bit more efficient :
empty(/a/b[. = following-sibling::b])
empty() returns true if the parameter expression yields empty sequence, and returns false otherwise. So in this case, if there found sibling b with the same value a.k.a a dupe, empty() will return false.
You can look for sibling with same value e,g:
count(b[preceding-sibling::b = .])
or to get true or false:
not(b[preceding-sibling::b = .])
The most efficient is probably
count(b) = count(distinct-values(b))
The other solutions you have been given are likely to be quadratic in the number of test elements, whereas this is likely to be O(n log n).
(However, this is on the assumption that duplicates are rare. If duplicates are very common, then some kind of fold operation might find them faster, especially with XQuery 3.0).

Delete an array from a multi-dimensional array in ruby

I have a multi-dimensional array of this form:
array = [["http://domain.com/product.html", 10], ["http://domain.com/product.html", 150], ["http://domain.com/product.html", 500]]
I need to delete all arrays that have the last value smaller than 150.
I already tried the following, but it doesn't seem to have any effect:
array.delete_if {|element| element.last < 150 }
Any help will be highly appreciated. Thanks.
I would probably do it this way:
array.reject!{|x| x if x.last < 150}
You can also use this:
array.map{|f| f if f.last < 150}.compact
I don't know if it is better or not than Akarsh, just another solution that I would have used.
Anyways, your solution works, user3493101, but if it doesn't, you can still use that.

How to simplify this expression?

F(A,B,C)=ABC+A'BC+A'BC'+AB'C+AC'
how to simplify this expression?
Need help...
Thanks.
How would you simplify this boolean expression? I don't know how to apply the boolean laws
ABC+A'B(C+C')+AB'C+AC' ==
ABC+A'B+ABC+AC'==
AC(B+B')+A'B+AC'==
AC+A'B+AC'==
A+A'B==
A+B
I haven't don't this in a long time. :(
F(A,B,C)=ABC+A'BC+A'BC'+AB'C+AC'
(A + A')BC+A'BC'+AB'C+AC'
BC+A'BC'+AB'C+AC'
B(C+A'C')+A(B'C+C')

Checking if a mathematical transformation returns true on a Ruby range

say I have a Ruby range, 1..500, and I'd like to ask the question of whether any element in that range is evenly divisible by 5. What's the best way to do this?
Try this
(1..500).any?{|n| n%5 == 0 }
Thanks #nash for Ruby sugar:
(1..500).any?{|n| n.modulo(5).zero? }

Resources