Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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,...,41}
B ={-7,-6,-5,...,23}
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?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

Define Administration?

Answered: 1 week ago

Question

Assess three steps in the selection process.

Answered: 1 week ago

Question

Identify the steps in job analysis.

Answered: 1 week ago