Overview of Collections Flashcards

1
Q

What is a collection?

A

Container for zero or more data objects

Tracks its own size and resizing is automatic

Comes with built-in operations for access, insertions, removals, etc.

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

What do we do with the details of a collection’s underlying data structures and operations? Why?

A

We ignore them because they are hidden in the implementation

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

Built-in python collections

A

String, Tuple, List, Set, Dictionary

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

Basic categories of collections

A

Linear, Hierarchical, Graph, Unordered

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

Types of linear collections

A

List, Stack, Queue, Priority Queue

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

Linear collection characteristics

A

Elements are ordered by position

Each element except the first has a unique predecessor

Each element except the last has a unique successor

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

List characteristics

A

Allow accesses, replacements, insertions, and removals at any position

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

Stack characteristics

A

Allow accesses, insertions, and removals at one end only

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

Queue characteristics

A

Allow insertions at one end and removals and accesses at the other end

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

Priority Queue characteristics

A

Sort elements by priority, but elements with equal priority are added and removed in queue-like order

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

Types of hierarchical collections

A

Binary tree, General tree, Binary search tree, Heap

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

Hierarchical collection characteristics

A

Each element except the root has a unique predecessor

Each can have zero or more successors

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

Types of graph collections

A

Undirected graph, Directed graph

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

Graph collection characteristics

A

Each element can have zero or more predecessors

Each can have zero or more successors

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

Types of unordered collections

A

Bag, Set, Dictionary

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

Unordered collection characteristics

A

No notion of position from the user’s perspective

We can visit all the objects with a for loop

17
Q

Types of sorted collections

A

Sorted Set, Sorted Dictionary

18
Q

Sorted collection characteristics

A

The elements are not ordered by position, but they are ordered by content (ascending order)

19
Q

Aspects of a collection

A

Formal properties (what it is and what you can do with it - as expressed in its interface)

Implementations - array-based, link-based, etc.

Performance characteristics - space/time tradeoffs of different implementations

20
Q

Basic types of operations

A

Create a collection: collection()

Obtain the string representation: str(collection)

Obtain the number of items currently in the collection: len(collection

Test an item for membership: item in collection

Iterate through the items: for item in collection:

Concatenate two collections (of the same type): collection1 + collection2

Test for equality: collection == object

Make the collection empty: collection.clear()

Add an item: collection.add(item)

Remove an item: collection.remove(item)