2.3.1 - Algorithms (Data Structures) Flashcards

1
Q

What would be output using a breadth-first traversal on the following tree?

A

Italy, France, Spain, Austria, Germany, Norway

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

What would be output using a depth-first traversal on the following tree?

A

Austria, Germany, France, Norway, Spain, Italy

Root node is always last in depth-first (post-order)

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

Describe the steps involved in a breadth-first traversal

A

Uses a queue data structure to perform the traversal

  1. Visit root node
  2. Visit all direct children
  3. Visit all children of first child
  4. Repeat three points for each child visited
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe the steps involved in a depth-first traversal

A

Uses a stack data structure to perform the traversal

  1. Traverse the left subtree
  2. Traverse the right subtree
  3. Visit the root node
  4. Repeat three points for each child visited
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In what situation would a depth-first traversal be chosen over a breadth-first traversal?

A

Depth

  • Requires less memory than breadth first search.
  • Quicker than breadth if you are looking at deep parts of tree

Breadth

  • Is more efficient when the data searched for is closer to the root.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Keywords to describe a binary tree

A
  • Ordered Data Structure
  • Child Node
  • Parent Node
  • Root Node
  • Leaf Node
  • Sub Tree
  • Edge / Branch
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Draw this Binary Search Tree

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

What is the purpose of the root and free pointers in a binary search tree?

A

Root Pointer - Points to where the tree starts (root node)

Free Pointer - Points to where the next piece of data would be added in the array

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

Key words to descirbe a tree (multi-branch)

A
  • No restriction on the number of child nodes per parent
  • Un-Ordered Data Structure
  • Child Node
  • Parent Node
  • Leaf Node
  • Sub Tree
  • Edge / Branch
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write the pseudocode to push an item to a stack

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

Write the pseudocode to pop an item to a stack

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

Keywords to describe a queue

A
  • Dynamic Data Structure
  • Enqueue
  • Dequeue
  • First in First Out
  • Peek
  • Front Pointer
  • Rear Pointer
  • Circular / Non-Circular
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Write the pseudocode to dequeue an item to a queue

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

Write the pseudocode to enqueue an item to a queue

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

Describe the purpose of the front and rear pointer in a queue

A

Front - Where the data will be removed from (dequeued)

Rear - Where the data will be added to (enqueued)

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

Give examples of where stacks and queues are used in computers

A

Queues - Used in print queues – New print jobs are added to the end of the queue. Jobs are processed from the front of the queue

Stack - Internet History – When you visit a site the last site is pushed to the stack. When you click back the last item is popped from the stack, and then loaded.

17
Q

Keywords to describe a linked list

A
  • Dynamic Data Structure
  • Node (made up of a pointer and a piece of data)
  • Non-Contiguous
  • Start Pointer
  • Null
18
Q

What are the pros and cons of a linked list?

A

(+) You can store multiple pointers without reordering the linked list

(+) Using pointers means that the linked list does not need to be store contiguously in memory

(-) Inefficient for searching as you must go through each node one at a time following the pointers (WHILE loop until ‘null’ is reached).

19
Q

What would the pointers be to output this linked list in alphabetical order?

A

Start Pointer = 2

20
Q

What types of edges can be used in a graph?

A
  • Directed
  • Undirected
  • Weighted
  • Unweighted

Edges in a directed graph only go in one direction. Undirected edges can go in both directions.