Basic DS Flashcards

1
Q

What are the key 3 differences between an array and a list?

A

An array is of static size, while a list has a dynamic size. Also, all indices of an array are accessible with O(1) . Lastly, you can’t have any implicit null space between elements in a list

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

What is a link list?

A

A list that consists of nodes with a data field and a pointer to the next node

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

What is a singly-linked list?

A

A list where each node points to the next in a single direction

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

What special nodes are included in a linked list field to allow traversal?

A

A head node @ the beginning or a tail node @ the end

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

How do doubly-linked nodes and singly-linked nodes differ?

A

doubly-linked nodes have a previous feild

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

What special cases arise for the list add/contains method?

A

null parameter, which is signalled with a IllegalArgumentException

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

What special cases arise for the remove method?

A

invalid position & empty list which are signalled by IndexOutOBoundsException

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

What fields does an array implemented list have in general?

A

An array that holds the data and a numItems feild

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

How does a circularly list node differ from a regular linked list?

A

A circularly linked node’s last node points to the first & vice versa if it is also doubly-linked

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

What type is a stack?

A

Last-In-First-Out (LIFO)

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

What three unique operations does a stack have?

A
  • push: adds to the top of the stack
  • pop: remove and returns the top of the stack
  • peek: returns the top of the stack
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What type is a queue?

A

First-In-First-Out (FIFO)

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

What two operations does a queue have?

A
  • enqueue: add to the rear

- dequeuer: removes from the front

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

To implement a queue with a linked list, what must be done to make the methods efficient?

A

Create a circularly linked list

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

What fields are included in the linked list constructor?

A

A reference to a header node and/or tail pointer and a numItems variable

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

What type of variables ARE the members of a list with the array implementation vs. the linked list implementation?

A

arbitrary object, list node object that holds an arbitrary object (with a next field)

17
Q

What iterator must be used to traverse a list?

A

An indirect iterator, since the array is not accessible by the iterator class since the data is only accessible through the list field in the iterator class

18
Q

What main problem does a doubly linked node fix?

A

The need to traverse to the node just before n

19
Q

What special cases have to be dealt with when removing a node from a doubly linked list?

A

When the node is either the first or last node. Thiss can be fixed by making it circular

20
Q

What special case needs to be dealt with in the remove method of a circular list?

A

When removing the header node the header pointer needs to be adjusted

21
Q

What is one main disadvantage of a doubly linked list?

A

It takes up more memory since each node has more fields

22
Q

What does pop and peek throw?

A

EmptyStackException

23
Q

What does dequeuer throw?

A

EmptyQueueException

24
Q

What fields are in the constructor of the array implementation of a stack?

A
  1. ) array of objects
  2. )size constant
  3. )numItems
25
Q

What location is the most efficient to have the top of the stack?

A

The end of the array so data members don’t have to be shifted

26
Q

For a DS that implements an array what options are there to expand the array?

A

shadow array (O(1)) and creating a larger array and copying the values

27
Q

Why is the top of the linked list implementation of a stack at the beginning (@header node) rather than the end?

A

Because the header node can directly access the top without traversing

28
Q

What is the problem with the naiive array implementation of the queue?

A

To remove from the front, the members have to be shifted to array[0]. This is solved by keeping a front and rear index field.

29
Q

What index points to the rear where elements are added in a queue?

A

The rear index

30
Q

When the circular array is expanded (rear & front index are adjacent) where are the new values copied to?

A
  • All indexes from the front index to the end of the array are copied to the same front index
  • Add values from the beginning of the array to the rear index after the first sequence of insertions
31
Q

What three fields are in the LList implementation of a queue?

A

The front node
The rear node
numItems

32
Q

What is the advantage of the array implementation of a stack and queue?

A

The indices point to the data themselves and not list nodes (this goes for any array implementation)