## Question about numbering of internal nodes in circuit diagrams when one circuit element has more than 1 internal node

I have the following circuit diagram that I’ve added labels for the internal nodes to using outside sources. I understand what an internal node is, however what I’m confused about is– for example– E1 has 2 wires connected to another circuit element, so they’re both internal nodes, but how do I distinguish which is `n1`? Or is this completely arbitrary?

And why is `n2` after E4 here, is it because it has to follow the flow of the circuit?

Sorry for the noob question, my book doesn’t explain this (at least so I’ve read, I could be missing it).

## Super nodes in networking

What are the similarities and differences of super nodes in centralized peer to peer network and hybrid peer to peer network? All I know is super node is for handling data flow and connections for other users.

## Minimum number of nodes to select such that every node is at most k nodes away

I received this problem on an exam a few months ago, and have kept thinking about how to solve it with no luck.

Given a binary tree where each node in the tree can either be selected or unselected, implement a function k_away() which returns the minimum number of nodes that need to be selected so that every node in the tree is at most k nodes away from a selected node.

So, the nodes simply contain a pointer to the left child, a pointer to the right child, and a boolean marking it as selected or not:

``struct Node {     Node *left;     Node *right;     bool selected = false; // starts out false }; ``

The problem specifies a constraint of having a time complexity of O(n) and an auxiliary space complexity of O(n).

What I’ve thought of so far:

• It seems like there are 2^n potential solutions (if I can choose to either select or not select every node and there are 2 of them), so brute force is a bad idea
• I’ve searched around for similar problems and the closest thing I can find is the Dominating Set problem which seems… impossible to solve at this moment in polynomial time. I doubt this problem was given as an impossible problem.
• Running DFS to get to the leaf nodes, then counting height as recursion unrolls. Every k away, marking the node as selected. This seems to work on small test cases, but does not return the minimum number away.
• Running BFS on the root node to find all nodes k away while using another data structure to mark all visited nodes as ‘covered’, and then recursively running the BFS on each k-away node. This also seems to work on small test cases, but again doesn’t return the minimum number away.

## CLRS 22.3-1, How Come Solutions Online State There Can’t Be Edges From WHITE to GRAY nodes “at any point… during search”?

The exercise (from the book Introduction To Algorithms) states

Make a 3-by-3 chart with row and column labels WHITE, GRAY,and BLACK. In each cell (i, j) indicate whether, at any point during a depth-first search of a di- rected graph, there can be an edge from a vertex of color i to a vertex of color j . For each possible edge, indicate what edge types it can be. Make a second such chart for depth-first search of an undirected graph.

The colors WHITE, GRAY, BLACK correspond to Undiscovered, discovered but not finished, and finished. The following solution is what multiple sites & universities have posted(such as: walkccc, Rutgers University):

`` |       | WHITE         | GRAY                | BLACK                | |-------|---------------|---------------------|----------------------| | WHITE | All kinds     | Cross, Back         | Cross                | | GRAY  | Tree, Forward | Tree, Forward, Back | Tree, Forward, Cross | | BLACK | -             | Back                | All kinds            | ``

I will draw a minimal counter example as it helps understand my conflict:

• Start at node 0: 0 is GRAY
• PAUSE
• At this point, 3 is still white and has an edge to 0
• Resume and keep going, eventually the edge from 3 to 0 will be discovered as a tree edge

This contradicts the solutions saying you can only have Cross/Back edges going form WHITE->GRAY. This example can be easily modified to contradict many of the elements in the table. I think the solutions are doing one of the following:

• Assuming that the graph is a tree and that we start at its root. (Wrong as DFS doesn’t need a tree graph and any node can be started from).
• More likely (Just thought of this), interpreting the question of "can there be an edge" as "can there be an edge that we have discovered". In which case, the solutions work, as although the edge from 3->0 was a WHITE->GRAY edge at one point, we hadn’t discovered it yet.

## finding the combinatorial solutions of series and parallel nodes

I have n nodes, and I want to find the (non duplicate) number of possible ways in which these nodes can be combined in series and parallel, and also enumerate all the solutions. For example, for n=3, there are 19 possible combinations.

`` 0 (0, 1, 2)  1 (0, 2, 1)  2 (1, 2, 0)  3 (1, 0, 2)  4 (2, 0, 1)  5 (2, 1, 0)  6 [0, 1, 2]  7 [0, (1, 2)]  8 [0, (2, 1)]  9 (0, [1, 2]) 10 ([1, 2], 0) 11 [1, (0, 2)] 12 [1, (2, 0)] 13 (1, [0, 2]) 14 ([0, 2], 1) 15 [2, (0, 1)] 16 [2, (1, 0)] 17 (2, [0, 1]) 18 ([0, 1], 2) ``

In the notation above, a series combination is denoted by (..) and a parallel combination is denoted by [..]. Duplicates are removed, for example [0,1,2] is the same as [1,2,0] since all of them are happening in parallel so the order does not matter here.

Can you give me an algorithm for this, or if any such algorithm already exists, then point me to it?

(I tried googling for a solution, but did not hit any relevant answer, maybe I was entering the wrong keywords.)

Note: for a sequential-only solution, the answer is easy, it is n!, and the enumeration of the solutions is also easy. But when parallelism (especially non duplicates) is added to the problem, it gets very complex.

## Time taken by virus to reach all nodes

Given a connected graph, with weighted edges, a virus starts from a given node. It takes x seconds for the virus to travel from a node to one of its neighbours where x is directly proportional to the weight of the edge.

If you are allowed to remove one edge from this graph in order to maximize the ammount of time it takes for the virus to infect all the nodes. How to find this edge?

I could come up with an O($$n^2$$) solution to remove every edge one by one and then run BFS to find out the time it takes for the virus to infect every node. Is there a better solution in terms of time complexity?

## How is it possible for nodes at height \$h\$ in Tree \$T\$ to be at height \$h-1\$ at T’

I was searching for answers to the Question:

Show that there are at most $$\lceil n / 2^{h + 1} \rceil$$ nodes of height $$h$$ in any $$n$$-element heap.

Recently I asked a related question and found out the solution was flawed so I looked for another one.

So I took over to another answer and found this

It took over to prove by induction and it is quite understood on the first read except for the statement:

Note that the nodes at height $$h$$ in $$T$$ would be at height $$h − 1$$ in tree $$T’$$.

Preface:

Let $$N_h$$ be the number of nodes at height $$h$$ in the n-node tree $$T$$. Consider the tree $$T’$$ formed by removing the leaves of $$T$$.

## Find the probability of occurrence of each edge in a graph having \$n\$ nodes after \$k\$ operations

Given a graph with $$n$$ nodes . The adjacency matrix of the graph is given. We do $$k$$ operations on this graph. In each operation we choose two distinct nodes $$i$$ and $$j$$ (there are $$(n*(n-1))/2$$ such choices) equiprobably (all choices are equiprobable) and if there exists a edge between $$i$$ and $$j$$ we delete that edge or else we draw an edge between the chosen pair of nodes.
We have to output a $$n*n$$ matrix where the element at $$(i,j)th$$ position denotes the probability of occurrence of edge connecting the nodes $$i$$ and $$j$$ in the final resulting graph.
The constraints on n and k are $$n<=50$$ and $$k<=50$$ .
I tried it using dynamic programming but could figure out transitions properly.

## No of ways of selecting k non adjacent nodes in a graph for all k

Suppose there is an undirected connected graph with n<=38 nodes without multiple edges and self loops . We have to find the no. Of ways to select k nodes such that no two of them are adjacent for all possible k efficiently

## Directed Grid Graphs; All Possible Paths Through Nodes

I have a problem in which I am interested in taking a matrix of positive integer weights, including zero, where the matrix has dimensions nrow x ncol and the columns always sum to the same arbitrary number. I want to search for a list of paths (sets of edges essentially) that traverse through the grid space of the same dimension & create the paths such that the # of edges in a path going through a node is equal to the nodes weight (from the matrix). Ie: if a particular index in my matrix was "3", there would be 3 edges that would run into (and out of) this node.

Some important restrictions. Firstly, The only direction the edges can move is rightward (so vertical edges are disallowed) but only one column distance at a time. I do allow for the edges to go from any row_j (in column_i) to any other possible row_j in column_i+1, so diagonal edges (either upwards or downwards are allowed). Here’s an example of such a solution (it is non singular which is why Im interested in ALL possible paths)

Most importantly, I am interested in two things. First I want all possible paths from this process, and even more critically, I want to minimise the number of possible diagonal edges that my resulting paths will contain.

Any sort of algorithm here to solve this would be hugely helpful.

I have managed to solve the case when I don’t care about the number of diagonal edges, and just want a set of paths that match with the weights. To do that, I used the weights at adjacent columns to generate a Markov transition process. This gave me a series of transition matrices (of length ncol-1) which from there I was able to construct probabilistically what my paths through my weights were.

Let me know if anyone needs any more details/explanations here.