Difficulty in understanding a portion in the proof of the $\text{“white path”}$ theorem as with in CLRS text

I was going through the $ \text{DFS}$ section of the Introduction to Algorithms by Cormen et. al. and I faced difficulty in understanding the $ \Leftarrow$ direction of the proof of the white path theorem. Now the theorem which is the subject of this question depends on two other theorems so I present the dependence before presenting the actual theorem and the difficulty which I face in the said.


Theorem 22.7 (Parenthesis theorem) In any depth-first search of a (directed or undirected) graph $ G = (V, E)$ , for any two vertices $ u$ and $ v$ ;, exactly one of the following three conditions holds:

  • the intervals $ [d[u], f[u]]$ and $ [d[v], f[v]]$ are entirely disjoint, and neither $ u$ nor $ v$ is a descendant of the other in the depth-first forest,

  • the interval $ [d[u], f[u]]$ is contained entirely within the interval $ [d[v], f[v]]$ , and $ u$ is a descendant of $ v$ ; in a depth-first tree,

  • the interval $ [d[v], f[v]]$ is contained entirely within the interval $ [d[u], f[u]]$ , and $ v$ is a descendant of $ u$ in a depth-first tree.

Corollary 22.8 (Nesting of descendants’ intervals) Vertex $ v$ is a proper descendant of vertex $ u$ in the depth-first forest for a (directed or undirected) graph $ G$ if and only if $ d[u] < d[v] < f[v] < f[u]$ .

Theorem 22.9 (White-path theorem)

In a depth-first forest of a (directed or undirected) graph $ G = (V, E)$ , vertex $ v$ is a descendant of vertex $ u$ if and only if at the time $ d[u]$ that the search discovers $ u$ , vertex $ v$ can be reached from $ u$ along a path consisting entirely of white vertices.


$ \Rightarrow$ : Assume that $ v$ is a descendant of $ u$ . Let $ w$ be any vertex on the path between $ u$ and $ v$ in the depth-first tree, so that $ w$ is a descendant of $ u$ . By Corollary 22.8, $ d[u] < d[w]$ , and so $ w$ is white at time d[u].

$ \Leftarrow$ :

  1. Suppose that vertex $ v$ is reachable from $ u$ along a path of white vertices at time $ d[u]$ , but $ v$ does not become a descendant of $ u$ in the depth-first tree.
  2. Without loss of generality, assume that every other vertex along the path becomes a descendant of $ u$ . (Otherwise, let $ v$ be the closest vertex to $ u$ along the path that doesn’t become a descendant of $ u$ .)
  3. Let $ w$ be the predecessor of $ v$ in the path, so that $ w$ is a descendant of $ u$ ($ w$ and $ u$ may in fact be the same vertex) and, by Corollary 22.8, $ f[w] \leq f[u]$ .
  4. Note that $ v$ must be discovered after $ u$ is discovered, but before $ w$ is finished.$ ^\dagger$ Therefore, $ d[u] < d[v] < f[w] \leq f[u]$ .
  5. Theorem 22.7 then implies that the interval $ [d[v], f[v]]$ is contained entirely within the interval $ [d[u], f[u]]$ .$ ^{\dagger\dagger}$
  6. By Corollary 22.8, $ v$ must after all be a descendant of $ u$ . $ ^\ddagger$

$ \dagger$ : Now it is clear that since $ u$ is the first vertex to be discovered so any other vertex (including $ v$ ) is discovered after it. In point $ 1$ we assume that $ v$ does not become the decendent of $ u$ , but by the statement that but before $ w$ is finished I feel that this is as a result of exploring the edge $ (w,v)$ (this exploration makes $ v$ ultimately the descendant of $ u$ , so the proof should have ended here $ ^\star$ )

$ \dagger\dagger$ : Considering the exact statement of theorem 22.7 , I do not get which fact leads to the implication in $ 5$ .

$ \ddagger$ : The proof should have ended in the $ \star$ , but why the stretch to this line $ 6$ .

Definitely I am unable to get the meaning the proof of the $ \Leftarrow$ . I hope the authors are using proof by contradiction.

(I thought of an alternate inductive prove. Let vertex $ v$ is reachable from $ u$ along a path of white vertices at time $ d[u]$ . We apply induction on the vertices in the white path. As a base case $ u$ is an improper descendant of itself. Inductive hypothesis, let all vertices from $ u$ to $ w$ be descendants of $ u$ , where $ w$ is the predecessor of $ v$ in the white path. We prove the inductive hypothesis by the exploration of the edge $ (w,v)$ . But I want to understand the proof the text.)

Shortest Path in a Directed Acyclic Graph with two types of costs

I am given a directed acyclic graph $ G = (V,E)$ , which can be assumed to be topologically ordered (if needed). Each edge $ e$ in G has two types of costs – a nominal cost $ w(e)$ and a spiked cost $ p(e)$ . I am also given two nodes in $ G$ , node $ s$ and node $ t$ .

The goal is to find a path from $ s$ to $ t$ that minimizes the following cost: $ $ \sum_e w(e) + \max_e \{p(e)\},$ $ where the sum and maximum are taken over all edges of the path.

Standard dynamic programming methods show that this problem is solvable in $ O(E^2)$ time. Is there a more efficient way to solve it? Ideally, an $ O(E\cdot \operatorname{polylog}(E,V))$ algorithm would be nice.

This is the $ O(E^2)$ solution I found using dynamic programming, if it’ll help.

First, order all costs $ p(e)$ in an ascending order. This takes $ O(E\log(E))$ time.

Second, define the state space consisting of states $ (x,i)$ where $ x$ is a node in the graph and $ i\in \{1,2,…,|E|\}$ . It represents "We are in node $ x$ , and the highest edge weight $ p(e)$ we have seen so far is the $ i$ -th largest".

Let $ V(x,i)$ be the length of the shortest path (in the classical sense) from $ s$ to $ x$ , where the highest $ p(e)$ encountered was the $ i$ -th largest. It’s easy to compute $ V(x,i)$ given $ V(y,j)$ for any predecessor $ y$ of $ x$ and any $ j \in \{1,…,|E|\}$ (there are two cases to consider – the edge $ y\to x$ is has the $ j$ -th largest weight, or it does not).

At every state $ (x,i)$ , this computation finds the minimum of about $ \deg(x)$ values. Thus the complexity is $ $ O(E) \cdot \sum_{x\in V} \deg(x) = O(E^2),$ $ as each node is associated to $ |E|$ different states.

shortest path algorithm – why backtrack from the end node instead of starting from the starting node?

I was watching a dynamic programming video by Erik Demaine . He says here https://youtu.be/OQ5jsbhAv_M?t=2133 , finding the shortest path by guessing the node after the starting node is not the right approach, and instead should guess the node before the last node. I didn’t understand his explanation. Can someone explain better why find the path backwards? It seems to me that you should get the same answer either way and both approaches are equally good.

Graph search or shortest path algorithm for graph with multiple “goals”?

I did a project in a class using A* search to solve an 8-puzzle. But what about a puzzle with multiple ‘solved’ states? For example, and 8 puzzle with some repeated tiles. I’m not sure whether something like A* search could still work or not. I have trouble fathoming how a heuristic might be designed. Are their other shortest path algorithms or search algorithms that are better suited for this kind of problem?

Where can I learn about reverse proxy’s and path traversal SSRF?

I am tasked to record a lesson for my students about path traversal SSRF (Server-Side Request Forgery) my understanding is reverse proxy’s are heavily used on big websites which have a massive attack surface.

Some weird proxy’s process requests differently at times an attacker is able to traverse out of an API call and access internal apps routing through a reverse proxy.

I am wanting to learn the following things about the things above.

  1. How do I get access to private endpoints?
  2. What are some interesting payloads to try?
  3. How would I be able to achieve access to internal apps?

I hope anyone on here can help me 🙂

Cheers, Blake

Moving platform falls instead of following path

I was trying to make my platform move from Point A to Point B so that the player jumps on the platform. I’ve implemented the code(down below) and made all the necessary objects for it move. But, when I hit the Play button, the platform falls down and the original platform(of which I used a duplicate to make the moving platform) also disappears. Please have a look at these screenshots:

enter image description here enter image description here enter image description here enter image description here enter image description here

using UnityEngine; using System.Collections;  public class PlatformMover : MonoBehaviour {      public GameObject platform; // reference to the platform to move      public GameObject[] myWaypoints; // array of all the waypoints      [Range(0.0f, 10.0f)] // create a slider in the editor and set limits on moveSpeed     public float moveSpeed = 5f; // enemy move speed     public float waitAtWaypointTime = 1f; // how long to wait at a waypoint before _moving to next waypoint      public bool loop = true; // should it loop through the waypoints      // private variables      Transform _transform;     int _myWaypointIndex = 0;       // used as index for My_Waypoints     float _moveTime;     bool _moving = true;      // Use this for initialization     void Start () {         _transform = platform.transform;         _moveTime = 0f;         _moving = true;     }          // game loop     void Update () {         // if beyond _moveTime, then start moving         if (Time.time >= _moveTime) {             Movement();         }     }      void Movement() {         // if there isn't anything in My_Waypoints         if ((myWaypoints.Length != 0) && (_moving)) {              // move towards waypoint             _transform.position = Vector3.MoveTowards(_transform.position, myWaypoints[_myWaypointIndex].transform.position, moveSpeed * Time.deltaTime);              // if the enemy is close enough to waypoint, make it's new target the next waypoint             if(Vector3.Distance(myWaypoints[_myWaypointIndex].transform.position, _transform.position) <= 0) {                 _myWaypointIndex++;                 _moveTime = Time.time + waitAtWaypointTime;             }                          // reset waypoint back to 0 for looping, otherwise flag not moving for not looping             if(_myWaypointIndex >= myWaypoints.Length) {                 if (loop)                     _myWaypointIndex = 0;                 else                     _moving = false;             }         }     } } 

algorithm to find shortest path connecting EVERY node

I have received a problem to solve and I am not sure what algorithm to use.

TLDR; Find the shortest path to get to every node in a undirected graph

enter image description here

The problem states that one must visit every station in the shanghai metro in the shortest path possible. Interchange Stations (‘edges’) can be reused and you can start / stop anywhere.

I have created a lookup table that shows connected stations as well as the distance to travel (not shown)

"Xinzhuang": [   "Waihuan Rd." : 1 ], "Waihuan Rd.": [   "Xinzhuang": 2.2,   "Lianhua Rd.": 3 ], "Lianhua Rd.": [   "Waihuan Rd.": 4,   "Jinjiang Park": 5, ], "Jinjiang Park": [   "Lianhua Rd.": 9.1,   "South Railway Station": 10.3 ], "South Railway Station": [   "Jinjiang Park": 4.1,   "Caobao Rd.": 1.1,   "Shilong Rd.": 2.5 ], ... 

I found this leetcode problem but it did not mention any specific algorithm and since it was O(2^N * N) I wondered if there was a faster method than BFS.


Since my graph is so big, I was going to reduce the lines with a single path to a single node.

What algorithm can I use that will work in Polynomial time, OR has the least time complexity?

Difficulty in few steps in proof of “Amortized cost of $\text{Find-Set}$ operation is $\Theta(\alpha(n))$”assuming union by rank, path compression

I was reading the section of data structures for disjoint sets from the text CLRS I faced difficulty in understanding few steps in the proof of the lemma as given in the question title. Here we assume we follow union by rank and path compression heuristics. Before we move into our target lemma a few definitions and lemma is required as a prerequisites for the target lemma.

The prerequisites:

$ $ level(x)=\max\{k:rank[p[x]]\geq A_k(rank[x])\}$ $ $ $ iter(x)=\max\{i:rank[p[x]]\geq A_{level(x)}^{(i)}(rank[x])\}$ $ $ $ \phi_q(x) = \begin{cases} \alpha(n).rank[x] &\quad\text{if $ x$ is a root or $ rank[x]=0$ }\ (\alpha(n)-level(x)).rank[x]-iter(x) &\quad\text{if $ x$ is not a root and $ rank[x]\geq1$ }\ \end{cases}$ $

Lemma 21.9: Let $ x$ be a node that is not a root, and suppose that the $ q$ th operation is either a $ \text{Link}$ or $ \text{Find-Set}$ . Then after the $ q$ th operation, $ \phi_q(х) \leq \phi_{q-1}(х)$ . Moreover, if $ rank[x] \geq 1$ and either $ level(x)$ or $ iter(x)$ changes due to the $ q$ th operation, then $ \phi_q(х) < \phi_{q-1}(х) – 1$ . That is, $ x$ ‘s potential cannot increase, and if it has positive rank and either $ level(x)$ or $ iter(x)$ changes, then $ x$ ‘s potential drops by at least $ 1$ .

Now in the proof below I marks the steps where I face problem

Lemma 21.12: The amortized cost of each $ \text{Find-Set}$ operation is $ \Theta(\alpha(n))$ .

Proof: Suppose that the $ q$ th operation is a $ \text{Find-Set}$ and that the find path contains $ s$ nodes. The actual cost of the $ \text{Find-Set}$ operation is $ O(s)$ . We shall show that no node’s potential increases due to the $ \text{Find-Set}$ and that at least $ \max\{0,s – (\alpha(n) + 2)\}$ nodes on the find path have their potential decrease by at least $ 1$ .

To see that no node’s potential increases, we first appeal to Lemma 21.9 for all nodes other than the root. If $ x$ is the root, then its potential is $ \alpha(n) . rank[x]$ , which does not change.

Now we show that at least $ \max\{0,s – (\alpha(n) + 2)\}$ nodes have their potential decrease by at least $ 1$ . Let $ x$ be a node on the find path such that $ rank[x] > 0$ and $ x$ is followed somewhere on the find path by another node $ у$ that is not a root, where $ level(y) = level(x)$ just before the $ \text{Find-Set}$ operation. (Node $ у$ need not immediately follow $ x$ on the find path.) $ \require{color}\colorbox{yellow}{All but at most $ \alpha(n) + 2$ nodes on the find path satisfy these constraints on $ x$ .}$ $ \require{color}\colorbox{yellow}{Those that do not satisfy them are the firstnode on the find path (if it has rank $ 0$ ),}$ $ \require{color}\colorbox{yellow}{ the last node on the path (i.e., the root), and the last node $ w$ on the path for which}$ $ \require{color}\colorbox{yellow}{ $ level(w) = k$ , for each $ k = 0,1,2,…, \alpha(n) – 1$ .}$

Let us fix such a node $ x$ , and we shall show that $ x$ ‘s potential decreases by at least $ 1$ . Let $ k = level(x) = level(y)$ . Just prior to the path compression caused by the $ \text{Find-Set}$ , we have

$ rank[p[x]] \geq A_k^{(iter(x)}(rank[x])$ (by definition of $ iter(x)$ ) ,

$ rank[p[y]] \geq A_k(rank[y])$ (by definition of $ level(y)$ ,

$ rank[y] > rank[p[x]]$ (by Corollary 21.5 and because $ у$ follows $ x$ on the find path)

Putting these inequalities together and letting $ i$ be the value of $ iter(x)$ before path compression, we have

$ rank[p[y]] \geq A_k(rank[y]) \geq A_k(rank[p[x]])$ (because $ A_k(j)$ is strictly increasing) $ > A_k(A_k^{(iter(x)}(rank[x])) = A_k^{(i+1)}(rank[x])$ .

Because path compression will make $ x$ and $ у$ have the same parent, we know that after path compression, $ rank[p[x]] = rank[p[y]]$ and that the path compression does not decrease $ rank[p[y]]$ . Since $ rank[x]$ does not change, after path compression we have that $ \require{color}\colorbox{pink}{$ rank[p[x]]\geq A_k^{(i+1)}(rank[x])$ . Thus, path compression will cause either $ iter(x)$ to }$ $ \require{color}\colorbox{pink}{increase (to atleast $ i + 1$ ) or $ level(x)$ to increase (which occurs if $ iter(x)$ increases}$ $ \require{color}\colorbox{pink}{to at least $ rank[x] + 1$ ). In either case,by Lemma 21.9, we have $ \phi_q(х) \leq \phi_{q-1}(х) – 1$ .}$ $ \require{color}\colorbox{pink}{Hence, $ x$ ‘s potential decreases by at least $ 1$ .}$

The amortized cost of the $ \text{Find-Set}$ operation is the actual cost plus the change in potential. The actual cost is $ O(s)$ , and we have shown that the total potential decreases by at least $ \max\{0,s – (\alpha(n) + 2)\}$ . The amortized cost, therefore, is at most $ O(s) — (s — (\alpha(n) + 2)) = O(s) — s + 0(\alpha(n)) = O(\alpha(n))$ , since we can scale up the units of potential to dominate the constant hidden in $ О (s)$ . ■

In the proof above I could not get the mathematics behind the statements highlighted in yellow and pink. Can anyone help me out?

Find path of file on website with randomized string in it

Users have the possibility to upload a sensitive personal file to a specific website. After uploading, only the user himself and the administrator of the website have the ability to download the file again.

All files of any user are uploaded to the following folder: https://example.com/folder/uploads/.

Before a file is uploaded, it gets renamed to <<username>>.docx.

So for Foo the path would be: https://example.com/folder/uploads/foo.docx and for Gux it’d be https://example.com/folder/uploads/gux.docx.

As you can see, this is not safe at all. Foo could simply examine the download link, and replace his own name in the file-path with the username of other users to download their files.

So to prevent this, the web-developer did the following: Before a file is uploaded, a random string of 15 characters gets prepended to the filename. This random string is different for each upload.

For Foo this would be for example https://example.com/folder/uploads/heh38dhehe83ud37_foo.docx and for Gux https://example.com/folder/uploads/abcnjoei488383b22_gux.docx.

When Foo examines the download-url, he will know in which folder all the files are stored. But there is no way that he could guess the random string that is prepended to Gux’ file. The random string actually functions as a 15-character long password.

In all directories an index.html-file is placed so the directory content does not get listed.

If Foo still wanted to download other users their files, how would he do that? I’m looking for a way Foo would do this by forming a specific URL or HTTP-request. Breaching the server or database is a correct answer but not the kind I’m looking for.

TL;DR: How to find the path of a file on a public website with a unique and randomized string in it? You know the path to the upload-folder, but there is a index.html-file there so you can’t see the content.