Collections part 2 Flashcards

1
Q

Set characteristics

A
  1. Elements are not ordered.
  2. Elements in the set must be unique.
  3. Adding a duplicate does nothing.
  4. Cannot access elements by index, only by iterator (for each).
  5. add( x ) adds an element to the set.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Set syntax

A
Set  variable = new HashSet();
Set - Set interface
 - Data Type the Set will Hold
HashSet - implementation class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Set order

A

The Order of the elements in a Set can be controlled by the Implementation Class used.

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

HashSet - implementation class of Set

A
  1. Does not guarantee Order.

2. Allows null.

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

LinkedHashSet - implementation class of Set

A
  1. Order of Insertion

2. Allows null.

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

TreeSet - implementation class of Set

A
  1. Natural Order of Data Type
  2. Does not allow null
    Natural Order of numeric types is numeric order:
    1, 2, 10, 20, 21, 30
    Natural Order of String is alphanumeric order:
    1, 10, 2, 20, 21, 30
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Key-Value pairs

A

A set of 2 pieces of data, where the value is associated by a unique key, allowing the value to be retrieved by providing the key.

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

Map

A

A collection that utilizes Key-Value pairs, allowing values to be assigned and then located using user-defined keys.

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

Map keys characteristics

A
  1. Can be any reference type.
  2. Must be unique.
  3. Cannot be null.
  4. Stored as a Set.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Map values characteristics

A
  1. Can be any reference type.
  2. Can have duplicates.
  3. Can be null.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Map syntax

A

Map variable = new HashMap();
Map - is an interface
K - the first Type is the Data Type of the Key
V - the second Type is the Data Type of the Value
HashMap - the implementation class to instantiate

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

Map Methods

A

put( key, value ), get( key ), remove( key ), containsKey( key ), containsValue( value ), keySet(), entrySet()

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

Algorithm Problems

A

Algorithms are not measured by the speed they run, but by how their performance increases as the problem size increases.

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

Big O Complexities

A

O(1) - Constant-time
- The complexity doesn’t increase as the problem increases (selecting an item from an Array by index).
O(log n) - Logarithmic
- The complexity increases at a constant factor that is not directly related to the problem size.
O(n) - Linear
- Doubling the problem size, doubles the complexity (iterating over every item in a list).
O(n log n) - Linearithmic
- Doubling the problem increases the complexity by a fixed size (most search algorithms).
O(n2) - Quadratic
- Doubling the problem size multiplies the complexity by a factor of 4 (loop within a loop)
O(nx) - Polynomial
- Double the size of the problem multiplies the complexity by a factor multiplied by the exponent
O(2n) - Exponential
- Increasing the problem size by 1 double the complexity. Doubling the problem size squares the work.
O(n!) - Factorial
Something has gone horribly wrong

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

Collection Complexity

A

Each collection time has a complexity associated with
Insert (at the end, at the beginning, at the end), Searching, Retrieval, Removal (from the end, from the beginning, from the end)

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

Map implementation classes

A

HashMap - does not maintain order.
LinkedHashMap - maintains the order of insertion.
TreeMap - maintains the natural order of the key data type.

17
Q

Algorithm Complexity

A

Big O notation is used to describe an algorithm’s change in performance as the problem size increases.
Big O and complexity are always measured in the Worst Case Scenario.