1. Define the following two relations on the set {a, b, c, d} S = { (a, b), (a,
ID: 3005796 • Letter: 1
Question
1. Define the following two relations on the set {a, b, c, d}
S = { (a, b), (a, c), (c, d), (c, a) }
R = { (b, c), (c, b), (a, d), (d, b) }
Write S R as a set of one or more ordered pairs.
2. Write an algorithm in pseudo-code with the following input and output
Input: a1, a2,..., an, a sequence of integers.
Output: The smallest integer in the sequence.
3. What is the value of count after the last iteration of the outer for loop? Please show your work.
count :=0
For i= 1 to 2
For j=1 to 2
count :=j(count + 2i) Here, the right-hand side is j times the quantity (count + 2i)
End-for
End-for
Explanation / Answer
2)
procedure lastsmallest(a_1,a_2,...,a_n: integers)
min = a_1
location = 1
for i = 2 to n
if min >= a_i
then
min = a_i
location = i
end
{location is the location of the last occurrence of the smallest element in the list}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.