CS2400 M3 Flashcards

1
Q

What is an ADT Bag

A

Finite collection of objects in no order, and can contain duplicates.
- get # of items
- check for empty
- add/remove

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How long do the user and producer need to wait to get to work?

A

As soon as they can agree on an interface, both sides can start development. Tunnel analogy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Bag: Public methods

A

+getCurrentSize(): integer
+isEmpty(): boolean
+add(newEntry: T): boolean
+remove(): T
+remove(anEntry: T): boolean
+clear(): void
+getFrequencyOf(anEntry: T): integer
+contains(anEntry: T): boolean
+toArray(): T[]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Bag: private methods

A

-bag: T[]
-numberOfEntries: integer
-DEFAULT_CAPACITY: integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why would you make a private data field final?

A

To avoid any possibility of the user having control over data using the reference.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to write constructor for array bag?

A

@SuppressWarnings(“unchecked”)
T[] tempBag = (T[])new Object[capacity];
bag = tempBag;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Bag .add method

A

If full: return false and don’t add
Else add new entry after the last entry and return true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Safe code/assertion

A

Can be in comment form if not important, but for delicate, important code there are failsafes to ensure that certain variables MUST have certain values before proceeding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Linked Bag?

A

Another way to implement bag interface, but using nodes. Each node contains a data value and a “next” value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Pros/cons of Linked Bags

A
  • Can’t move backwards
  • Takes up more space
    + Easier to transport
    + Generally faster to transport
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Linked Add Method

A

2 cases: empty or not
newNode.next= firstNode;
firstNode = newNode;
numberOfEntries++;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Linked Remove Method

A

2 cases: specified or not
If unspecified return firstNode and remove its link.
If specified first swap with firstNode then remove.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Set

A

Similar to bag, but doesn’t allow duplicates & lacks a getFrequencyOf() method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly