Question: Calculate denotational semantics for the following nondeterministic programs. a . Let S - = if x > y x : = x - 1 x

Calculate denotational semantics for the following nondeterministic programs.
a. Let S-= if x>yx:=x-1x>yy:=y+1x+y=4x:=yxx+y=4x:=
xy fi, and let ={x=3,y=1}. Calculate M(S,) and show your work.
b. Let W-= do x>yx:=x-1x>yy:=y+1x+y=4x:=yxx+y=4x:=
xy od, and let ={x=3,y=1}. Calculate M(W,) and show your work.
Let b be an array of size n1, and bbb[n]=100nb0'sJ-=dob[k0]=1k0:=k0+1b[k1]=0k1:=k1+1odk0k1Jk0k1b[k0]=0b[k1]=1JM(S,)S|=={p}S{q}|==p|=={p}S{q}M(S,)|==q{p}S{q}tot{p}S{q}AA0i. Decide which number (0or1)is the
majority inb without counting their quantities.
Write a program named MAJORITY in our language that can solve the above problem and bind the majority
among 0 and 1to variable major. You can assume that bis written in the memory state; and to simplify the
question, we artificially define b[n]=100,so you don't need to worry about a possible runtime error when the
array index reaches n. Your program doesn't have tobe deterministic. Be careful of the grammar in our
programming language.
Here are some hints:
We can use the following linear-search-like algorithm: scan the array bto pair up each 0 with a1. Once we
have some 1's left over, then 1is the majority; once we have some 0's left over, then 0is the majority; if
we can pair up all numbers, then either of them can be the majority.
A student Jason wrote a partial solution that can be useful to solve the above problem:
J-=dob[k0]=1k0:=k0+1b[k1]=0k1:=k1+1od
Consider k0 and k1as pointers for number 0 and 1 respectively. What program J does isto find the next
k0 and k1 such that b[k0]=0 and b[k1]=1. You can use J inside of your program.
True or false. Justify your answer briefly.
a.IfM(S,) contains exactly one state, then S must be a deterministic statement.
b.If|=={p}S{q}, then |==p.
d.If|=={p}S{q}, then M(S,)|==q.
e.If{p}S{q}, then tot{p}S{q}.
Calculate denotational semantics for the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!