Fundamentals of algorithms

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What are the key features of the merge sort algorithm?

Very fast. Uses divide and conquer technique. Recursive.

What is the algorithm for pre-order traversal?

Visit the node. Recursion of pre-order traversal with the left node. Recursion of pre-order traversal with the right node.

On what sort of data set does binary search work for?

A sorted data set.

What is infix notation?

A way of writing mathematical expressions where the operators are in the middle of operands.

What are the 2 types of graph traversal?

Depth-first. Breadth-first.

Why is Reverse Polish notation better?

Easier for machines to interpret using stack. It is unambiguous (no need for brackets).

How does the binary search algorithm work?

Find the midpoint, check if its smaller or larger, then select the side in which it lies. Repeat this until the lower and upper bound are in the same position (i.e. found the item).

What is linear search?

Going one by one through a list checking if it is the value.

How are Reverse Polish notation expressions evaluated using stacks?

If the value is a number, it is pushed onto the stack. If the value is an operator, the top 2 values on the stack are popped off and operated on. The result is then pushed onto the stack. This procedure is followed until the stack has just one value left.

What is the time complexity of binary search?

O(log n).

What is the time complexity of the merge sort algorithm?

O(n log n).

What is the time complexity of linear search?

O(n).

What is the time complexity of the bubble sort algorithm?

O(n^2).

What are the 3 ways of traversing a binary tree and what are they?

Pre-order traversal - output on the left. In-order traversal - output beneath. Post-order traversal - output on right.

What is the algorithm for breadth-first graph traversal?

Push first vertex onto queue - mark as visited. Visit all unvisited vertices connected to vertex. Pop next vertex from queue. Visit all vertices connected. Push vertex onto queue.

What is the algorithm for depth-first graph traversal?

Push first vertex onto stack - mark as visited. unvisited Push vertex onto stack - mark as visited. If no next vertex to visit: pop vertex off stack. Else: repeat from step 2.

What data structure does a breadth-first graph traversal algorithm use?

Queue.

What is the algorithm for in-order traversal?

Recursion of in-order traversal with the left node. Visit the node. Recursion of in-order traversal with the right node.

What is the algorithm for post-order traversal?

Recursion of post-order traversal with the left node. Recursion of post-order traversal with the right node. Visit the node.

How does the merge sort algorithm work?

Split the whole data set repeatedly into individual data. Then merge each pair back together one by one in order.

What data structure do we use to evaluate Reverse Polish notation?

Stack.

What data structure does depth-first graph traversal algorithm use?

Stack.

What is depth-first graph traversal?

Start at start vertex and follow one branch as far as it will go, then backtrack and do the same.

What is breadth-first graph traversal?

Start at start vertex and scan each node connected and continue from left to right all the way down.

What are the 3 functions you need for a merge sort algorithm?

The master merge sort algorithm. The function to split lists. The function for merging 2 ordered lists.

What is prefix notation (Polish notation)?

Where operators are placed before operands.

What is postfix notation (Reverse Polish notation)?

Where the operators are placed after the operands.

Can you do some work with Dijkstra's shortest path?

Yes.

How would you convert an infix equation to a postfix (Reverse Polish) equation, such as 3*(1+2)?

You would first write the infix equation as a binary tree, where operands are the children, and the operators are the parent/root nodes. Then use post-order traversal to write the RPN form of the equation. For this example it would be 312+*.

How does the bubble sort algorithm work?

swapMade = False. Compares the first 2, if they are in they are in the wrong order then they are swapped and swapMade = True. This is done the algorithm gets to the end of the data set. If swapMade = True by the end, then everything is repeated until it runs through with swapMade = False. Then it is done.


Ensembles d'études connexes

Chapter 13: Reformations and Religious Wars Book Vocab

View Set

Biology- Cancer: Module 1 Homework

View Set

Cellular Respiration: Kreb's Cycle

View Set