The approach is absolutely correct. However, there is an error in the calculation. Sum of first n terms is n(n+1)/2 :).
Sorry didnt get the time to explain the example suggested. Here it follows:
First push 8 pop 8, push 4 pop 4, push 2 pop 2, push1.
After that push 8 pop 8, push 4 pop 4, push 2.
Again push 8 pop 8, push 4.
Finally push 8.
So, at each step we can see that a pattern is followed and if we relate it with n, then we get 2n-1, 2(n-1)-1, 2(n-2)-1 .... 2(1)-1 respectively. So, adding all these terms, we get
2(n + n-1 + n-2 +......+ 1) - n = 2(n(n+1)/2) - n = n2 + n - n = n2.
The maximum possible number of iterations will be n2 which occurs when the numbers are stored in increasing order in Q. It can be proved by taking an example. Take the initial Q as 8,4,2,1. Now execute the given code.
This program will output 8. The logic is:
first the expression within () is solved. There are three expressions within () separated by comma. The first expression will result in making a value as 4, the second expression is constant 5 and the third expression is a whose value is now 4.
Now the twist is comma is treated as operator in C, which has left associativity, so the () will return last expression i.e. a with value 4. So, the final expression will be a+=a which results in a value as 8.
Whether the empty relation is reflexive or not depends on the set on which you are defining this relation -- you can define the empty relation on any set A.
The statement "S is reflexive" says: for each x∈A, we have (x,x)∈S. This is vacuously true if A=∅(empty set), and it is false if A is nonempty.
The statement "S is symmetric" says: if (x,y)∈S then (y,x)∈S. This is vacuously true, since (x,y)∉S for all x,y∈A.
The statement "S is transitive" says: if (x,y)∈S and (y,z)∈S then (x,z)∈S. Similarly to the above, this is vacuously true.
To summarize, S is an equivalence relation if and only if it is defined on the empty set. It fails to be reflexive if it is defined on a nonempty set.
The short-term scheduler (also known as the CPU scheduler) decides which of the ready, in-memory processes are to be executed (allocated a CPU) next following a clock interrupt, an IO interrupt, an operating system call or another form of signal. In practice, the short-term scheduler is invoked whenever an event (internal or external) causes the global state of the system to change. Given that any such change could result in making the runninng process suspended or in making one or more suspended processes ready, the short-term scheduler should be run to determine whether such significant changes have indeed occured and, if so, to select the next process to be run. All of the above mentioned events can cause rescheduling by virtue of their ability to change the global system state, hence OS invokes short-term scheduler in these cases.
The question is asking for minimum no. of colors that is sufficient to vertex-color any planar graph, i.e. a planar graph with any no. of vertices. However, in some cases, 3 colors are not suffcient to vertex-color a planar graph. But is has been proved that 4 colors are sufficient to vertex-color every planar graph. It is called as the four color theorem. You can have look at the below page:
your logic for placing digits in forth place is wrong. If you placed 7 in first position then you have 2 choices for forth place(0, 5). But if you placed 5 in first position then u dont have 2 choices for forth place, you can only place 0 there.
Okay now i got the question, it is given that Y is the inorder-successor of X, which can only be possible if either of the following condition exists:
1). Y is right child of X.
2). Y is parent of X and X does not have right child.
Here condition 1 is in violation of the question, so condition 2 must hold. According to condition 2, X does not have right child is satisfied by the question, so the only thing that is remaining is Y is parent of X. Hence option B is correct.