2.3.2 - Algorithms for Main Data Structures Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is a stack?

A

A stack is a first-in, last-out data structure.

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

How do you check the size of a stack?

A

Size()

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

How do you check if a stack is empty?

A

isEmpty()

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

How do you return the top element of a stack but not remove it?

A

Peek()

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

How do you add an item onto a stack?

A

Push(element)

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

How do you return and remove the top element of a stack?

A

Pop()

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

What is a queue?

A

A queue is a first-in, first-out data structure.

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

How do you check the size of a queue?

A

Size()

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

How do you check if the queue is empty?

A

IsEmpty()

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

How do you return the front element but not remove it from a queue?

A

Peek()

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

How do you add an element to a queue?

A

Enqueue(element)

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

How do you remove and return the front element from a queue?

A

Dequeue()

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

How is a tree formed?

A

Trees are formed from nodes and edges.

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

What are the two types of tree-traversal?

A

Depth first (post-order) traversal and breadth first traversal.

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

How does depth first traversal work?

A

It works in the same way as a post-order traversal.

Draw around the graph and mark the nodes when the drawing goes around on the right of the node.

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

How does breadth first traversal work?

A

It works by visiting all of the children of the start node and then all nodes directly connected to them.

In simple terms, go across from the top left to the bottom right.

17
Q

What is a binary search tree?

A

A tree where each node can have a maximum of two child nodes.

The left child node is alphabetically or numerically lower than the parent node and the right child node is alphabetically or numerically higher than the parent node.

18
Q

How is a node deleted from a tree?

A

1) The tree is searched to find the node to be deleted.
2) Replace the content of the node to be deleted to null.
3) Make the parent node point to the child node of the node to be deleted.
4) Add the node to be deleted to the empty node list.

19
Q

How is a node added to a tree?

A

1) Search the tree to find the value where the node needs to be added to.
2) Create a new node with the correct value.
3) Add a pointer from the parent node to the new node.
4) Make the new node point to null.

20
Q

What are similarities between a tree and a graph?

A

Both consist of nodes.

Both are connected by edges/links.

Both are dynamic data structures.

21
Q

What are differences between a tree and a graph?

A

Tree is 1-directional whereas a graph is 2-directional.

Tree has a root node whereas a graph doesn’t have a clear root node.

Trees are not weighted whereas graphs can be.

Trees will not have cycles whereas graphs can contain cycles.

22
Q

What are differences between recursion and iteration?

A

Recursion uses more memory than iteration.

Recursion can run out of memory whereas iteration cannot.

Recursion will call itself whereas iteration does not.

23
Q

What are four features in an IDE that help with debugging?

A

Stepping through the code to run one line at a time.

Syntax error highlighting.

Breakpoints.

Variable watch window.

24
Q

How does stepping through the code help with debugging?

A

Runs one line at a time to see where the error is.

25
Q

How does syntax error highlighting help to debug a program?

A

To distinguish syntax errors in the program code.

26
Q

How does setting breakpoints help with debugging?

A

It allows individual sections of code to be debugged at one time.

27
Q

How does a variable watch window help with debugging?

A

It checks that the variables are being updated correctly.