Q20. Suppose a computer program has been initialized such that the following sets have been stored for use in any algorithm: A = {1, 2, 3, ..., 46} B = {-7, -6, -5, ..., 27} Consider the following algorithm, which represents one part of the whole computer program (comments may occur after the # symbol on any line and are not used in computations): #Part 1: computes A - B and its cardinality AminusB = set() for element in A:   # this line runs through every element in A     if not(element in B): #A - B is the set of elements that are in A and are not in B         AminusB.add(element) # Add to AminusB every element in A if the element is also not in B n = len(AminusB) #len() returns the number of elements in the array print(n)    What value is printed as a result of executing this algorithm?

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter16: Searching, Sorting And Vector Type
Section: Chapter Questions
Problem 16SA
icon
Related questions
Question

Q20. Suppose a computer program has been initialized such that the following sets have been stored for use in any algorithm:

A = {1, 2, 3, ..., 46}
B = {-7, -6, -5, ..., 27}

Consider the following algorithm, which represents one part of the whole computer program (comments may occur after the # symbol on any line and are not used in computations):

#Part 1: computes A - B and its cardinality

AminusB = set()
for element in A:   # this line runs through every element in A
    if not(element in B): #A - B is the set of elements that are in A and are not in B
        AminusB.add(element) # Add to AminusB every element in A if the element is also not in B

n = len(AminusB) #len() returns the number of elements in the array
print(n) 

 

What value is printed as a result of executing this algorithm?

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning