Filters
Question type

Study Flashcards

The standard Python hash function always returns a unique positive integer.

A) True
B) False

Correct Answer

verifed

verified

The AbstractSet class is a subclass of AbstractBag .

A) True
B) False

Correct Answer

verifed

verified

False

Array-based implementations of sets and dictionaries do not perform well.

A) True
B) False

Correct Answer

verifed

verified

In the code for the __init__ method in the Entry class or a dictionary, what is the missing code? def __init__(self, key, value) : < missing code > Self.value = value


A) key = self.key
B) self.key = key
C) value = self.key
D) self.key = value

E) None of the above
F) A) and C)

Correct Answer

verifed

verified

A set is similar to a bag, but it contains unique data items and additional methods.

A) True
B) False

Correct Answer

verifed

verified

Which of the following is a subset of Set A if Set A is {19 4 26 8}?


A) None of the choices are subsets of Set A
B) {19 4 26 8 0}
C) {4 8 19 26 44}
D) {}

E) A) and D)
F) A) and B)

Correct Answer

verifed

verified

Python supports multiple inheritance, so a class can have more than one parent class.

A) True
B) False

Correct Answer

verifed

verified

For a key value of 93 and a hashing function of key % 46 , what is the index into the array?


A) 1
B) 2
C) 46
D) 47

E) All of the above
F) A) and B)

Correct Answer

verifed

verified

Which method is specific to a set compared to a bag?


A) remove
B) __str__
C) add
D) __sub__

E) None of the above
F) A) and B)

Correct Answer

verifed

verified

With a set, the difference and subset operations are not symmetric.

A) True
B) False

Correct Answer

verifed

verified

In the Entry class for a dictionary, comparisons are done using the value item in each entry.

A) True
B) False

Correct Answer

verifed

verified

To reduce the probability of collisions with hashes, you can decrease the array length.

A) True
B) False

Correct Answer

verifed

verified

In which collision-avoidance hashing strategy are the items stored in an array of linked lists in which each item's key locates the bucket where the item is to be inserted?


A) clustering
B) chaining
C) quadratic probing
D) linear probing

E) B) and D)
F) B) and C)

Correct Answer

verifed

verified

In the implementation of the AbstractDict class, which four methods have the same implementation for all dictionaries?


A) keys, values, __add__, __eq__
B) entries, values, __init__, __str__
C) keys, values, entries, get
D) get, __add__, keys, __init__

E) A) and B)
F) A) and C)

Correct Answer

verifed

verified

In the code for the __sub__ method for the AbstractSet class, what is the missing code? def __sub__(self, other) : Difference = type(self) () For item in self: If not item in other: < missing code > Return difference


A) difference.remove(item)
B) intersection.add(item)
C) difference.add(item)
D) return(item)

E) None of the above
F) A) and D)

Correct Answer

verifed

verified

In the code for the __iter__ method for the ArrayDict class, what is the missing code? def __iter__(self) : Cursor = 0 While cursor < len(self) : Yield self.items[cursor].key < missing code >


A) return(self.items[ cursor ])
B) cursor -= 1
C) return(self.items[ key ])
D) cursor += 1

E) A) and B)
F) A) and C)

Correct Answer

verifed

verified

D

In the hashing implementation of a set, self.index refers to the index of the chain in which the node was just located, or is -1 otherwise.

A) True
B) False

Correct Answer

verifed

verified

True

Referring to the keysToIndexes function, what is the result of the following statement? keysToIndexes([ 39, 18, 4, 51, 6, 28 ], 17)


A) [ 6, 2, 5, 1, 7, 12 ]
B) [ 7, 3, 6, 2, 8, 13 ]
C) [ 4, 2, 3, 1, 5, 10 ]
D) [ 5, 1, 4, 0, 6, 11 ]

E) All of the above
F) A) and B)

Correct Answer

verifed

verified

A small load factor and an array length that is a prime number increases the chances for a hashing collision.

A) True
B) False

Correct Answer

verifed

verified

What is the performance value of the array-based implementations of sets and dictionaries?


A) O( n 2)
B) O( n )
C) O n
D) O(1)

E) All of the above
F) None of the above

Correct Answer

verifed

verified

Showing 1 - 20 of 50

Related Exams

Show Answer