algorithms Flashcards

1
Q

2 things to check when developing an algorithm

A

time complexity
space complexity

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

what is time complexity

A

how much it takes to solve a particular problem

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

what is time complexity measured in

A

using big-o notation

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

what does big o notation show

A

the effectiveness of an algorithm
show the time taken relative to the number of data elements given as an input

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

what is the benefit of big O notation

A

allows to predict the amount of time it takes for an algorithm to finish the given number of elements

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

define liner search algorithm

A

an algorithm that looks through every item one at a time until it finds the item its searching for

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

big o notation for linear search algorithm is

A

0 (n)

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

what is binary search algorithm

A

a divide and conquer algorithm, this means it splits the list into smaller lists until it finds the item its searching for

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

big o notation for binary search

A

0 ((log(n)

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

what is a bubble sort algorithm

A

Algorithm that passes through the list evaluating pairs of items and ensuring the larger value is above the smaller value

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

big o notation for bubble sort 0(n^2)

A

0(n^2)

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

big o notation for bubble sort 0(n^2)

A

0(n^2)

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

what is an algorithm,

A

a series of steps taken to complete a task

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

what is space complexity

A

the space complicity of an algorithm is the amount oof storage the algorithm takes (keep in sotairage is expensive )

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

big o notation for space complexity

A

(O(n))

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

In maths and Physics tutor look at BIG ON NOTAION DEFINITIOSN AND GRAPHS

A
17
Q

what does bubble sort do

A

makes ​comparisons and swaps ​between pairs of elements

18
Q

how does bubble sorting work

A

he algorithm starts at the first element in an array and compares it to the second. If they are in the wrong order, the algorithm ​swaps ​the pair. Otherwise, the algorithm moves on. other wise repeats process

19
Q

important note in bubble sort

A

one pass= the whole line being sorted I ascending order even if the first element aren’t correct
e.g the 1st pass may look like this
4,1,6,7,9
2nd pass= bubble sort reorder again from the beginning
e.g 1,4,6,7,9

20
Q

pseudocode for bubble sort

A

A = A​rray of data
for i = 0 to A.length - 1:
noSwap = True forj=0toA.length-(​j+2)​:
if A[j] > A[j+1]:
temp = A[j]
A[j] = A[j+1]
A[j+1] = temp
noSwap = False
if noSwap:
break
return A

21
Q

is bubble sort a fast algorithm

A

slow

22
Q

what is insertion sort

A

insertion sort ​places elements into a sorted sequence​.

23
Q

where does insertion sort start

A

rt ​starts at the second element ​in the input, and compares it to the element ​to its left​. If the two elements are in the wrong order, the smaller element is placed in the lowest position.

24
Q

things to note about insertion sort

A

if you have gotten to the 6 element of the list and it is smaller than all the first ones (although it has already. been sorted) it automatically goes to its correct position

25
Q

speudocode for insertion sort

A

A = A​rray of data
for i = 1 to A.length - 1:
elem = A[i]
j=i- 1
while j > 0 and A[j] > elem:
A[j+1] = A[j]
j = j -1 A[j+1] = elem

26
Q

pseudocode in bubble sort

A

n= items.Length
swapped = True
while n > 0 AND swapped
swapped = False
n = n - 1
For index = 0 TO n - 1
IF items [index] > items [index+1] then
Swap (items[index], items[index+1])
swapped = True
End If
End For
End while

26
Q

pseudocode in bubble sort

A

n= items.Length
swapped = True
while n > 0 AND swapped
swapped = False
n = n - 1
For index = 0 TO n - 1
IF items [index] > items [index+1] then
Swap (items[index], items[index+1])
swapped = True
End If
End For
End while

27
Q

bubble;e sort code in python

A

n=len (items)
swapped = true

while n > 0 and swapped ==true:
swapped = False
n=n-1
for index in range (0,n)
if items [index] > items [index+1]
temp = items [index]
items [index] = items [index+1]
items [index+1] = temp
swapped=true