Algorithms Flashcards

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

What does Dijksta’s Algorithm do?

A

This method takes a lot of computing time but it will always calculate the fastest route

You first visit the starting Node,

You update the cost for each surrounding node,

You mark the current node as visited,

You visit the next smallest node

You keep doing this until you have reached your final destination

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

What is the A * Star Version do?

A

This method is more efficient, however it is not guaranteed to find the fastest route.

You take the halustic cost, which is the estimated cost and add it to the real cost to get the final cost, if the current cost you have for the final path is smaller than other predicted costs then you do not need to bother visiting them.

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

What is an Array?

A

Arrays hold multiple elements of data/ data types. So you cannot have a string and an integer in the same array. Data can be added and removed to the array, but the size cannot change. A 2d array is a list within a list.

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

How does a Stack work?

A

it Works on first in last out, like a stack of books.

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

How does a Queue work?

A

it Works on first in first out, like a queue of people.

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

What is Binary Search?

A

It’s a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array; if they are unequal, the half in which the target cannot lie is eliminated and the search continues on the remaining half until it is successful. If the search ends with the remaining half being empty, the target is not in the array.

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

What is Linear Search?

A

it’s a method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched

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

What is Bubble Sort?

A

It repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller or larger elements “bubble” to the top of the list.

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

What is Insertion Sort?

A

Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain.

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

What does Big-O do?

A

It measures efficiency of program by looking at space and time.

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

What does O(1) mean?

A

Constant Time

The program will execute in exactly the same amount of time regardless of the size of the data set

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

What does O(n) mean?

A

Linear Time

The value grows directly in proportion to the size of the data set in linear time, in most cases this will be a list.

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

What do O(n log n) and O(log n) mean?

A

Logarithmic Time

Execution time grows very slowly as the data set increases. Doubling the size of the data set has little effect on the time to complete

The base is taken to be 2 (changes in the base have little effect for Big O over very large data sets)

Divide and conquer algorithms where the list is halved on each permutation are O(log n)

Works the same as binary sort, overall decreasing time to search for an item depending on the size of the list / data set

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

What does O(n^2) mean?

n Squared

A

It is Polynomial time

Grows directly in proportion to the square of the size of the data set. For example where a loop is nested in a loop.

Deeper nested loops may be O(n^3)etc… Increasing time dramatically

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

What does O(2^n) mean?

2 to the power of n

A

It is Exponential Time

Execution time doubles with each item added to the data set. Execution time will very large very quickly

For practical purposes an algorithm within this time complexity would not be considered useful.

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

What does O(n!) mean?

A

It is Factorial Time

Execution time grows very, very quickly as the data set increases, even more than O

17
Q

What is the Worst Case Time Complexity for Linear Search?

A

O(n)

Linear

18
Q

What is the Worst Case Time Complexity for Binary Search?

A

O(log n)

Logarithmic

19
Q

What is the Worst Case Time Complexity for Bubble Sort?

A

O(n^2)

N Squared

Polynomial

20
Q

What is the Worst Case Time Complexity for Insertion Sort?

A

O(n^2)

N Squared

Polynomial

21
Q

What is the Worst Case Time Complexity for Merge Sort?

A

O(n log n)

Logarithmic

22
Q

What is the Worst Case Time Complexity for Quick Sort?

A

O(n log n)

Logarithmic