Performing crossover on trees in genetic algorithm

I’m using genetic algorithm for solving a problem. Each chromosome is a B* tree (where each node has only 2 child nodes).

I’m wondering how to perform the crossover. I found an example which says that crossover points are fixed in parents, at which the tree is sliced, and the child is constructed from sliced sub-trees.

But I know I need to consider more things. Like, what if the child tree is not balanced? Or, what if the child contains duplicate items?

Any advice how I should proceed with these questions in mind? Thanks in advance.

How Segment trees are used to answer interval stabbing query?

I’m new here and to Algorithms in general. I have a question that bugs and I have searched google without any fruitful results sadly.

Can anybody explain to me how segment trees are used to answer interval stabbing queries? I have searched and searched and only come with the beginning of the line. From my understanding I need to take all the end points of every interval and build a segment tree then what?

How can we know the original intervals now? How can we check whether a given point is present in any of them and report all those intervals with the point in them.

Many thanks in advance!

In the right-rotation case for red-black trees, there is a less efficient way to recolor it, why is it not O(log(n)) anymore?

So the first time I tried to recolor this insertion case from memory, I ended up with the right-hand side recoloring; of course the left recoloring is more efficient as the loop ends at this point. If however, we check in the right case for whether the grandparent of a is the root (color it black) and otherwise continue the loop from that node, I read that it makes the recoloring not O(log(n)) anymore, why is that? It still seems to me to be O(log(2n)) at worst, even if the number of rotations performed is not O(1) anymore. red-black recoloring alternatives

Number of Spanning Trees

We are given a graph G with N(numbered 1 to N) nodes and M edges.

Let’s create a big graph B with NK nodes (numbered 1 through NK) and MK edges. B consists of K copies of G ― formally, for each k (0≤k≤K−1) and each edge between nodes u and v in G, there is an edge between nodes u+kN and v+kN in B.

We take the complement of the graph B and name it H.

The task is to calculate the number of spanning trees in H.

Note : The maximum number of nodes in graph G is 20. The maximum value of K is 10^8. The graph G doesn’t have any self-loops or multiple-edges.

My approach : When the value of K is less than 40, I am being able to apply Kirchoff’s Matrix Tree theorem with a complexity of O(N^3)(Gaussian elimination gives us a O(n^3) algorithm to compute determinants). However,my solution doesn’t scale for very large graphs which are formed for high values of K. I am figuring I should be able to derive a formula to calculate the number of spanning trees because of the repeated copies of small graph G. But because of my limited mathematical knowledge, I am not being able to converge to a formula.

Any help would be greatly appreciated.

Number of distinct BFS, DFS trees in a complete graph

What is the number of distinct BFS, DFS in a complete graph?


My approach is like this–>

For DFS take a node, we have (n-1) possible tree edges, next we have all possible (n-2) tree edges,…….finally 1 possible tree edge. and we can choos any of n nodes as rooot node. hence no of distinct DFS trees= n*(n-1)(n-2)….1= n!

For BFS tree if we take a node as root, we have to explore all its neighbors , so the number distinct of BFS trees =no of nodes we can choose as root ie. n .

Is this approach correct?

Number of compatible trees with an ancestry matrix

Suppose you are given an ancestry matrix $ M$ which means that $ M[ij] = 1$ iff node $ i$ is an ancestor of node $ j$ . If $ M$ represents no cycles (treated as an adjacency matrix) the corresponding graph is a tree (or a forest). My question is what is the number of trees where their ancestry matrix is $ M$ .

Is this question any simpler than counting number of directed graphs which are compatible to a general ancestry matrix?

Directed Trees: Finding all the edges and vertices in a specific direction

I am an electrical engineer without experience in graph theory. However, I have a problem which I believe can be solved by graph theory. We have a directed tree, such as the one below. We want to find all the vertices and edges starting from a vertex in a given direction. For instance, in the figure below, we want to identify the vertices and edges downward from vertex 1 (the red lines). Is there an algorithm to do this (preferably in MATLAB)? The edges have equal weight.

enter image description here

Can an optimal global classification tree be constructed from trees for single categories?

Suppose we have a set of objects, each belonging to one of the disjoint categories $ c_1, … , c_n$ . Suppose further that for every single category $ c_i$ there is a corresponding set $ T_i$ that contains all optimal binary classification trees that only split the objects based on whether they belong to $ c_i$ or not. Optimal is defined as having the least sum of distances from the root to the leaf nodes.

Question: Can the sets $ T_1, …, T_n$ be used effectively to construct a single global binary classification tree that classifies objects for every category and is also optimal?