Maximum space consumption of stack and queue for DFS and BFS

I’m trying to determine the maximum memory consumption of the “pending nodes” data structure (stack/queue) for both travelings: BFS and (preorder) DFS.

Since BFS and DFS while traveling graphs have node discovery control (no loops), we can analyze the problem by thinking in terms of trees instead of graphs, where your starting node is taken as root, as usual.

I’ve started by assuming that the resulting traveling is a complete tree (all leafs have same depth), with height $ h$ , $ n$ nodes, and thus all nodes having degree $ d$ (except leafs).

Of course, since the tree is complete, $ n$ can be calculated from $ h$ and $ d$ :

$ $ n = \frac{1 – d^{h + 1}}{1 – d}$ $

Under this asumption, the worst case scenario for DFS is when you are in the deepest non-leaf node of the first branch of the tree: since each time you pop a node, you insert all of its children, for each level, you have $ D – 1$ pending nodes in the stack, except in the last non-leaf, where all of its children are inserted.

If you, instead of being in the first branch, were in another one, you would have some branch with less than $ d – 1$ pending children in the stack, and thus you have less nodes in the stack.

So the maximum memory consumption of DFS for a complete graph with homogeneus degree is ($ ms$ stands for maximum space):

$ $ ms = h * (d – 1) + 1$ $

This last + 1 represent the extra child for the last non-leaf node. For instance, for a tree with $ d = 4$ and $ h = 20$ nodes, a DFS’s stack would require as maximum:

$ $ ms_{DFS} = 20 * 3 + 1 = 81\ nodes$ $

Taking into account that this graph would have $ n = 1.4660155e^{12}$ nodes, this is a more than admisible amount. That’s the adventage of logarithmic space complexity ($ h = \lfloor log_d((d-1)n)\rfloor$ ).

However, for BFS, which have exponential space complexity, the worst case scenario is when you have all leafs pending to be discovered, while having discovered every other node, so your queue contains all leafs (so have the full last-level pending to be discovered but nothing else):

$ $ ms_{BFS} = d^h\ nodes$ $

which, from our example, equals $ 1.0995116e^{12}$ .

My problem now is relaxing the restriction of the graph to be complete, so $ d$ is not an homogeneus degree anymore, but an average degree instead (which can contain now decimals), and the tree can have any disbalance, even being a list. Consequently, the number of nodes is free, so it’s not attach to d and h as before.

If $ d$ is an average degree and $ n$ any amount of nodes, I’ve tried to model somehow an upper bound of space consumption by first modelling a complete tree with an homogeneus $ \lfloor d\rfloor$ degree, and then adding children to the last leaf until getting $ d$ (I assume that the resulting number of nodes should equal $ n$ , but I’m not sure on that either; I’ve even tried to calculate, given some $ d$ and $ n$ , a lower and upper bound for the height of the tree).

Since $ d$ is an average, if some node has more than $ d$ children is because some other node has less than $ d$ children, and thus the idea was to find the worst case scenario for DFS and BFS by removing children from one node and moving the cut branch as child of another node or, in general, finding somehow the closest upper bound as possible of memory consumption, but I couldn’t find a way.

The thing is that, if you apply this height increase repeatedly by moving sibling branches to deepest levels, you would probably end up having a lot parent or sibling paths consisting of just lists, which would be removed from the stack/queue very quickly, and thus there must be some tree state where you cannot make the space consumption worst than that. I assume though that the “worst tree” can be different from DFS and BFS though.

Is making this upper bound (or even exact amount) calculation even possible? Or the worst case scenario is just the balanced one?

Install Ubuntu Server on unused unformated partition (or on free space) – DUAL Boot

Context: – 1 SSD – Secure boot UEFI – 50 GB space

I want to install Ubuntu Server on a system that has a newly created “shrunk” space from Windows 10. I have tried both partitioned and by setting it up as a “Simple Drive” without any file system.

When using “free space” (without any partition): When I am using the Ubuntu Server Installer the free space is visible in the installer but I can not choose any option to install on it.

When set up as a partition without any file system I can choose the drive under manual but not sure how to continue the installation after that. I can apparently format it and set up RAID or LVM but the installation instructions I find is not for the “manual” mode. Only for using the whole disk. If I choose manual, should I use LVM on partition 5?

Please advice =)

Injectivity verification in o(n) space and O(n) time

The problem I want to solve is this: Given a list $ A$ of $ n$ elements, I want to verify that they are all distinct. If I were to do this “myself”, I would need $ O(n)$ space and $ O(n\log n)$ time to solve it, e.g. via a hashmap or binary tree. Luckily, I have an untrustworthy but omnipotent oracle ally who is willing to give me hints on how to solve the problem.

The oracle is allowed to provide me $ O(n)$ of hints, and I want an algorithm that will read $ A$ and the oracle input (both read only) and determine either that $ A$ has no duplicates, or that the oracle has given me a bad hint, in time $ O(n)$ and much smaller read-write space ($ O(1)$ or $ O(\log n)$ ).

Can it be done?

Apache Error. no space left

I am trying to restart my Apache but I keep getting this error:

localhost systemd[1]: apache2.service: Failed with result 'resources'. localhost systemd[1]: apache2.service: Failed to run 'start' task: No space left on device localhost systemd[1]: Failed to start The Apache HTTP Server. localhost systemd[1]: apache2.service: Failed with result 'resources'. localhost systemd[1]: apache2.service: Failed to run 'start' task: No space left on device systemd[1]: Failed to start The Apache HTTP Server. systemd[1]: apache2.service: Failed with result 'resources'. localhost systemd[1]: apache2.service: Failed to run 'start' task: No space left on device localhost systemd[1]: Failed to start The Apache HTTP Server. localhost systemd[1]: apache2.service: Failed with result 'resources'. 

How to do Colored Lights in CIE XYZ/LUV-like Space?

I’ve a 2d background, some sprites, blitted onto it. And over all that in the final pass I draw colored lights, to make projectiles look cooler. Basically I apply a classic lightmap, which is colored in the process of blitting.

With RGB I used simple, but incorrect code:

//dr,dg,db - source before highlight //e = light energy //lr,lg,lb - color filter applied to the light energy ResultColor = RGB(lighten(dr,e*lr),lighten(dg,e*lg),lighten(db,e*lb));  //light energy divisor (0x100*4*32) #define EDIV 15 uint8_t lighten(int t, int e) {   return clamp_byte(t + ((t*e)>>EDIV)); } 

Now in CIE-style spaces, instead of RGB, we have luminance coordinate (L in LUV, or Y in XYZ), and two chroma coords, picking the chroma inside the color triangle.

Calculating light in CIE appears to be simple, it is just:

result_light = dst_light*incoming_light 

But what about XZ or UV? I tried doing simple averaging:

result_x = 0.5*dx + 0.5*lx; result_z = 0.5*dz + 0.5*lz; 

but it gave too bland of a result, compared to the original RGB color-filter:

enter image description here

Maybe instead of taking 0.5, these weights should depend on the light component somehow? If so, what is the proper matrix? I’m sure it can exist, because the transform from CIE XYZ to RGB is linear.

Unity Space invaders with top 3 players

I’m about to create a simple Space Invaders game but I have a difficulty on it, I have to create like a Top3 weekly, from all the users and get the top three most scored users, this is easy, is a backend task, but I’m wondering if is there any backend for Unity to make it simpler, I know how to create API Rest for many frameworks but I’m used to use Spring, is that good for Unity? If now, what’s better? Is there any library to do an API calls from Unity? Like Retrofit in Android? I’m asking it because I’d like to have like a Log in to game, register etc, but I don’t know if it’s a work of Unity or not, since I need to have the user tracked.

Also I want to export this Space invaders to iOS and Android, is that ok, right? I’ve been looking and Unity facilites to you the export.

Does the rule that you cannot willingly end your move in another creature’s space force or prevent certain actions?

There is a rule in the “Moving Around Other Creatures” section which states:

Whether a creature is a friend or an enemy, you can’t willingly end your move in its space…

I am wondering just how absolute this rule is and have come up with example situations where its application is unclear to me:

  1. On your turn, you are forced to occupy the same space as another creature, you have no more movement available, but you still have your action or bonus action available. Are you required to take the Dash action or to use some method (such as casting misty step) to get you out of the creature’s space?

  2. Caltrops state:

    Any creature that enters the area must succeed on a DC 15 dexterity saving throw or stop moving and take 1 piercing damage. Until the creature regains at least 1 hit point, its walking speed is reduced by 10 feet. A creature moving through the area at half speed doesn’t need to make the saving throw.

    An adjacent creature in standing on top of caltrops, and you only have 15 speed (and 15 movement left). I believe that you could not walk through them at half speed as you would run out of movement and be stuck in the creature’s space.
    However, could you walk through them normally even though they have a chance of having your move stop in the creature’s space (which, presumably, the character would know about, and thus would make it a willing decision)?

  3. Everything is difficult terrain, there is an adjacent creature, and you have 15 feet of movement left, could you move onto the creature’s space and then realize you can’t leave that space (as you don’t have enough movement to do so)?

I believe that my question is different from this one in a few ways. My second and third examples involve more willingly ending your move in another creature’s space (at least to me they seem to be more willingly done) and my first example calls into question what happens when the creature still has a way to gain the ability to leave the creature’s space (such as by taking the Dash action or casting misty step) which the linked question did not mention or address.

Does the rule preventing you from ending your turn in another creature’s space force you to take certain actions?