Data Structures: Linked Lists Flashcards

1
Q

What is the purpose of a linked list?

A

a linked list is a dynamic arrangement of nodes that can grow and shrink at runtime. Therefore, it is useful when you do not know the initial size of the data. where each node contains a link to the next node in the list. These ‘links’ are pointers

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

What are the advantages of a linked list?

A

Dynamic data structure

Resizable at runtime

efficient and easily implemented insertion and deletion functions

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

When do we use a linked list over a list/array?

A

When implementing a queue, in which elements are continuously inserted or removed from the beginning of the list

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

How does a linked list work?

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

What is the structure of a linked list?

A

a linked list consists of Nodes. Each node contains two components: data and a pointer to the next node.

The last node in the linked list points to NONE or NULL
The first node in the linked list is the HEAD

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

All data structures have unique strengths and weaknesses. Therefore, it is important to know these strengths/weaknesses when it comes to designing, optimizing, and scaling programs

So, the strengths and weaknesses of a linked list are:

A

The strengths of the linked list:

+ The linked list has two operations, insertion and deletion, that are efficient and easy to implement
+ linked list has dynamic data structure that can grow and shrink at runtime
+ no memory wastage

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

Why are linked lists used?

A

linked lists are often used because insertion and deletion are efficient and easy to implement

Linked lists are used for queues, stacks, and other abstract data types

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

What are the disadvantages of linked lists?

A

Memory usage: more memory usage is required in a linked list than an array/list since each node stores both data and a pointer to the next node

Traversal: it is more time-consuming to traverse a linked list than an array since you have to traverse all n elements to access the nth element. Whereas with an array, you can directly access the nth element

Reverse Traversing: is not possible on a singly linked list and requires a doubly linked list, which stores an additional pointer in the node. This pointer points to the address of the previous node. Thus, there is a wastage of memory

Random Access: poor performance as a result of random memory storage. The data can be stored far apart, which makes it difficult for the CPU to cache the contents of a linked list, which results in poor performance

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