4.3 Fundamentals of Algorithms Flashcards

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

What is a Graph Traversal?

A

A graph traversal is a process of systematically visiting each node in a graph

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

What is a Breadth-first traversal?

A

1) A Breadth-first traversal is a method for traversing a graph that explores the nodes closest to the starting node
2) A queue is used to track the nodes to be visited (Contents of a queue)

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

What is a Depth-first traversal?

A

1) A Depth-first traversal starts at a chosen node and explores as far as possible along each branch away from the starting node before backtracking
2) Uses current node and Visited nodes on a graph

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

What are the three ways to traverse a binary tree and how do they work?

A

1) Pre-Order: Traversing by visiting the root, traversing to the left subtree and the ten traversing to the right subtree
2) Post-Order: Traversing a left subtree then a right subtree and finally visiting the root
3) In-Order: Traversing the left subtree then the root and finally the right subtree

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

What is the use of a Pre-order traversal?

A

Outputting the contents of a binary search tree in

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

What is the use of a Post-order traversal?

A

1) Emptying a tree

2) Producing a postfix expression from an expression tree

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

What is the use of a In-order traversal?

A

Outputting the contents of a binary search tree in ascending order

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

What is recursion?

A

When a function calls itself eventually unwinding when the procedure ends there must be a true condition that terminates the recursive procedure

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

What is Reverse Polish Nation?

A

1) A way of writing mathematical expression in a format where the operators are written after the operands
2) E.g. 5 + 3 becomes 5 3 +

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

How do you evaluate infix expressions?

A

1) 5 + 3
2) You add the 3 to the 5 to create the result
3) 3+ (18/3 squared * 3) -4
- Square 3 = 9
- 18/9 =2
- 2 * 3 = 6
- 3 + 6 = 9
- 9 - 5 = 4

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

What is a Linear Search and what is its time complexity?

A

1) A search for items in a file, array or memory where the data items are searched one by one until the required one is found or the end of the list is reached

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

What is a Binary Search and what is its time complexity?

A

1) A Search where the items in the list are sorted it does this by halving the search area with each execution of the loop
2) Split into the middle section and two other sections
2) Start with n items n/2 after 1 comparison n/4 2nd comparison etc…

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

What is the Time Complexity of a Linear Search?

A

0(n) = Linear

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

What is the Time Complexity of a Binary Search

A

0(log n) = Logarithmic

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

What is a Binary Tree Search?

A

1) Same Time Complexity 0 = log(n) = Logarithmic

2) On each pass half of the tree or subtree is eliminated each time its root is examined

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

What is a Bubble Sort Algorithm?

A

1) The simplest but most inefficient sorting algorithm

2) Uses two nested loops to sort n items

17
Q

What is the time complexity of a Bubble Sort?

A

0(n squared)

18
Q

What is a Merge sort Algorithm?

A

1) Uses divide and conquer approach
2) Far more efficient for a larger number of items

Steps:
1) Divides unsorted list into n sublists with each containing a single element

2) Repeatedly merges sublists to produce new sorted sublists until there is only one remaining sorted list

19
Q

What is the Time Complexity of a Merge Sort?

A

0(nlong n)

n sublists and n factors to be multiplied

20
Q

What is Dijkstra’s shortest path algorithm?

A

1) Designed to find the shortest path between one particular node and every other node in a weighted graph
2) Uses a priority queue rather than a FIFO queue
3) Uses include distance or time taken to travel between towns, or the cost of travel between airports etc