is it always true that the depth of BFS is $\leq$ DFS?

I have a simple theoretical question in very basic algorithms, as the title mentions, is it always true that the depth of BFS is $ \leq$ DFS?

From what I understand, the tricky part here is the possible cycles in the graph. Even though that I believe that the depth of BFS will always be less or equal to the depth of DFS.

In each iteration of BFS, from what I understand, the depth might grow by one, but DFS’s grows in each vertex it can not reach, sometimes above the maximal value of BFS.

So, is it always true that the depth of BFS is $ \leq$ DFS?

Optimized Depth First Search?

I’m trying to solve this question:

Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color ci.

Now it’s time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some vertex in hands, while all the other vertices move down so that the tree becomes rooted at the chosen vertex. After that Timofey brings the tree to a trash can.

Timofey doesn’t like it when many colors are mixing together. A subtree annoys him if there are vertices of different color in it. Timofey wants to find a vertex which he should take in hands so that there are no subtrees that annoy him. He doesn’t consider the whole tree as a subtree since he can’t see the color of the root vertex.

A subtree of some vertex is a subgraph containing that vertex and all its descendants.

Your task is to determine if there is a vertex, taking which in hands Timofey wouldn’t be annoyed.

Input The first line contains single integer n (2 ≤ n ≤ 105) — the number of vertices in the tree.

Each of the next n - 1 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v), denoting there is an edge between vertices u and v. It is guaranteed that the given graph is a tree.

The next line contains n integers c1, c2, …, cn (1 ≤ ci ≤ 105), denoting the colors of the vertices.

Output Print “NO” in a single line, if Timofey can’t take the tree in such a way that it doesn’t annoy him.

Otherwise print “YES” in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them.

I have come up with a solution that works but times out on large inputs.

 from collections import defaultdict  n = int(input()) graph = defaultdict(list) colors = defaultdict(lambda: -1) for i in range(n-1):     (u, v) = [int(i) for i in input().split()]     graph[u].append(v)     graph[v].append(u)  c = [int(i) for i in input().strip().split()] colors = {i+1: v for (i, v) in enumerate(c)} bad = set()   def start(start):     nebs = graph[start]     return all(dfs(n, set([start]), colors[n]) for n in nebs)   def dfs(start, visited, want):     visited.add(start)     if colors[start] != want:         return False     for neb in graph[start]:         if neb not in visited:             if not dfs(neb, visited, want):                 return False     return True   found = False ans = -1  for i in range(1, n+1):     if start(i):         found = True         ans = i         break     else:         bad.add(i)  if not found:     print("NO") else:     print("YES")     print(ans)  

I’d love some guidance on how I can make this faster — thank you!

Merge sort and quciksort recursion tree depth

1) I need to determine recursion tree depth for strings composed of 10, 100 and 1000 elements when using merge sort. For the 10 elements one I can do it on a paper, just drawing tree, but what about 100 or 1000 elements? How do I determine recursion tree depth for them? Is there any pattern that I cannot see? What if someone would ask me for recursion tree depth for a string composed of one million elements?

And the second thing is:

2) I need to determine the biggest and the smallest recursion tree depth for strings composed of 10, 100 and 1000 when using quicksort. So it’s kind of similar but those could be any strings, so is there even constant number that defines the smallest and the biggest? How to count this?

And the third thing is:

3) I need to provide a recursive dependency which value for the given n is the number of recursion tree levels of recursive calls of merge sort for an n-element string.

Constructing a 3D virtual map from 2D Depth Maps and $x, y, z, \theta$ coordinates

Context: I intend on building a quadrotor which can generate a 3D virtual map of an area of which it captures photos with a 2D camera.

I plan on first training a Convulational NN to return a depth map from a 2D image, then use the information from that depth map along with the x, y, z coordinates and angular displacement of the quadrotor to generate this 3D map.

What do I need to learn in order to do something on this scale?

Any ways to make this easier?

Thanks, -ShreyJ

FindRoot with NIntegrate: either recursion depth exceeded or numerical integration converging too slowly

Trying to numerically solve an equation involving an integral, either the error Recursion depth exceeded appears (when AccuracyGoal->10 or smaller) or the error Numerical integration converging too slowly appears. In the MWE below, the functions involved are smooth, bounded and the solution for the equation is 1 (as confirmed by Plot[{hdif[z], 0}, {z, smin, 2}]), so there should not be difficulty numerically integrating or solving.

How to find a solution to similar equations which cannot be solved by hand analytically?

MWE

Clear[smin, smax, h, hdif] smin = -1; h[z_] := Exp[-z/2] hdif[zmax_?NumericQ] :=   NIntegrate[(Exp[z] - 1)*h[z], {z, smin, zmax}, AccuracyGoal -> 5] smax = FindRoot[{hdif[smax] == 0}, {smax, 0, smin, Max[-smin, 1000]}] 

Other solutions recommend increasing AccuracyGoal or WorkingPrecision (both of which I tried), cancelling periodic oscillations, integrating piecewise around points where the derivative is discontinuous (these do not apply to the function in question). Replacing NIntegrate with Integrate works for h[z_] := Exp[-z/2], but not for functions without a closed form integral.

Depth of Field Effect?

Hi all,
Just trying to create a modal that zooms and blurs the background back. Based on avgrund by hakim https://lab.hakim.se/avgrund/
Now it has nesting modals also with the help of @deathshadow over at codingforums.
Here is the current state:
https://jsfiddle.net/postcolonialboy/1jz0q3xk/19/
Now, what I am trying to do is:
by clicking the nested modal link, everything should be pushed back again and blurred – like simulating receding layers/depth of field.
I've…

Depth of Field Effect?

do in depth keyword research competitor for $5

Best SEO Keyword Research, Competitor Analyses & Backlinks Analyses [ 100% Positive Clients Reviews Satisfaction Guaranteed ] SEO is truly the most effective way to market a business, you need to be a Good Profitable kw’s research! Here am I finding a good Keywords for your website will increase your Ranking Keywords Research Include: ✔️ Up to 100/200/300+ keywords [No. of Kw’s depended on your niche category or targeted market] ✔️ Ranking KWs Difficulty ✔️ Low SEO Difficulty Easy To Rank ✔️ High Search Volume ✔️ CPC (Cost per Click) ✔️ PPC keywords ✔️ Content Analysis ✔️ Complete Excel Report Competitor Research Include: ✔️ Full Backlinks Report ✔️ Full Content Analysis ✔️ Domain Authority & Page Authority ✔️ Ranking Kws Benefits of Service:✔️ Pdf + Excel Report ✔️ 24/7 Full-Service✔️ Delivery on Time✔️ Unlimited RevisionsOrder Now!!! Place your order and feel free. Relax while we help you to grow your business. You can ask me anything if you need any help.

by: imzaidasghar
Created: —
Category: Onsite SEO & Research
Viewed: 148


Minimum depth of a leaf in a tree that corresponds to a comparison-based sorting algorithm

The lower bound of comparisons in a comparison-based sorting algorithm is $ \log_2 n!=Θ(n\log n)$ . Yet there can be less comparisons needed in an algorithm. If you take a sorted array, it will take $ n-1 = O(n)$ comparisons (with insertion sort) to sort the array — comparing every adjacent pair of numbers. I don’t understand then how is $ \log_2 n!=Θ(n\log n)$ the lower bound.

I also don’t understand the corresponding trees to the sorting-based algorithms: each leaf in the tree corresponds to one of the permutations of the $ n$ numbers. If the minimum number of comparisons needed is $ \log_2 n!$ then the depth of every leaf should be at least $ \log_2 n!$ , yet I saw that it’s possible for a leaf to be with depth of $ O(n)$ .

Can there be leaves with depth even smaller than $ n-1$ ?

Why have symbolic links between files in folders at same depth?

I noticed that on OS X, the /usr/local/Cellar folder contains binaries installed using Homebrew, and that /usr/local/opt has symbolic links to a bunch of those binaries. I haven’t used symbolic links much, but as I understand it, the purpose of them is to create a link in a convenient location to a file/folder that acts as a copy of that file/folder, without having to move that file/folder from its original location.

So my questions are:

1) Am I correct in my understanding of symbolic links there? ^^

2) If so ^^, why would you create symbolic links in one folder (/usr/local/opt) to binaries in another folder (/usr/local/Cellar) that is at a similar location/depth in the file structure? Under what circumstances would you use these symbolic links where you couldn’t just use the binaries?

Thanks!