4.3 (every spec covered) Flashcards

(60 cards)

1
Q

What are the features of a breadth first graph traversal? (3)

A

explores graph level by level

uses a queue data structure

best for finding the shortest path in an unweighted graph

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

how does a breadth first search logically work (4)

A

Uses a queue to keep track of nodes to visit
Uses a visited set to avoid resvisiting nodes

start at first node, enqueue and mark as visited

dequeue A, Enqueues A’s unvisited neighbours

Repeat

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

What are the features of a depth first graph traversal?

A

Explores as deep along each possible branch before backtracking

uses a stack

applications include maze, puzzle solving and path finding

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

How does a depth first search logically work

A

need a stack and a visited set of nodes

step by step:

start at node 1, push 1 onto stack

pop 1, mark 1 visited, push neighbours onto stack

pop neighbour at the top of stack push unvisited neighbours of that stack

repeat until there are no unvisited neighbours

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

pre order tree traversal order

A

Node, Left, Right -

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

post order tree traversal

A

Left, Right, Node -

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

in order tree traversal and when its used (1)

A

Left, Node, Right -
Used in binary search trees

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

What is Meant by O(N)

A

O represents the order of complexity

N represents the number of inputs

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

What are the factors of complexity used in big o notation

A

Memory used, time clompexity

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

Time complexity of linear search

A

O(n)

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

Time complexity of Binary/Binary tree search

A

O(log n).

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

Time complexity of Bubble sort

A

O(n^2).

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

Time complexity of Merge sort

A

O(n log n).

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

What is djikstras algorithim?

A

Finds the shortest path between one node and all other nodes on a weighted graph.

It is considered a type of breadth first algorithim

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

What does it mean when algorithims are tractable?

A

These are problems that have a polynomial (or less) time solution (x^2)

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

What is it when an algorithim is intractable?

A

These are problems that have solutions in greater than polynomial time

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

What methods are used when tackling intractable problems

A

Heuristic methods

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

How do we trace a graph depth first

A

Start at a root and follow one branch as far as it will go. (using stack)

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

How do we trace a graph breadth-first

A

start at root scan every node connected and then continue scanning from left to right (using queue)

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

What are heuristic methods

give 2 examples

A

practical approaches used when finding an optimal solution is impractical or impossible due to time constraints

For example trial and error, pattern recognition

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

Describe the traversing of a graph breadth first using a queue

A

Set the root node as current node
Add current node to list of visited nodes
For every edge connected to that node enqueue the linked node

Then dequeue the current node and move front pointer up by one and repeat steps with the new current node

output all visited nodes

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

Describe the traversing of a graph depth frist using a stack

A

Visited nodes are pushed onto the stack, when there are no nodes left to visit the nodes are popped off the stack.

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

what does a depth first graph traversal give us

A

Suitable solutions for game or puzzle problems

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

what does an inorder traversal tell us

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
what does an preorder traversal tell us
used to copy a binary tree return prefix expressions in RPN
26
what does an postorder traversal tell us
used to delete a binary tree outputting postfix expressions
27
What is meant by infix notation
Standard notation for where the operator is fixed between the operands : A + B
28
What is the problem with infix notation
It can be ambiguous without brackets.
29
What is reverse polish notation
An alternative to infix notation without ambiguity, where the operator comes after the two operands (postfix)
30
What are the three main reasons why RPN if so useful
Eliminates the need for brackets in sub-expressions Expressions are suitable for evaluation using a stack Can be used in interpreters based on a stack
31
How do we convert a infix expression into RPN
Store in a binary tree, take the first number and put it as a node when you come across a operator move up the tree and make it a central node, repeat Then By using a post order traversal, left right node
32
How can we evaluate a RPN using a stack
When you hit an operand push it onto the stack, when you hit an operator pop the last two items off the stack perform the calculation and push the result back onto the stack
33
What is a linear search algorithm
Linear search finds an item in a sorted or unsorted list by checking each item one by one
34
What are the advantages and drawbacks of the linear search algorithm
Doesn't require the data set to be in order Can be efficient for smaller data sets easy to implement Is inefficient for large data sets
35
What is a application of the linear search
find and replace function in a word processor
36
What is the time complexity of linear search algorithim
O(n)
37
What is a binary search algorithim
An efficient algorithm for finding an item in a sorted data list
38
What does a binary search require from a list in order to work
The list must be sorted
39
Describe how a binary search works
Midpoint of list is found, by performing integer division on the first and last index values added together Checks if midpoint is value we are looking for, if not then it checks if the value that it is looking for is larger or smaller In either case it halves the size of the data set and move to the midpoint of the top or lower half of the data set. Process is repeated until value is found or search range is empty
40
What is the time complexity of a binary search
O(log n)
41
What is a bubble sort algorithim (3)
A bubble sort orders an unordered list of items by comparing each item with the next on and swapping the items if they are out of order The algorithim is complete when there are no more swaps to be made In effect it bubbles the largest value to the end of the list hence the name.
42
why is the time complexity of the bubble sort O(n^2)
it uses two nested loops which could each iterate up to n times
43
What is the time complexity of the bubble sort
O(n^2)
44
What is the space complexity of the bubble sort
O(1)
45
What is the space complexity of the binary search
O(1)
46
What is the merge sort algorithim
A sorting algorithm which is very fast that carries out the following operation: Data set is repeatedly split in half until each item is in its own list Adjacent list sare then merged back together with each item being compared and sorted in the new combined list This process is repeated until new list is reconstructed
47
What are the applications of the merge sort
Works best with large data sets Ideal for parallel processing environments which are computing systems that perform multiple calculations or processes simultaneously
48
What is the time complexity of a merge sort
O(n log n)
49
why is the time complexity of a merge sort O( n log n)
n is the number of elements in the list log n comes from the number of recursive calls n is from the merging of the n lists
50
What is the space complexity of a merge sort
O(n)
51
What are the applications of Djikstras shortest path algorithim
chip design finding routes from one place to another web crawlers
52
Describe the operation of djikstras shortest path algorithm
Start with the source node and set its distance to 0, all others to ∞. Pick the closest unvisited node and update its neighbors’ distances if a shorter path is found. Mark the node as visited (processed). Repeat until all nodes are processed. At the end, you have the shortest path distances from the source to every node
53
what is the time complexity of djikstras shortest path algorithm and why is it that. (2)
O(v^2) This is because for each vertex, finding the minimum distance node takes O(V) time.
54
What are some applications of djikstras algorithim
Geographical maps application, towns = nodes, distances = edge weights
55
What is an algorithim
A specific sequence of stems that can be followed to complete a task that always terminates.
56
What is pseudocode
A text based way of representing steps in an algorithm
57
what is a binary search tree
A binary tree that maintains a specific order among its elements
58
what is a binary search tree characterized by: (4)
each node has at most two children left child node contains values less than the parent node right child node contains values greater than the parent node rule is applied to all nodes in the tree
59
describe what is meant by the binary tree search algorithm
Find out if a specific value exists in a binary search tree
60