Questions tagged [ancestor]

In a graph, ancestor is a node that is connected to all lower-level nodes. The connected lower-level nodes are "descendants" of the ancestor node.

164 questions
35
votes
5 answers

Jquery: get ancestors (or descendants) and self

One can use matchedset.find(selector) / matchedset.parents(selector) to get the descendants/ancestors of the current matched set filtered by a selector, but that doesn't include the matched set itself (if it happens to match the selector too). Is…
gsakkis
  • 1,569
  • 1
  • 15
  • 24
33
votes
6 answers

jQuery select ancestor

Is is possible to use jQuery to select an ancestor of an element? Markup:
jerome
  • 4,809
  • 13
  • 53
  • 70
11
votes
4 answers

Check if there exist a path between two vertices in directed acyclic graph - queries

This question can be easily solved in O(n + m) per query, however is this possible to answer such queries in better complexity with preprocessing better than O(n²) ? In tree it can be easily done by working with pre-order and in-order. I tried…
11
votes
3 answers

Check if 2 tree nodes are related (ancestor/descendant) in O(1) with pre-processing

Check if 2 tree nodes are related (i.e. ancestor-descendant) solve it in O(1) time, with O(N) space (N = # of nodes) pre-processing is allowed That's it. I'll be going to my solution (approach) below. Please stop if you want to think yourself…
Alec
  • 1,486
  • 2
  • 14
  • 30
8
votes
3 answers

MongoDB Tree Model: Get all ancestors, Get all descendants

I have an arbitrary tree structure. Example data structure: root |--node1 | |--node2 | | |--leaf1 | | | |--leaf2 | |--node3 |--leaf3 Each node and leaf has 2 properties: id and name. The important…
Benjamin M
  • 23,599
  • 32
  • 121
  • 201
7
votes
3 answers

Nokogiri equivalent of jQuery closest() method for finding first matching ancestor in tree

jQuery has a lovely if somewhat misnamed method called closest() that walks up the DOM tree looking for a matching element. For example, if I've got this HTML:
Yay
Assuming element is set to…
lambshaanxy
  • 22,552
  • 10
  • 68
  • 92
6
votes
1 answer

Google App Engine Query (not filter) for children of an entity

Are the children of an entity available in a Query? Given: class Factory(db.Model): """ Parent-kind """ name = db.StringProperty() class Product(db.Model): """ Child kind, use Product(parent=factory) to make """ @property def…
Thomas L Holaday
  • 13,614
  • 6
  • 40
  • 51
4
votes
2 answers

How does one find the lowest ancestor with a descendant leaf node with some label?

The problem Given a rooted tree with n nodes, where all leaves are labelled from a set of labels. Build a datastructure which, given a leaf node, a and a label l, can find the lowest ancestor, u, of a, where u has at least one descendant with label…
4
votes
1 answer

jQuery function still fires with the wrong class

I'm trying to create a nav that is optimized for mobile.
Max Kurapov
  • 145
  • 1
  • 8
4
votes
2 answers

Swing AncestorListener: Don't fire for tab switching?

I'm using the following code to let my component register/unregister event listeners when it's added/removed respectively. addAncestorListener(new AncestorListener() { @Override public void ancestorRemoved(AncestorEvent event) { …
Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301
4
votes
3 answers

Is there a way to get notification when JComponent is not visible anymore beucase parent is removed from collection?

Say I have a simple JFrame with a JTabbedPane containing 3 panels, and the second panel contains a JComponent. Is there a way the JComponent to be notified when "Tab 2" panel is removed from its container? My problem is that the JComponent may be…
DejanLekic
  • 18,787
  • 4
  • 46
  • 77
3
votes
1 answer

Finding best common ancestor of two leaf nodes where nodes have zero, one, or two parents

Goal: I am looking for an algorithm to find the best common ancestor of a graph where nodes in the graph can have zero, one, or two parents. I am not sure of the terminology of "best common ancestor": better terminology might be "lowest common…
bgoodr
  • 2,744
  • 1
  • 30
  • 51
3
votes
1 answer

Why does this common ancestor solution have better worst-case performance?

I'm looking at two solutions to find the first common ancestor of two nodes in a binary tree (not necessarily a binary search tree). I've been told the second solution provides a better worst-case run time, but I can't figure out why. Can someone…
AfterWorkGuinness
  • 1,780
  • 4
  • 28
  • 47
3
votes
1 answer

Django migration dependencies reference nonexistent parent node

I have a problem with django migrations. I get this error: django.db.migrations.exceptions.NodeNotFoundError: Migration user.0050_merge_20170523_1254 dependencies reference nonexistent parent node ('user', '0049_auto_20170519_1934') I fix the…
GIA
  • 1,400
  • 2
  • 21
  • 38
3
votes
3 answers

With Git, how can I show the tree of commits that all share a common ancestor?

Suppose I have a 'master' branch, a branch for reviewed & approved changes for my team (call it 'stage'), and a bunch of feature branches all based on the stage branch. (The idea is to group changes into a common pull request from stage into…
Steve Hollasch
  • 2,011
  • 1
  • 20
  • 18
1
2 3
10 11