
Fine. You're not wrong, but you didn't have to be an ass about it. But that's nothing new for you.





Not sure how I am being an ass.
You brought up shallow copy which was not in any way relevant. I can only respond to what you posted.
Best I could guess was that you were using a different definition of shallow copy than I was. So I defined the term.





Richard Andrew x64 wrote: so that would lead to exceptions caused by changing the list out from under them.
That cannot happen.
Per your original description the worker threads do not modify it.
The management thread creates a new list. The worker threads never use that list until it is done and the management thread is done with it.
Richard Andrew x64 wrote: seeing the new version of the list while other threads are still working with data from the old version of the list.
I think that requirement is going to end up requiring additional locking.
Say you look up prices in a list. Then an execution flow looks like this
Worker1: Gets price X (v1) from list. Continues work
Management: rebuild list (simple lock)
Worker2: Starts (simple lock gone) and gets price X (v2) from list.
Worker1: Finishes work with v1
Worker2: Finishes work with v2





jschell wrote: That cannot happen. Not even if the worker thread is in the middle of enumerating the list?
The difficult we do right away...
...the impossible takes slightly longer.





Richard Andrew x64 wrote: enumerating the list?
Correct.
The Management thread creates a new list. Completely new. It does not modify nor touch the old list in any way.
The worker threads, are using the old list. Because they copied the pointer, the old list is the only one that they can use. The old list is not modified.
The pointer copy is the key to this behavior.





Yes, you're right, by George.
So that implies that the reference assignment itself is atomic?
The difficult we do right away...
...the impossible takes slightly longer.





Richard Andrew x64 wrote: So that implies that the reference assignment itself is atomic?
Yes that must be the case.
For java and C# it is.
Best I can tell in C++ the answer is sort of. Apparently it depends on the execution environment. But there is std:atomic.
I wondered, when this thread started, if it was possible to have a language that supports threads where assignment was not atomic. (C++ the language does not support threads.)





Without knowing frequencies, the size of the "work unit", the implications of returning a "busy" signal versus "locking", it's hard to make a thoughtful recommendation.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation."  Napoleon I





Appreciate you chiming in anyway. The Slim Reader/Writer lock provides for that by offering methods that acquire locks with timeout values.
The difficult we do right away...
...the impossible takes slightly longer.





So far, I see no evidence that the list has to be "protected" at all. If it's "updates"; they should be atomic. If it's inserts, the caller picks it up in the next "list query". If you're not using lists as lists, maybe you should be using a concurrent dictionary. If you don't like dictionaries, wrap it to make it look like a list (keys, values or key value pairs).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation."  Napoleon I





T(n)=c if n=1
=2T(n1)+d if n>1
Find the value of T(n) and thus the time complexity.
My attempt at it got stuck.
T(n)=4T(n2)+3d
T(n)=8T(n3)+7d
..
..
..
T(n)=8T(nk)+7d
It can't be solved further.





Quote: It can't be solved further
This does not help us in any way or format, why can it not be solved further, did it freeze, were there an error etc. etc.





Start writing things out more fully then look for the pattern in terms of n .
T(1) = c
T(2) = 2T(1) + d
T(2) = 2c + d  take this

T(3) = 2T(2) + d 

____________ and put it here

/\
T(3) = 2(2c + d) + d
T(3) = 4c + 2d + d
T(3) = 4c + 3d
T(4) = 2T(3) + d
T(4) = 2(4c + 3d) + d
T(4) = 8c + 6d + d
T(4) = 8c + 7d
T(5) = 2T(4) + d
T(5) = 2(8c + 7d) + d
T(5) = 16c + 14d + d
T(5) = 16c + 15d
"the debugger doesn't tell me anything because this code compiles just fine"  random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers."  chriselst
"I don't drink any more... then again, I don't drink any less."  Mike Mullikins uncle





Googling suggests that time complexity requires 'code'. So as a starting point doesn't one need to write the recursive function first?





A colleague has asked for assistance with the problem stated below. I have searched and tried to create a solution without success. Another colleague suggested I post on this forum. The preferred approach would be in msAccess/vba, but any advice appreciated.
The problem:
Given a set of N participants, divide the participants into teams of m members. There are a number of Activities that take place in Sessions. Assign Teams to each session*activity such that no participant/member is assigned more than once in session, and no participant/member is in same activity more than once. Each team can only participate in 1 activity.
For testing suppose there a 4 activities that occur in 4 sessions, and 8 participants in teams of 2.Is there an algorithmic solution for 4x4 and 2. The underlying question isis there a scalable solution beyond 4x4 and 2?
Manually, with 8 participants A,B,C,D,E,F,G,H  there is a solution
......... Activities
......... 1 2 3 4
Session 1 AECFDGBH
Session 2 CGAHBEDF
Session 3 DHBGAFCE
Session 4 BFDECHAG
modified 3Nov23 11:34am.





Reminds of some companies: send you on courses you don't need to fulfill the "educational quota". May as well be talking colored marbles.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation."  Napoleon I





So, you want us to do your homework for you; sorry, that's not what this site is for. And looking at your profile you have been a member long enough to know that.





I'm not asking for you or anyone to do homework. My interest is really whether this is a problem that fits a "family of problem types with an algorithmic solution". I have seen picking marbles etc and how many ways can you do X, but I found this particular problem more complex. Any advice as to how to approach the problem would be helpful.
I do recognize there are 16 teams (4x4) in a solution and that with 8 participants, there are 28 unique teams. But it's not just selecting 16 out of 28.





You have all the information you need in the question. It even provides you with sample data to work out first (4x4 and 2). S otry to draw some diagrams to see how you can fit the respective teams into the different activitie, and if there is a common thread to get to the answer.





Hello!
I need to implement an algorithm to create roundrobin tournament schedules, but with the constraint that up to 2 teams – that may play in different leagues – might share the same field on the same time slot of the week, so they must be never be scheduled to play at their home field in the same round of their league schedule.
Simple example:
leagueA = [
TeamA(plays at FieldA on Sunday),
TeamB(plays at FieldB on Sunday),
TeamC(plays at FieldA on Saturday),
TeamD(plays at FieldD on Saturday)
]
leagueB = [
TeamE(plays at FieldA on Sunday),
TeamF(plays at FieldF on Sunday),
TeamG(plays at FieldG on Saturday),
TeamH(plays at FieldF on Saturday)
]
I was thinking of generating the schedule for leagueA with the circle algorithm alternating home and away at each round as described in the linked article, and then to approach the scheduling for leagueB by prefilling the slots for the teams that share the field with teams in the other league somehow, but I'm not sure whether it's the right approach and how to actually implement it in a way that is guaranteed to produce schedules do not produce conflicts.
Any help would be highly appreciated!





Sounds like a "static" schedule; which you imply by ignoring winners and losers; so any feasible schedule you generate, first time out, will do. (And "schedules" doesn't come into it).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation."  Napoleon I





Recently, I joined a programming competition and stumble across a question that i consider difficult to answer because I cant even fully understand the problems given, to me this is the hardest question in the competition.
The problem goes like this :
You are given an integer k>0 and a series of k+2 numbers n[1], n[2], …, n[k+2]. You are told
that the numbers in the series are calculated using an equation of the following form for n>0:
n[x] = ((x + a[1]) * (x + a[2]) * (x + a[3]) ... (x + a[k])) / d
You do not know the value of d. You do not know the values for a[1] ... a[k]. You only know
that each (a[i] ≥ 0) and (d > 0) and you can assume that the product in the numerator is evenly
divisible by the integer value d. You can assume that the numerator can be represented by a
32bit integer. But you know that the formula for n[x] is a polynomial function of degree k and
you know the value of k+2 points for this function. Based on this information, you actually have
enough information to calculate the next number n[k+3] in the sequence! This is your task.
Input
The first line will contain a single positive integer by itself that represents the value k. The
second line will consist of (k+2) integer values separated from each other by a single space.
The values on the second line represent the series n[1] through n[k+2].
The input must be read from standard input.
Output
The output of program should display a single integer on a line by itself representing the value
for n[k+3].
The output must be written to standard output.
Sample Input #1
First Line : 1
Second Line : 3 4 5
Output : 6
Sample Input #2
First Line : 2
Second Line : 1 3 6 10
Output : 15
I dont even understand why this problem is solvable when there is an unknown variable(d) and another function in the sequence(a[x]) and how to get the value of n(k+3)





It's Algebra and Dynamic Programming; converging on a number. (I go blank after x number of words; so it's just a thought).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation."  Napoleon I





There is a bit of extra information in the problem. Maybe they didn't count well the number of equations and unknowns. You have k+1 unknowns (a[1],...a[k] and d) and k+2 equations. We can take only the first k+1 equations and leave the last one for verification. Here is the math:
We can write n[x] as a polynomial with unknown coefficients c[1] to c[k]:
n[x]=x^k + c[1]*x^(k1)+c[2]*x^(k2)...+c[k] We know the values of this polynomial in each of the points 1, 2,...k+1 so we can write the following system of k+1 equations:
1^k + 1^(k1)*c[1]+...+c[k] = n[1]*d
2^k + 2^(k1)*c[1]+...+c[k] = n[2]*d
....
k^k + k^(k1)*c[1]+...+c[k] = n[k]*d
(k+1)^k + (k+1)^(k1)*c[1]+...+c[k] = n[k+1]*d Reordering terms, this gives:
n[1]*d + 1^(k1)*c[1]+...+c[k] = 1^k
n[2]*d + 2^(k1)*c[1]+...+c[k] = 2^k
....
n[k]*d + k^(k1)*c[1]+...+c[k] = k^k
n[k+1]*d + (k+1)^(k1)*c[1]+...+c[k] = (k+1)^k
This is a system of k+1 equations with k+1 unknown that can be solved:
 d 
c[1]
...  = M^1 * V
c[k] where M is the coefficients matrix:
n[1] 1^(k1) ... 1
n[2] 2^(k1) ... 1
...
n[k+1] (k+1)^(k1)...1 and V is the free terms vector:
1^k
2^k
...
(k+1)^k After you've calculated the coefficients finding the value of the polynomial is trivial.
Here is a numerical example for the case k=2
1 1 1  1
M= 4 2 1  V= 4
6 3 1  9 after calculating the inverse of M, the end result is d=2 c[1] = 1 c[2] = 0 and the polynomial is n[x] = x^2+ 1*x + 0. n[4]/2 = (16+4)/2 = 10 (matching the extra equation given) and n[5]/2 = (25+5)=15 matching the suggested answer.
Mircea





Why can we rewrite the original equation into this?
n[x]=x^k + c[1]*x^(k1)+c[2]*x^(k2)...+c[k]
Where does 'd' goes, Why does x^k until x^(kk) and why replace a(x) with c(x). Sorry for the inconveniences, I just dont understand.



