How to answer multiple queries for a tree?

I encountered an interesting problem based on tree-data-structure.

We are given a tree which has N nodes, with 1≤N≤105.

Time starts from second 1 and it continues for q seconds.

At each second, the value of each internal node is transferred to all of its child nodes. This happens with all the nodes, except leaf nodes.

Sometimes, at a given time p (seconds), we are asked to return the current value of node x.

There is this O(logN) approach: just find the pth ancestor of the given node x, and output its value.

A harder version of the same problem

Sometimes, at a given time p (seconds), we are asked to return the current value of node x, or we are said to update the value of node x to y.

How to solve this problem for q queries (seconds) efficiently, where 1≤q≤105.

Example

Input

N=5, q=8

Edges of the tree:-

4 3 3 1 5 2 1 2 

Values of nodes 1 to 5:-

1 10 4 9 4 

Queries:-

  • 1st second:- Add(1,6). Add the value 6 to node 1.
  • 2nd second:- What is the current value of node 3? (?,3)
  • 3rd second:- Add(3,5)
  • 4th second:- (?,3)
  • 5th second:- Add(2,2)
  • 6th second:- Add(5,10)
  • 7th second:- (?,5)
  • 8th second:- (?,4)

Expected Output

  • 6
  • 0
  • 33
  • 25

Explanation

  • 1st second: 6,1,1,13,14 (Values of all nodes)
  • 2nd second: 0,6,6,14,15
  • 3rd second: 0,0,5,20,21
  • 4th second: 0,0,0,25,21
  • 5th second: 0,2,0,25,21
  • 6th second: 0,0,0,25,33
  • 7th second: 0,0,0,25,33
  • 8th second: 0,0,0,25,33

Combine 3 queries for different lists into one

I am building API for client side apps. There are 3 API requests for 3 different lists as following:

tasksQuery = string.Format(@"<Where><And><Geq><FieldRef Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + FromDate + "</Value></Geq><And><Eq><FieldRef Name='TaskCompleted' /><Value Type='Boolean'>0</Value></Eq><Or><Eq><FieldRef Name='CreatedBy' /><Value Type='Text'>" + LoggedUser + "</Value></Eq><Or><Eq><FieldRef Name='Responsible' /><Value Type='Text'>" + LoggedUser + "</Value></Eq><Or><Eq><FieldRef Name='Accountable' /><Value Type='Text'>" + LoggedUser + "</Value></Eq><Or><Contains><FieldRef Name='Consulted' /><Value Type='Note'>" + LoggedUser + "</Value></Contains><Contains><FieldRef Name='Informed' /><Value Type='Note'>" + LoggedUser + "</Value></Contains></Or></Or></Or></Or></And></And></Where>")  meetingQuery = string.Format(@"<Where><And><Geq><FieldRef Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + FromDate + "</Value></Geq><Or><Eq><FieldRef Name='Organizer' /><Value Type='Text'>" + LoggedUser + "</Value></Eq><Eq><FieldRef Name='Creator' /><Value Type='Text'>" + LoggedUser + "</Value></Eq></Or></And></Where>")  newsQuery = string.Format(@"<Where><Eq><FieldRef Name='Status' /><Value Type='Text'>1</Value></Eq></Where><OrderBy><FieldRef Name='NewsArticleDate' Ascending='False' /></OrderBy>"; 

How can I combine all these queries in one query?

How to prevent LCK_M_IX waiting/locking on the following Delete and Insert queries

Given the following table structure, records are being continuously inserted with the update_time of a very recent datetime. A separate Connection to the DB is periodically trimming old records with dates of older than 2 weeks.

Table Structure:

Table Structure

The following Insert is being run very frequently, with different values:

Insert Statement

The following delete statement is repeated until required, running a select right after to see if the process is complete

delete top(5000) from trade_options with (READPAST) where update_time < '<Two Weeks Ago>' 

Activity Monitor shows that the Delete is locking, and the Insert is waiting ( LCK_M_IX):

Image of the Activity Monitor

Thanks

how to use media queries with javascript in my web parts – classic mode

I have a site that is using the pnp responsive and the webparts are responsive. But i’m using a jquery (easypaginate.js) in the webpart.

When i resize my webpart how can i dynamically change the step option to show only 3 li items when i resize the screen to let say 500px using (media queries) @media (max-width: 500px)

Below is the default setting options

$  ('ul#items').easyPaginate({         step:7,         nextprev:false,         numeric:true     });  } 

I want the step to be 3 when i go on a smaller screen. Thanks in Advance

Failing on queries with length of multiples of 32

tl;dr: Every SQL query of length 64 or higher that is a multiple of 32 results in the connection closing with a 2013 error when interacting with our remote MySQL server.

I am having the strangest issue with our MySQL database. For background, it is running MySQL v5.6 on a remote server hosted by Network Solutions which our IT requires us to use. As such, privileges are really lacking. I can create, read, update, and delete databases, tables, columns, rows, etc., but I can’t do things like restarting the server or defragging. I don’t believe our IT has access to do so either and this is just a Network Solutions thing.

When updating some values, I noticed that some queries were causing a MySQL 2013 error which is

Lost connection to MySQL server during query.

Those queries would continue to fail on retries, and past successes would still succeed. I realized that the common factor was that the failed queries all had a total length of 64, ex.

SELECT code FROM my_database WHERE assignee = 'abcde@gmail.com' 

Also noticed that it will continue to error out if the length is any other multiple of 32, except for 32 itself. The assignee in this instance can theoretically be any length up to 50, so the query can always theoretically be a multiple of 32 no matter how I format it.

I’ve tried with different tables, databases, and clusters and they all have the same issue. Also tried running the queries on a different computer. Strangely, phpMyAdmin does everything just fine.

The only solution I have right now is to check assignee length and change the query accordingly so that it isn’t going to fail but this is a lot of work to put in place for every single SQL statement I have written in our systems.

This might be an issue to bring up with Network Solutions but they have been extremely unhelpful in the past when it comes to technical issues and I don’t even know where to start on telling them how to fix it.

Long running READ queries stuck in “idle in transaction”

I have a JDBC connection pool in a web API that makes frequent requests to the RDS Instance. Each request is for a long running SQL query where PG decides not to use indices because the amount of data to be returned is quite large.

I’m noticing that some of these long running queries are just stuck in state idle in transaction. When look up the pid for these processes in pg_locks table they have 152 rows . With mode AccessShareLock.

The intent for this table is to be never updated — It serves as a point in time table. So I don’t see a need for idle transaction or accesssharelock. Is there I can turn these off so that my queries run faster and aren’t stuck because of AccessShareLock?

CAML queries suddenly quit working; SP Online; SPServices

I have CAML queries performed against SharePoint Online lists through SPServices that have worked beautifully for 5 years. Sometime in the last couple of weeks they started returning incorrect results. The problems all seem to be oriented around the “EndOfLife” text field which always contains a “1” or a “0” (without the quotes).

<Where>   <Eq>     <FieldRef Name='EndOfLife'></FieldRef>     <Value Type='Text'>1</Value>   </Eq> </Where> 

Executed through SPServices in the browser, this query against a particular list returns 10 results. The same query against the same list executed through U2U CAML Query Builder returns over 900 results.

Executed against a different list in another site collection, that query returns 3 results through SPServices in the browser and 2000 results through U2U CAML Query Builder.

There are no changes on my end that correlate with the timing of these problems.

Any idea why these queries executed through SPServices in the browser would suddenly be returning incorrect results?

‘n’ number of CAML queries in a single executeQueryAsync function

How to execute ‘n’ number of CAML queries to get a different list of objects? We can use multiple clientContext.load() if we have a defined number of queries like clientContext.load(collListItem); clientContext.load(collListItem1);

In my scenario, the queries are generated and cannot determine the number of CAML queries needs to be executed. Is this possible?

clientContext.load(collListItem1); clientContext.load(collListItem2); ... ... clientContext.load(collListItemN); 

Data structure & algorithms for super-interval queries on intervals with small integer ends

I would like to have an online data structure that supports inserting an interval, and given a query interval $ I_q=[l_q,h_q]$ answer if $ I_q$ is contained at some interval of the data structure, i.e. if $ I_q$ is a super-interval of some interval of the structure (so the answer of the query is just boolean, no need to output all such intervals on the structure) at the fastest possible time complexity.

I have searched for such a combination, and found out that probably an Interval Tree would be appropriate for my situation, with $ O(\log n)$ interval insertion and overlapping intervals query (so it’s not exactly my desired query, but I think that it could possibly be turned to it. Also I can avoid the output complexity dependence, since the desired output is boolean and therefore on the first match I would know the answer is true).

Furthermore, here (https://en.wikipedia.org/wiki/Interval_tree) it is stated that:

If the endpoints of intervals are within a small integer range (e.g., in the range [1,…,O(n)]), faster data structures exist with preprocessing time O(n) and query time O(1+m) for reporting m intervals containing a given query point.

Since I also can guarantee that both interval ends are going to be small integers (i.e. not floats, but natural integers up to $ \approx 10^6$ ), what would be the best data-structure/algorithmic way (considering time-complexity of the above two operations) to implement those two operations I would like to have?

If the fastest time-complexity would be an Interval Tree, then how can I modify the overlapping-intervals query to support my query in $ O(\log n)$ time, i.e. not $ O(k\cdot\log n)$ where $ k$ is $ I_q$ ‘s range? However, I am quite interested in the above quoted passage, and how I could possibly (with another data structure, maybe?) manage such a fast complexity, so in that case Interval Trees wouldn’t matter.

Note: In my attempt to test such an algorithm and speed on an Interval Tree, I have found out the following library: https://github.com/chaimleib/intervaltree/blob/master/intervaltree/intervaltree.py where a similar query seems to be implemented on the envelop query with a time-complexity of $ O(m+k\cdot\log n)$ , where “$ n$ = size of the tree, $ m$ = number of matches, $ k$ = size of the search range”, which however is not as fast as I would like (especially considering the $ k$ multiplying factor).

Constructing a directed graph for O(1) queries

I need help to design a data structure for a directed graph with the following properties:

  1. Initialization should be done in O(1) time.
  2. AddVertex(id1,id2,…idK) – Add a new vertex to the graph. The new vertex is added with id=N+1 where N is the number of existing vertices. id1…idK are the neighbors of the new vertex, such that there is an outgoing edge from the new added vertex to each of the vertices id1 .. idK. This should be done in O(1) time.
  3. GetNumberOfNeighbors(id) – Return the number of outgoing edges for a vertex with a given id (id is in 1..N). This should be done in O(1) time. All O(1) times are for worse case.

Thanks allot