Linear Data Structure: Iteration Flashcards

1
Q

What is a cursor?

A

An abstraction that represents a position with a collection; a property of a collection that records a specific position

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

Operations on a cursor interface

A

itemExists (check)

item (getter)

goFirst (mover in list)

goForth (mover in list)

goLast (mover in list)

goBefore (mover outside of list)

goAfter (mover outside of list)

before (test)

after (test)

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

Are all operations necessary?

A

No, different data structures/ADTs will have different types of operations

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

How to represent: between 2nd and last element in a list

A
  • position value: non-null
  • prevPosition value: non-null
  • # elements in list: > 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to represent: first element in a list

A
  • position value: non-null
  • prevPosition value: null
  • # elements in list: > 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to represent: after in a list

A
  • position value: null
  • prevPosition value: non-null
  • # elements in list: > 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to represent: before in a list

A
  • position value: null
  • prevPosition value: null
  • # elements in list: > 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to represent: before and after in a list

A
  • position value: null
  • prevPosition value: null
  • # elements in list: 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the external differences between the cursor interface of the ArrayedList and LinkedList classes

A

None, they are the same, which is an advantage of cursors; cursors have the same outward functionality regardless of the different list structure

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

Are there internal differences between the cursor interface of the ArrayedList and LinkedList classes

A

Yes, different data structures have different internal implementations, even though they externally work the same

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

What is an iterator? How is it different from a cursor

A

A distinct object that represents a position in an instance of a collection and always has public methods for iteration.

Cursors are just an abstraction of a position and may not have public methods

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

What is the idea behind iterators?

A
  1. An instance method of a list (or any collection) is called that returns an iterator object.
  2. The iterator object implements the cursor interface.
  3. The iterator object can be used to “loop” over the elements of the list instance which generated it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What’s the purpose of iterators?

A

Cursors can be used for something else in the moment, while we are iterating with an iterator.

Otherwise, it would be up to the user to save and restore the collection’s cursor before and after using the cursor to iterate

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