KD-tree range search/query complexity

I’m currently reading up on the time complexity of the range search/query for an unbalanced KD-tree.

I see all these different articles where the same the complexity is O(sqrt(N)) where N is the number of points. And this order of growth is proportional to the number of points a vertical line can intersect with in a KD-tree. But if we create a KD-tree with 7 points, the MAX intersects points from a vertical line should be sqrt(7) = 2,64. Let’s assume that it’s rounded up to 3. While drawing the some “test” kd-tree’s you see this relation is true. But when you draw unbalanced kd-trees, this is not true.

How would you go about analyzing the range search complexity of an unbalanced KD-tree?

My thoughts: An unbalanced KD-tree would be O(N) since the points/nodes are aligned to one side(Like a linked-list)

IndexError: list index out of range

I am pretty new in Python (or more precisely in programming).

I found on the Internet (link) this code:

import numpy as np import scipy.integrate as sp import sys g, l, k = 9.81, 10, float( sys.argv[1] ) PTS = 3000 def rhs( y, t, g, l, k ): return [ k*t/l * np.cos(y[1]) - g/l * np.sin(y[1]), y[0] ] y0 = [ 0, 0 ] t = np.linspace( 0, 30, PTS+1 ) y = sp.odeint( rhs , y0, t, args = (g, l, k) ) for i in range(PTS): print( t[i], y[i][1] * 180/np.pi, np.arctan(k*t[i]/g) * 180/np.pi ) 

I understood that I need to input a value of k to this code, so I got this code:

import numpy as np import scipy.integrate as sp import sys g, l, k = 9.81, 10, 0.4, float( sys.argv[1] ) PTS = 3000 def rhs( y, t, g, l, k ): return [ k*t/l * np.cos(y[1]) - g/l * np.sin(y[1]), y[0] ] y0 = [ 0, 0 ] t = np.linspace( 0, 30, PTS+1 ) y = sp.odeint( rhs , y0, t, args = (g, l, k) ) for i in range(PTS): print( t[i], y[i][1] * 180/np.pi, np.arctan(k*t[i]/g) * 180/np.pi ) 

But I got an error: IndexError: list index out of range.

I found on the Internet that this error means that I am providing an index for which a list element does not exist, but I do not know, how to fix it. Could somebody explain to me where is the problem and alternatively how to fix it, please?

Leaving threatened range with Opportunistic Withdrawal

The Opportunistic Withdrawal feat from D&D 4e PHB3 says:

While you are adjacent to an enemy granting combat advantage to you your movement doesn’t provoke opportunity Attacks from that enemy.

If an enemy grants me advantage, does Opportunistic Withdrawal allow me to move out of the threatened area without suffering OA? An OA is an immediate interruption so technically I’m still adjacent, so how does it work in this case?

Using ScalingFunctions to ListPlot data in specific range and also to print FrameTicks with appropriate precision, gives strange fluctuations

Through the following code, we generate Tp1:

In[1]:= tempPV = (   3 \[Pi]^(2/3) + 6 6^(2/3) P \[Pi] V^(2/3) -     6^(2/3) V^(     2/3) (-3 + Sqrt[       9 + (4 6^(2/3) \[Pi]^(4/3) q^2)/(        V^(4/3) \[Beta]^2)]) \[Beta]^2 +     3 6^(2/3) V^(     2/3) \[Beta]^2 Log[      1/6 (3 + Sqrt[         9 + (4 6^(2/3) \[Pi]^(4/3) q^2)/(V^(4/3) \[Beta]^2)])])/(   6 6^(1/3) \[Pi]^(4/3) V^(1/3));  In[2]:= \[Beta]in = 0.01; \[Beta]fi = 100; \[Beta]st = 0.005; Table[   xlog[\[Beta]] = Log[10, \[Beta]]   , {\[Beta], \[Beta]in, \[Beta]fi, \[Beta]st}];  In[6]:= parap1 = {q -> 0.1, V4 -> 5000}; parap2 = {T2 -> 15, q -> 0.1, V2 -> 10000}; parap4 = {T4 -> 5, q -> 0.1, V4 -> 5000};  In[9]:= Table[    pressp2[\[Beta]] =     P /. Solve[(tempPV - T2 == 0) /. V -> V2 /. parap2, P][[1]];(*p1=   p2*)   pressp4[\[Beta]] =     P /. Solve[(tempPV - T4 == 0) /. V -> V4 /. parap4, P][[1]];(*p3=   p4*)   Tp1[\[Beta]] =     T1 /. Solve[(tempPV - T1 == 0) /. V -> V4 /. parap1 /.         P -> pressp2[\[Beta]], T1][[1]];   , {\[Beta], \[Beta]in, \[Beta]fi, \[Beta]st}];  In[10]:= mi =   Min[Table[Tp1[\[Beta]], {\[Beta], \[Beta]in, \[Beta]fi, \[Beta]st}]] ma = Max[Table[    Tp1[\[Beta]], {\[Beta], \[Beta]in, \[Beta]fi, \[Beta]st}]]  Out[10]= 11.9083  Out[11]= 11.9083  In[12]:= ListPlot[  Table[{xlog[\[Beta]],     Tp1[\[Beta]]}, {\[Beta], \[Beta]in, \[Beta]fi, \[Beta]st}],   ScalingFunctions -> {Rescale[#, {mi, ma}, {0., 1.}] &,     Rescale[#, {0., 1.}, {mi, ma}] &}, Joined -> True, Frame -> True,   FrameStyle -> Black,   BaseStyle -> {FontSize -> 14, PrintPrecision -> 11},   FrameLabel -> {"\!$$\*SubscriptBox[\(log$$, $$10$$]\) (\[Beta])",     "\!$$\*SubscriptBox[\(T$$, $$1$$]\)"}, RotateLabel -> False,   PlotStyle -> {Blue, Thickness[0.006]},   PlotRange -> {{-2, 2}, {mi, ma}}, Axes -> None, AspectRatio -> 0.8,   ImageSize -> 400, FrameTicks -> {{ticks, None}, {Automatic, None}}]  

The result is the following plot:

As it is clear there is a strange fluctuation for $$log_{10}^{\beta}=1-2$$. As it should be a smooth decreasing plot, what is the origin of these fluctuations? How to fix this possibly numerical error?

maximise BITWISE AND find an integer in range [L,R]

Given an integer x
find y in range L<=y<=R so that x & y is maximum & is Bitwise AND where 0< L, R <10^12 I had tried to iterate and solve but it is resulting in TLE

Why does a range query on a segment tree return at most $\lceil \log_2{N} \rceil$ nodes?

If an array $$A[1 \ldots N]$$ is represented using a segment tree having sets in each interval, why does a range query $$[L\ldots R]$$ returns at most $$\lceil \log_2{N} \rceil$$ sets (or disjoint intervals)?

To quote:

Find a disjoint coverage of the query range using the standard segment tree query procedure. We get $$O(\log n)$$ disjoint nodes, the union of whose multisets is exactly the multiset of values in the query range. Let’s call those multisets $$s_1, \dots, s_m$$ (with $$m \le \lceil \log_2 n \rceil$$).

I tried searching for a proof, but couldn’t find it on any site. Can anyone help me prove it?

Matrix multiplication over range in $O(n)$

Let $$M$$ denote the time it takes to multiply 2 matrices, and $$Q$$ denote the number of queries.

Is it possible to create a data structure with $$O((n+Q)M)$$ pre-computation time, and can answer range matrix multiplication queries that satisfy $$l_{i-1}\le l_i$$ and $$r_{i-1}\le r_i$$ with an overall time complexity of $$O((n+Q)M)$$. I’ve been thinking a lot on how to manipulate 2 pointers to get the intended results, but haven’t come up with any approach yet. The matrices are not necessarily invertible.

Can a Major Image illusion move outside of the range in which it was originally cast?

Major Image (relevant sections):

You create the image of an object, a creature, or some other visible phenomenon that is no larger than a 20.foot cube. The image appears at a spot that you can see within range and lasts for the duration.

As long as you are within range of the illusion, you can use your action to cause the image to move to any other spot within range. As the image changes location, you can alter its appearance so that its movements appear natural for the image. For example, if you create an image of a creature and move it, you can alter the image so that it appears to be walking.

At Higher Levels: When you cast this spell using a spell slot of 6th level or higher, the spell lasts until dispelled, without requiring your concentration.

I initially presumed this to mean you can create an illusion limited by the 20ft cube maximum size, and then the illusion can move within the original 120ft casting radius, with no option to leave it. But upon reading it again, it seems that if the caster is within range of the illusion, the character can command the illusion to move outside any initial range, and indeed can have the illusion follow the character around the map for miles. Is this correct?

If the initial target of the Hex spell is reduced to 0 HP, can the curse be moved to an unseen target or one out of range?

To originally cast the spell hex, you must target “a creature you can see within range”. The spell says that if the target drops to 0 hit points before the spell ends, the caster can use a bonus action on a subsequent turn to move the curse to a new creature. However, it does not say that the new creature being cursed has to be seen or within range.

If the initial target of hex is reduced to 0 HP, can the curse be moved to an unseen target or one out of range?

Rules as Written, it seems possible to do so, but that seems a bit overpowered.

Level Range of Dragon of Icespire Peak

I am planning to run a introductory campaign with the scenario ‘Dragon of Icespire Peak’, and I would like to estimate how long it will going to take. However, there is no where in the book written about the level range of this scenario, unless I have miss some phrases.

Can someone tell me what is the level range and how long the campaign would take assuming playing it once a week for about 4 to 5 hours each.