Are there 1:M Recursive relationships in the StackExchange Database? - data.stackexchange.com

I'm looking for a 1 to many recursive relationship in the Stack Exchange Database. I'm querying it here https://data.stackexchange.com/math/queries. I don't see any 1 to many recursive relationships. The closest I've found is the relationship between posts and the parent of posts (both columns in the Posts table). I suppose that's still a 1:M recursive relationship, but it only goes 1 level deep, because there are no posts that are parents of one post, but children of a different post.
Can anyone point me to a 1 to many recursive relationship in this database?
Thanks,
ET

Related

how can I insert, updatek select, delete datata among three tables and pivote table where many to many ternary relationship exists?

for example We have 5 sales men, 1000 customers, 5 airlines listed. Now, suppose salesman 1 has sold 5 ticket to 2 customer of three airlines, again same customer has bought 15 ticket of five airlines from 3 salesmen. So it is definitely going to be a ternary many to many relationship in pivote sales table. Now How can entry and retrieve those sales from a single form where all data with relationship would be listed in all four respective table in the background? Thank you

master-detail relationship: showing detail as null until drilled

I have 2 graphs with master-detail relationship about company hierarchy. First graph groups number avarages by departments, second one groups by the divisions of the selected department in the first graph. Question: is there any possible way to not show any results in the second graph until master event clicked on the first one?
Not really, since master-detail is one single analysis which also means one data stream.

What is the best way to index many-to-many relationship in mongodb?

I have two entities. User and Item with many to many relationship. I will read/query
items by user id - 50% of time
users by item id - 50% of time
Writing performance dosn't matter.
How should I store those data for best performance?
user:{id:1, items:[1,2,3,4,5]} and index by items
similar for items i.e. item:{id:1, users:[1,2,3,4,5]}
duplicate data and indexes only by id i.e. user:{id:1, items:[1,2,3,4,5]} and item:{id:1, users:[1,2,3,4,5]}
In your case, the relation should be stored similarly to how you would do it in a relational DB. You'll have 3 collections: one for users, one for items, and a relation collection where each document has just one user-item relation.
Thus any query to get the users for an item or vise-versa will require two queries, one to the relation collection and one to the "target" collection. This is definitely one of those situations that a RDBMS does better, but for most people it's a fair trade-off and if you have MongoDB setup correctly the two queries should still be very fast.
I would not recommend duplicating data, aside from the increased storage requirements, in an ideal world it would work but you're likely to end up with consistency issues.

Create binary tree from existing location table with parent_id relationship

I've spent half a day looking into Binary Trees and Binary Search Trees and simply cannot get my head around them, or how it applies to what I have here. All the reading I have looked at is rather confusing in concept, and none give real world examples.
I have inherited a MySQL and PHP system that has a table of geographical locations. This is hierarchical by nature and all records are linked to their immediate parent via a parent_id field.
e.g. New Zealand -> North Island -> Auckland -> Auckland City
This table also has two fields called "lft" and "rgt" which are already populated. My job is to alter this table with more (and changed) geographical locations, and thus, update these lft and rgt values.
I understand that if I look at a child node's lft and rgt values and write a query to the effect of: SELECT * FROM table WHERE lft <= child_left AND rgt > child_rgt, I will get a chain of ancestors.
But I don't understand the logic of this. I don't follow the theory behind assigning these lft and rgt values to a record. They certainly don't appear to have any correlation to the unique id of the records themselves.
Can someone point me to a decent resource with examples? Or have a simple way of explaining BST's?
For future searches:
I found this old article from 2003 that explains it on a basic level very well.
Page 3 also has a PHP function for walking the tree and assigning left and right values to each item using an existing parent as a reference.
http://www.sitepoint.com/hierarchical-data-database/

Appointments scheduling algorithm [duplicate]

This question already has answers here:
Best Fit Scheduling Algorithm
(4 answers)
Closed 9 years ago.
I have the following problem to solve, perhaps you could give me some ideas regarding the problem - solving approach:
There are:
8 classrooms
16 teachers
201 students
149 parents
241 appointments (most of the parents need to see multiple teachers, either because the have more than one child or because one child is being taught by two or more teachers)
2 days.
For each day:
7 classrooms are available for 20 hours per day.
1 classroom is available for 10 hours per day.
Each teacher occupies one classroom
Each appointment lasts for one hour
Further constrains:
- For each parent, all appointments must be sequential (having at maximum 1 hour pause)
- Each parent should have to visit the school one day only.
- For each teacher, all appointments within the day must be sequential (having at maximum 2 hours pause)
- Out of the 16 teachers, 3 can only be present one of the two days.
I'm trying to find an approach to produce the appointments schedule, obviously without having to calculate all possible variations until all the requirements are met. Any ideas?
You need to define your constraints a bit more; i.e., what is the relationship between students and teachers? What is the relationship between students and parents? Do parents have to have individual appointments, or are the parents of a single student allowed to meet with a single teacher together?
I'd approach this with an initial (in testing) naive approach; just pick your highest constrained resource (looks like the teachers that can only be present for one of the two days), schedule those using the first available resources, and then continue through the set of resources, scheduling them using the first available resources that match their constraints and see if you can schedule the entire set. If not, you need to find your limiting resource(s), and apply some heuristics to your matching to find the best way to optimize those limited resources.
It's a bit of a tricky problem; have fun!
Take a look at the curriculum course track of ITC2007 and it's implementation in Drools Planner or unitime. Both of them use meta-heuristics such as tabu search and simulated annealing.

Resources