Determine whether given f is shortest path function

I have the following question: Let $ G = (V,E)$ be a directed graph with a weight function $ w:E\rightarrow \mathbb{R}^+$ , and let $ s \in V$ be a vertex such that there is a path from $ v$ to every other vertex, i.e $ 0\leq dist(s,v) < \infty$ . Let $ f\colon V \to \mathbb R$ a given function. Describe an algorithm that runs in $ O(|V| + |E|)$ that determines wethter this given $ f$ is the shortest path function from $ s$ , i.e $ \forall v \in V :f(v)=dist(s,v)$ .

What I thought about was to check for every $ v \in V$ whether $ f$ fulfill the two following demands:

  1. $ f(s)=0$
  2. $ f(v) \leq f(u) + w(uv)$ for all $ u \in V$ and $ uv \in E$

This runs in the proper complexity. I thought to prove it by showing that $ f(v) \leq dist(s,v) \land f(v) \geq dist(u,v) \Rightarrow f(v) = dist(f,v)$

I proved that $ f(v) \leq dist(s,v)$ , but I am stuck at proving that $ f(v) \geq dist(s,v)$ .

Decide whether two strings $x, y$ can be split into substrings $a,b,c$ such that $x=abc$ and $y=cba$

What is the fastest algorithm for the following problem?

Given two strings $ x, y \in \Sigma^*$ as input, decide whether there exists strings $ a, b, c \in \Sigma^*$ , such that $ x=abc$ and $ y=cba$ .

By calculating all the length of the longest common prefix of $ s = x$ y$ and all suffixes of $ s$ , we can compute all candidates for $ a$ in $ O(n)$ time.

For each candidate of $ a$ with length $ k$ , we now just need to check whether $ x_k, x_{k + 1}, \ldots, x_{n}$ is a rotation of $ y_0, y_1, \ldots, y_{n – k}$ . This can of course be done in $ O(n)$ .

However checking the rotations naively results in a worst-case $ O(n^2)$ algorithm.

It seems that using the result from either https://arxiv.org/pdf/1601.08051.pdf or https://arxiv.org/pdf/1311.6235.pdf would make the algorithm run in expected $ O(n)$ time.

Is there a simpler way of speeding up the rotation checking, where it is still faster than $ O(n^2)$ ? Is there a way of making it deterministic, so that it still runs in $ O(n)$ time?

Deciding on whether to learn Rust or OpenGL next

I’m currently a student studying Computer Science. I love to learn new things in order to further enhance my skills in the things I find useful. Part of me wants to learn OpenGL so I can get a better understanding of graphics programming, and to apply it with Unity game making (working on my very first game). However, I am also intrigued in what I read about Rust and too also gain an additional programming language that I can add to my arsenal. I’m stuck and don’t know which would be more useful in the long run. I would appropriate all the help I can get. Thank you!

Does the monster, spectator, need to roll an attack die to determine whether it hits with its rays?

The spectator is a D&D monster that can shoot rays out from its eyes and if it attacks you, you have to exceed a DC 13 saving throw in a particular skill. But, on top of that, does the spectator have to also roll an attack roll to determine whether the ray hits its target or misses.

In determining whether any segments intersect, why there must be some sweep where segments $a$ and $b$ are consecutive?

In CLRS, Section 33.1, we are given the any-segment-intersect algorithm. It’s a cool algorithm for sure but going through the correctness proof, I don’t know how to prove the following:

“Given that we have two segments (call them $ a$ and $ b$ ) that intersect at some point $ p$ , then there must be some sweep line $ x$ for which intersecting segments $ a$ and $ b$ are consecutive in the total preorder.” why they must consecutive at some sweep line?

I do see why visually using the figure on page 33.4 (page 1023) but I don’t know a proof for this statement. How can I prove this?

If anyone had read that section, please enlighten me. Thank you

An approach to determine whether language is regular or not?

I have the following problem. I need to determine whether this language is regular or not:

L:= { w∈Σ*: for every α ∈ Σ, |w|α is even or divisible by 3}

(α is index here |w|)

I know that I need to use deterministic/non-deterministic finite automata, regular expression/grammar to prove that it is regular or to use pumping lemma to prove that it is not.

But I’m not sure how to approach this problem to start proving something. Is this trial and error method or is there some way to know from the start?

I appreciate your help!

Is there an algorithm to check if two spheres are in collision and whether they’re colliding on the x or the x axis?

I was wondering if there was a way to find out whether a spheres is intersecting another sphere on either its x or its z axis. For instance, Planet A is moving along the Z Axis towards Planet B a stationary object and when collision occurs I would like to get a reponse that tells me that they collided on the zAxis. I can find out if a collsion has occured using the code below however I’m not sure on how to impliment the directional aspect of this. Any help would be appreciated.

    enum ECol { x_Axis, z_Axis, none };      // Collision detection between two spheres      distanceX = sphere2XPosition - sphere1XPosition;     distanceZ = sphere2ZPosition - sphere1ZPosition;     distance = sqrt(distanceX * distanceX + distanceZ * distanceZ );      if (distance < (sphere1Radius + sphere2Radius))     { // Collision occurred }