sql server – Cannot run query to get deadlock graph in a timely fashion

I am trying to get deadlock information from a sql-server by using this query

select XEventData.XEvent.value('(data/value)(1)', 'varchar(max)') as DeadlockGraph
(select CAST(target_data as xml) as TargetData
from sys.dm_xe_session_targets st
join sys.dm_xe_sessions s on s.address = st.event_session_address
where name = 'system_health') AS Data
CROSS APPLY TargetData.nodes ('//RingBufferTarget/event') AS XEventData (XEvent)
where XEventData.XEvent.value('@name', 'varchar(4000)') = 'xml_deadlock_report'

The query however takes forever and returns an empty result.

Why does it take that long time and is the deadlock information you get from this views retroactive so I will be able to pinpoint a deadlock that occured some time ago?

algorithm – Puzzled by this interview problem: schedule a computation graph on a single-processor under a memory constraint

I recently went through a interview session for a SWE/CS role at a well known company.
It wasn’t specifically a “coding-round” but was titled a “domain interview” session, so I assumed the interviewer was interested in an discussion/high-level-solution related to the problem.

The problem:

You’re given a computation graph with nodes representing computations, edges representing dependence, and the values on edges representing the data-size in MB (input or output) at that edge.
You want to schedule this graph on a single-processor with limited memory X MB.
To execute a node/computation, both inputs and outputs data should fit within X memory of the processor.
It’s given for for each node sum of its inputs/outputs data <= X.
If at any time the data the total data that needs to be stored execeeds X, then there is extra cost per MB of fetching data from the disk. (it can happen with node n1 has produced an output that needs to be used by n2 but not all predecessors of n2 have run yet).
How would you schedule this graph?

My approach/What I discussed:

  • I answered by saying that “in general” this problem is intractable(NP-complete) for multi-processor systems, and likely too for single-processor system due to the memory constraint.
  • Then I suggested a greedy approach based on keeping track of all ‘ready’ nodes at a given time that can be executed as their predecessors have been executed.
  • Which specific node to schedule next from several available/ready
    ones can be done based on trying to minimize the cost associated with
    memory constraint (i.e. seeking to schedule the one with the min cost
    associated with data transfer).
  • If there are several nodes with same minimum cost associated with
    data transfer, the pick the node among them with the biggest
    input+output mem requirement.

During the session, the interviewer didn’t suggest many things or gave any tips or direction on which directions he may have wanted me to lead to, so it turned out to be very open-ended.

He was almost neutral or very slight camera/tight-lipped smile taking notes most of the time.

I couldn’t gauge exactly what interviewer may have been looking for due to the intractableness of the problem — it’s hard to come up with a general optimal algo for such at the top of your head.

Later I came to know I received a ‘no’ decision for this session.


This has me puzzled. I’ve been racking my brain on if I didn’t approach it correctly, or if the interviewer was expecting one to talk about something else that the things I mentioned.

Is there something optimal or direct I missed?

Could there be some specific algo that interviewer may have been looking for that generally one is expected to know?

During the session, I thought I was providing a reasonable solution given the constraints of the problem, and could have deep-dived into any direction that interviewer may have asked me to.

But didn’t get any push-back or suggestions from the interviewer during the session, i’m interested to know what i missed or how I should have approached this problem.

graph theory – Centrality measures in a network with negative correlations

I have a bidirectional network where the weights of edges are based on partial correlation matrix. I have both positive and negative values as weights. Now, I want to compute centrality measures as degree, closeness, betweenness and eigenvector. How can I handle the negative values? Would I get correct values for these measures, if I keep the negatives? Should I use absolute value or take (1-absolute value)?

Basically, I am confused about if these values would affect the outcome in any way. I have not found any resources that would discuss this. Please recommend, if you know any.

postgresql – How to turn a complicated graph into Json Graph Format?

So having such normalized Postgres 13/14 graph of item joins:

  item_id     serial PRIMARY KEY,
  title text
  id          serial PRIMARY KEY,
  item_id     int,
  child_id    int
INSERT INTO items (item_id,title) VALUES
  (2,'LEVEL 2'),
  (3,'LEVEL 3.1'),
  (4,'LEVEL 4.1'),
  (5,'LEVEL 4.2'),
  (6,'LEVEL 3.2');
INSERT INTO joins (item_id, child_id) VALUES

How to turn it into a JSON Graph Format document containing item columns as fields?

list manipulation – Efficient way to get all $k$-factors of a graph $G$?

In Graph factorization, a $k$-factor of a graph $G$ is a spanning $k$-regular subgraph which has the same vertex set as $G$. Now I have a random graph $g$ (i.e. complete graph for simplicity) and I want to obtain all the $k$-factors in a list.

My strategy is

  1. get the edges and vertex of $G$: getpairs and getvetex
  2. create all the subsets of getpairs: allsublist, which is equivalent to create all the possible subgraphs.
    • check whether each elements (i.e. number) in every subset is repeated $k$ times (i.e. terms), which corresponds to check every subgraph is
      $k$-regular graph.
    • check each terms have the same vertex set getvetex of $G$
  3. store the correct subsets (i.e. $k$-factors) in selectlists.
  4. repeat steps 3-4 (namely the for-loop)

Here is the code for the above task:

n = 5;
g= CompleteGraph(n);
getpairs = EdgeList(g) /. UndirectedEdge -> List;
getvetex = VertexList(g);

selectlists = {};
kregular = 2;
allsublist = Subsets(getpairs);
For(ii = 1, ii <= Length(allsublist), ii++,
   terms = Cases(Tally@Flatten@allsublist((ii)), {x_, kregular} :> x);
   If(terms!={} && terms==DeleteDuplicates@Flatten@allsublist((ii)) && SameQ(SortBy(terms,Greater),getvetex),
    AppendTo(selectlists, allsublist((ii))););

For-Loop is quite inefficient and create all Subsets will also take long time when there are many edges in the graph with large n.

Let’s say n currently is small n<=6, can one get rid of the for-loop? Are there simple ways to do it? Thank you very much in advance!

graph theory – Tour expansion with min-cost flow


has the problem of formulating optimal tour-expansion for Symmetric TSP’s already been mentioned as a means for faster tour-expansion in the sense of potentially intergrating more than one city in each iteration and doing that in an optimal way, i.e. getting “the most” out of each iteration?

Motivation for the question is that I may have found such formulation but can’t remember having seen anything in that respect.

graph theory – Prove or disprove: $p$ is the shortest path from $sin V$ to $tin V$ with $w’=w_{1}+w_{2}$

I saw the following statement:

Let $G=(V,E)$ be a graph and two $w_{1},w_{2},:,Etomathbb{R}$ weight functions so there are no negative cycles in graph. Let $p$ be the shortest path from $sin V$ to $tin V$ with $w_1$ and $w_2$. Prove or disprove: $p$ is the shortest path from $sin V$ to $tin V$ with $w’=w_{1}+w_{2}$.

I could not disprove it and I believe this statement it true. But I could not prove it formally. How do I translate “$p$ be the shortest path from $sin V$ to $tin V$ with $w_1$ and $w_2$” into math?

For any direct graph $G(V,E)$, there is always an iteration of DFS algorithm on $G$ so the result does not have any cross trees

Consider the following graph:

enter image description here

A possible DFS starting from $a$ visits the vertices in this order: $langle a, b, c, d rangle$ producing the cross-edge $(c,b)$.

A possible DFS starting from $b$ visits the vertices in this order: $langle b, a, c, d rangle$ producing the cross-edge $(d,c)$.

A possible DFS starting from $c$ visits the vertices in this order: $langle c, a, b, d rangle$ producing the cross-edge $(d,b)$.

A possible DFS starting from $d$ visits the vertices in this order: $langle d, a, b, c rangle$ producing the cross-edge $(c,b)$.

Google Sheets: Line Graph of alternating columns. 1st Column as label

Month Notes January Notes February
Net Worth $500 $600
Liabilities $50 $40
Credit Cards $10 $20
Credit Card 1 $5 $10
Credit Cards 2 $5 $10
Savings & Checking $400 $500
Investments $100 $200

I have a google spreadsheet I use for tracking monthly financials that looks something like this. I use a new tab or sheet per year.
I was looking to add a Dashboard to the first tab that would display an individual line for each row.

Essentially I want the row and column labels to be the same I have here but translate the numerical values into a line graph.

I have attempted to select all of the cells with the respective data manually. I have tried selecting the ranges – but with my notes columns and there are detailed rows underneath each of the rows displayed here i.e. credit cards have a row each for each card, etc. So the rows and columns in the sheet are not exactly contiguous. I’m pretty sure I’ll have to manually click each item. I have also tried selecting a row with the column intended become that row’s label and the numeric values in that row as the plotted lines – but that doesn’t seem to work very well either. Especially if I try to add more than one row. to display multiple lines.

Find the DFS solution for the following graph if the starting point is vertex 3 and traces all vertice

Find the DFS solutionif the starting point is vertex 3 and traces all vertices
Find the DFS solution for the following graph if the starting point is vertex 3 and traces all vertice