Fundamentals of Algorithms Flashcards

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

What is an algorithm?

A

A set of instructions which completes a task in a finite time and always terminates.

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

Name the two types of graph traversal.

A

Depth-First Search (DFS)
Breadth-First Search (BFS)

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

Describe a Breadth-First Search

A

Startssearching at a designated startnode and searches through all the adjacentnodes (neighbours) before moving on.

Uses aqueueas a supporting data structure.

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

Describe a Depth-First Search

A

Begins at the start node and then searches as far as possible down a branch of the graph until there are no more nodes along the current branch to be explored. If the target node is found along the way, the search can stop. Otherwise, the algorithm must backtrack and find another branch to explore.

Uses astackas a supporting data structure.

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

State an application of DFS

A

Can be used to determine whether there is a path between two nodes of a graph.

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

State an application of BFS

A

Shortest path between two nodes on an unweighted graph.

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

Name the three types of tree-traversal

A

Pre-order
In-order
Post-order

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

Name a use of postorder traversal

A

Convert Infix to RPN
Emptying a tree
Produces a postfix expression from an expression tree.

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

What is a tree

A

A connected, undirected graph without any cycles.

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

Why is RPN used?

A

Eliminates the need for brackets, removing ambiguity and simplifying expressions.

It is well suited to manipulation by a stack, making it a popular choice when working with computers.

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

Where is RPN used?

A

In interpreters which are based on stacks.

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

Convert the following infix expression to RPN: (12 - 4) * (3 + 5)

A

12 4 - 3 5 + *

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

Convert the following reverse polish expression to infix: 13 6 + 4 -

A

(13 + 6) - 4

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

What is the time complexity of a linear search algorithm?

A

O(n)

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

Which searching algorithm requires the data to be sorted before starting?

A

Binary search

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

What is the time complexity of binary search?

A

O(log n)

17
Q

What is the time complexity of the bubble sort algorithm?

A

O(n^2)

18
Q

Which sorting algorithm is an example of “divide and conquer”

A

Merge sort

19
Q

What is the time complexity of a merge sort algorithm?

A

O(nlogn)

20
Q

Which is more time efficient: bubble or merge sort?

A

Merge sort

21
Q

What is the purpose of Dijkstra’s algorithm?

A

Find the shortest path between two nodes in a weighted graph.