Linked Lists Flashcards

1
Q

What is the primary characteristic of a doubly-linked list?

a) Items are only linked to their next item
b) Items have references to both the next and previous items
c) Items are stored in a fixed-size array
d) Each item has a unique index

A

b) Items have references to both the next and previous items

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

What does the setWithOneItem() method in the LinkedList class do?

a) Adds multiple items to the list
b) Links the first and last items together
c) Sets the first and last items to the same single item
d) Removes an item from the list

A

c) Sets the first and last items to the same single item

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

What is returned by the findItemByName() method if the specified item is not found?

a) An empty item
b) The first item in the list
c) Null
d) An exception is thrown

A

c) Null

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

How does the addItem() method handle adding an item to a non-empty list?

a) Inserts the item at the last position
b) Replaces the current first item with the new item
c) Links the new item to the first item and updates references
d) Creates a new array to store the items

A

c) Links the new item to the first item and updates references

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

What does the removeItemByName() method do if the item is successfully removed?

a) It throws an exception
b) It decrements the list count and returns true
c) It resets all list properties to null
d) It appends the item to the end of the list

A

b) It decrements the list count and returns true

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

What will be the value of the listCount property after adding three items to an empty LinkedList?

a) 0
b) 1
c) 2
d) 3

A

d) 3

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

What is the purpose of the getNextItem() method in the Item class?

a) It adds a new item to the list
b) It removes the next item from the list
c) It retrieves the reference to the next item in the list
d) It resets the next item to null

A

c) It retrieves the reference to the next item in the list

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

In a linked list, what happens when addItemAtBack() is called on an empty list?

a) It does nothing since the list is empty
b) It calls setWithOneItem() to initialize the list with the new item
c) It throws a NullPointerException
d) It creates a new array to store the item

A

b) It calls setWithOneItem() to initialize the list with the new item

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

What does the toString() method in the LinkedList class output?

a) A list of item names in the order they are stored
b) The memory addresses of all items in the list
c) The number of items in the list
d) A graphical representation of the linked list

A

a) A list of item names in the order they are stored

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

What does the addItem() method check before calling setWithOneItem()?

a) If the list contains duplicate items
b) If the listCount is zero
c) If the list contains null values
d) If the first item is equal to the last item

A

b) If the listCount is zero

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

How does the findItemByName() method iterate through the linked list?

a) By using a for loop with an index
b) By following the references using the getNextItem() method
c) By sorting the items first and then searching
d) By traversing both next and previous references simultaneously

A

b) By following the references using the getNextItem() method

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

What happens if you try to remove an item from the list using removeItemByName() and the item is not found?

a) An exception is thrown
b) The method returns false
c) The list is reset to its initial state
d) The first item is removed by default

A

b) The method returns false

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

What happens when you try to add an item to the back of the list using addItemAtBack()?

a) The list is cleared before adding the item
b) The new item is linked to the last item and becomes the new last item
c) The list is sorted after adding the item
d) The method removes all previous items from the list

A

b) The new item is linked to the last item and becomes the new last item

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

What advantage does a linked list have over an array?

a) It stores items contiguously in memory
b) It allows quick access to items using indices
c) It does not need resizing when adding items
d) It can only store primitive types

A

c) It does not need resizing when adding items

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

In which scenario would a circular linked list be useful?

a) When managing a browser’s back and forward buttons
b) When creating a looping playlist in a music player
c) When storing items with unique indices
d) When working with arrays of fixed size

A

b) When creating a looping playlist in a music player

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