Chapter - 35 Lists and linked lists Flashcards

1
Q

What is a list?

A

» Ordered data structure
» Dynamic
» Accessing the data involves using an index

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

What is the operation to test an empty list?

A

» isEmpty()

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

What is the operation to add a new item to list to the end of the list?

A

» Append(item)

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

What operation is used to remove the first occurrence of an item from the list?

A

» remove(item)

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

What operation is used to search for an item in a list?

A

» search(item)

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

What operation can you use to return the number of items in a list?

A

» length()

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

What operation can return the position of an item?

A

» index(item)

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

What operation can insert a new item at a position number?

A

» insert(pos,item)

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

What operation can remove and return the last item in the list?

A

» pop()

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

What operation can remove and return the item at a position number?

A

» pop(pos)

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

What is the difference between an array and a list?

A

» List is dynamic
» Array is static

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

How do you insert a new name in the list?

A

» Test whether the list is already full, print message if it is and quit
» Determine where new item needs to be inserted
» Starting at the end of the list, move other items along one piece
» Insert new item in correct place

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

How do you delete a name from the list?

A

» First delete the name
» Names coming after deleted item need to me moved up to fill the empty space - by copying them to the previous spot in the array
» Finally the last element which is now duplicated is replaced with a blank

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

What is a linked list?

A

» Dynamic data structure used to hold an sequence
» It provides a foundation upon which other structures can be built

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

What are some features of a linked list?

A

» Items which form the sequence are not necessarily held in contiguous data locations, or in the order in which they occur in the sequence

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

What is each item in the linked list called?

A

» A Node
» Contains a data field and a next address field called a link or pointer field

17
Q

What does the data field contain?

A

» Actual data associated with the list item

18
Q

What does the pointer field contain?

A

» The address of the next item in the sequence

19
Q

What is the use of the null pointer?

A

» The link field in the last item indicates that are no further items by the use of a null pointer

20
Q

What is the start pointer?

A

» Identifies the first node in the list

21
Q

How do we initialize a linked list?

A

» Keep two linked lists
» One for the actual data
» One for the free space

22
Q

What does the start pointer aim to in a new initalised linked list?

A

» First item in the list, initialised to null

23
Q

What does null indicate?

A

» A list is empty

24
Q

Which pointer does the last item of an empty list have?

A

» Pointer of null

25
What does the pointer point to?
» To the next index
26
What is the nextfree pointer?
» Points to the next free location in the array
27
What does Names[p].name do?
» Holds the name in node[p]
28
What does Names[p].pointer do?
» Holds the value of the pointer in node [p]
29
What are the steps to insert a new item to a linked list?
» Check if there is free memory for a node, output an error if there is not » Create a new node and insert data in the node indicated by the free storage pointer
30
How can you traverse a linked list?
» Check if the linked list is empty » Start at the node the start pointer is pointing to » Output the item » Follow the pointer to the next node » Repeated until the end is reached
31
Define the meaning of traverse
» Processing of where you access each element and every element present in a data structure
32
How can you make a circular linked list?
» By making the last node point to the first node » Each node in a circular linked list can also have an additional pointer pointing to the previous item - creating a doubly circular linked list
33
What is the advantages of implimenting a linked list using object oriented techniques?
» Any available memory adress can be used to store data » Does not need to be adjacent - as each node points to the next in the structure » Memory footprint of the data structure is not determined at compile time and can change dynamically at run time - Dynamic
34
What are the uses of a linked list?
» Operating system manages a processor to store processor to store process blocks in a ready state » Music players to store tracks in a platlist
35
What happens if the linked list is empty when a node is being added to it?
» New node becomes the first item » Creates a start pointer to it
36
What happens if the new node should be placed before the first node?
» New node becomes the first node - Change the start pointer to it » New node points to the second node
37
What are the steps if the new node is to be placed inside the linked list?
» Start at the first node » If the data in the current node is less than the value of the node, follow the pointer to the next node until position is found » New node is set to point where the previous node pointed » Previous nodes set to point to the new node
38
How do we delete items from a linked list?
» Check if the linked list is empty and output an error if there is no start node » If the first item is the item to delete, set the start pointer to the next node
39
What happens if the item to delete is in the linked list?
» Find the node to delete » Previous node's pointer is set to the next node after the delete one » Follow the new nodes pointer to the next node » Update the free pointers