Topic 5 (Linked lists, Binary Trees) Flashcards

1
Q

3 types of linked lists

A
  • Single linked
  • Double linked
  • Circular linked
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are linked lists composed of?

A

Header, pointer, node, tail

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

What does each node contain? (does not apply to doubly linked list)

A
  • An information field (the data itself)
  • Pointer (Points to the memory address of the next node in the LinkedList)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to draw single linked list

A

Draw the nodes out (info field + pointers)
Draw the head (first pointer that points to the first node)
- Draw the tail (last pointer that points to null from the last node)

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

Circular linked list what is it

A

It’s basically the same as a single linked list except the tail points back to first node

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

Doubly linked list

A

Each node contains 3 components.

Previous, Information Field, Next

You can move back and forth in the list

Otherwise, it is the same as a single linked list

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

The head is synonymous to which Collections method?

A

.getNext()

Accesses the first node

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

Traversing linked list how it works for each list

A

Singled linked list:
You can only move forward and it ends at the last node

Circular linked list:
You can only move forward however the list repeats itself

Doubly linked list:
You can move forward and backward however the list can end

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

How to add a node into a linked list

A

Find the 2 nodes where you want to enter the new node between. Imagine a sandwich.

The node on the left should now point to the new node’s memory address and the the new node points to the memory address of the node on the right.

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

Root node in a binary tree

A

The node at the top

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

Parent and child rules in a binary tree

A

Each parent can only have 2 children

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

How to build a binary tree with a list of numbers

A

First number in list becomes the root node, then if the next number is bigger than the root, it turns into a right child, if it’s less it it turns into a left child. Then, from here you know

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

Deleting nodes from a binary tree

A

Delete the node, then just make the connections between parent and child of the remaining nodes still make sense according to binary tree rules

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

On this whole condition checking thing in binary trees we always base it off the what?

A

Parent node, whether that be the root node or a subset of leaves

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

Trick for doing pre order traversal binary tree

A

Draw a line with a ball pointing to the left from each node.

e.g.
🔴–7

Now, start at the top left node based on the line and traverse through the binary tree whilst sticking to the top left rule.

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

Trick for doing in order traversal binary tree

A

Draw a line with a ball pointing down from each node.

e.g.
7
I
🔴

Now, start at the top left node based on the line and traverse through the binary tree whilst sticking to the top left rule.

17
Q

Trick for doing post order traversal binary tree

A

Draw a line with a ball pointing to the right from each node

e.g.
7–🔴

Follow the top left rule but do not skip any nodes (so you kinda have to go under and around the tree)

18
Q

1 pro and 1 con of a binary tree

A
  • Efficient searching and sorting (algorithm essentially halves the remaining trees every time)
  • Needs to be “balanced”
19
Q

2 examples of where circular linked lists are used

A
  • A media playlist that repeats endlessly
  • When multiple applications are running in a PC. A circular linked list is used to go through each application in use in a circular order and given an equal share in processing power
20
Q

Difference between dynamic and static data structure

A

Static data structures are allocated at compile-time with a fixed size, while dynamic data structures are allocated at runtime and can change in size.