Linked Lists Flashcards

1
Q

How will you implement a Linked List?

A

By connecting Nodes

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

How will you detect a cycle?

A

With tortoise and hare algorithm

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

How will you find middle element?

A

Use Tortoise and Hare algorithm or just divide the size by two and with usage of for loop get to the middle

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

How will you reverse a Linked List?

A

You have to move the elements to the left by one. To do this, use pointers prev and next, where next will store the next current value when current->next = prev and the current value will be assigned to the prev pointer. Make the update on the current pointer and in the end just assign prev pointer to head to make the last element meant by head.

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

How will you merge two sorted Linked Lists?

A

By reference to them and pushing back their data

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

How will you check if the Linked List is a palindrome?

A

If the reversed list is equal to the basic one

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

ARRAY QUESTION
How will you remove Nth node from the end?

A

By using size parameter, size - n and for loop

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

The advantages and disadvantages between Linked lists and Arrays

A

Linked List have constant time in adding at front and Arrays have amortized adding at back. The main difference is that linked lists are better situated in memory, and you have that constant time in pushing and poping at the front.

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

Which implementation of find middle element is faster:
- Tortoise and Hare algorithm
- middle is equal to size / 2 and next is to use loop

A

Tortoise and Hare algorithm is faster.

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

What is the difference between while( current != nullptr and current->next != nullptr )

A

The difference relies on when you use the current != nullptr the loop ends on the nullptr and when you use the second option with current->next != nullptr you will end on the last element in the linked list.

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