4.3 Fundamentals of Algorithms (Combined)

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/52

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

53 Terms

1
New cards

What is meant by graph-traversal?

The process of visiting each vertex in a graph

2
New cards

What are the types of graph traversal algorithms?

- Depth-first

- Breadth-first

3
New cards

How is a graph traversed using depth-first?

Each branch of the graph is fully explored before backtracking and exploring the next

4
New cards

How is a depth-first traversal implemented?

- A stack keeps track of the last node visited

- A list holds the names of the node which have already been visited

- Makes use of the call stack and recursion

5
New cards
<p>What would the order of nodes be when traversing this graph using depth-first?</p>

What would the order of nodes be when traversing this graph using depth-first?

F B A D C E G H

6
New cards

What are some applications of depth-first traversal?

- Job scheduling where jobs have to be completed before others can begin

- Finding a path between two vertices

- Solving puzzles (e.g. navigating a maze)

7
New cards

How is a graph traversed using breath-first traversal?

All nodes adjacent to another are visited before moving to the next

8
New cards

How is a breadth-first traversal implemented?

- A queue keeps track of the nodes to be visited

- A list stores the nodes that have been visited

9
New cards
<p>What would the order of nodes be when traversing this graph using breadth-first?</p>

What would the order of nodes be when traversing this graph using breadth-first?

F B G A D H C E

10
New cards

What are some application of breath-first traversal?

- Finding the shortest path between two points

- Web-crawlers

- Facebook friend suggestions

11
New cards

What is the time complexity of traversals in a sparse graph?

O(n)

12
New cards

What is the time complexity of traversals in a graph with the maximum number of edges?

O(n²)

13
New cards

What is tree-traversal?

The process of visiting/updating/outputting each node in a tree

→ Must start at the root

14
New cards

What are the types of tree traversal algorithms?

- Pre-order

- In-order

- Post-order

15
New cards

How is a tree traversed using pre-order?

knowt flashcard image
16
New cards

What is pre-order traversal used for?

Copying a tree

→ Can be performed on any tree

17
New cards

How is a tree traversed using in-order?

Traverse the nodes in ascending order

→ Can only be performed on binary trees

18
New cards

What is in-order traversal used for?

- Traversing binary search trees

- Alphabetising

19
New cards

How is a tree traversed using post-order?

Starts from the left and works up and round the tree

20
New cards

What is post-order traversal used for?

- Make infix to RPN conversions

- Make postfix expressions from expression trees

21
New cards

What is an algorithm?

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

22
New cards

What is a searching algorithm?

An algorithm to:

- Find the location of an item in a data structure

- Verify the presence of the item

23
New cards

What are the types of searching algorithm?

- Linear search

- Binary search

- Binary tree search

24
New cards

How does a linear search work?

Each item in the list is checked in sequence until the item is found or all items have been checked

→ Compared with the search term

→ Can be performed on any unordered list

25
New cards

Why are linear searches rarely used?

High time complexity - O(n)

26
New cards

How does a binary search work?

- Midpoint in the list is found

- Determine if the target is higher or lower than the midpoint

- This is repeated until the item is found or the list cannot be divided further

Ordered lists only

27
New cards

What is the time complexity of a binary search?

O(log n) - The list is halved with each search

28
New cards

How does a binary tree search work?

Identical to a binary search except it is conducted on a binary tree

29
New cards

What is a binary tree?

A rooted ordered tree in which each node has a maximum of two children

30
New cards

What is the time complexity of a binary tree search?

O(log n)

31
New cards

What is a sorting algorithm?

An algorithm that sorts elements of an array into a specific order

32
New cards

What are the key sorting algorithms?

- Bubble sort

- Merge sort

33
New cards

How does a bubble sort work?

- Items compared in pairs and swapped if they are in the wrong position

- Passes made until the list is fully ordered

34
New cards

What is the time complexity of a bubble sort?

O(n²) - very inefficient

35
New cards

How does a merge sort work?

Divide and conquer algorithm

- List is split into sub-lists until each list contains one item

- List reformed until one ordered list

36
New cards

What is the time complexity of a merge sort?

O(n log n)

37
New cards

What is an optimisation algorithm?

An algorithm that finds the best possible solution to the problem posed

38
New cards

What is an example of an optimisation algorithm?

Dijkstra’s algorithm

39
New cards

What does Dijkstra’s algorithm do?

Finds the shortest path from a starting node to every other node in a graph/network

→ Keeps track of visited nodes with a priority queue

40
New cards

What are some applications of Dijkstra’s algorithm?

- To calculate shortest paths (e.g. satellite navigation systems)

- Routing of packets in a network

41
New cards

What does it mean if a problem is computable?

If an algorithm can solve every instance of the problem in a finite number of steps

42
New cards

What does it mean if a program is soluble?

It is able to be solved

43
New cards

What makes a problem insoluble?

It cannot be solved

→ Includes solutions which would take millions of years

44
New cards

What does it mean if a problem is intractable?

It is unable to be solved in a reasonable time

45
New cards

What is an example of a famous intractable problem?

The Travelling Salesman Problem

→ Finding the shortest distance to visit every node on a graph exactly once

46
New cards

What are the time complexities of intractable problems?

- O(n!)

- O(2^n)

47
New cards

What are the time complexities of tractable problems?

- O(n)

- O(n²)

- O(n^a)

- O(log n)

48
New cards

What is meant by a heuristic method?

One which attempts to find a solution which may not be perfect but is adequate for its purpose

49
New cards

What are some examples of heuristic methods?

- Common sense

- Educated guess

- Gut feeling

50
New cards

What are the essential characteristics of a recursive routine?

- A stopping condition/base case

- The routine must call itself for input values other than the stopping condition

- Stopping condition must be reached after a finite number of calls

51
New cards

How is the call stack used in recursive algorithms?

Every time a subroutine is called, the return address is added to the call stack

→ The algorithm will ‘unwind’ automatically as the call stack is popped off

52
New cards

This is filler

This is filler

53
New cards

This is filler

This is filler