fundamentals of algorithms Flashcards

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

what are the two types of ways to traverse a graph

A

depth first

breadth first

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

what is a graph

A

an abstract data type used to represent complex non linear relationships between objects using unordered set of nodes connected by edges

-

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

describe depth first traversal

A

starts at root and follows one branch as far as it can go

-used to navigate mazes

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

describe breadth first traversal

A

start at the root node and scan every connect node from left to right

-finds the shortest path of an unweighted graph

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

what are the steps of depth first traversal

A

Visit the root node and push it onto the stack.

Traverse on of the sub tree

Visit each unvisited node in the sub tree and push them onto the stack

When you get to a node with no other connections pop it of the stack

If needed continue popping of nodes until you get to one connected to unvisited nodes

When all the nodes are visited the visited array will show the order of traversal

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

what are the steps of breadth first traversal

A

Visit root node queue connected nodes

Visited= [A]

Queue=[B, D, E]

From right to left visit connected nodes

Dequeue each node as you visit its connected nodes

Enqueue connected nodes

Visited= [A,B]

Queue=[D, E,C]

Visited= [A,B,D]

Queue=[E,C ,F]

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

what abstract data type is used for depth traversal

A

a stack

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

what abstract data type is used for breadth traversal

A

a queue

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

what are searching algorithms for

A

they are used to search for specific items in a data set

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

what are 3 types of searching algorithms

A

linear search algorithm
binary search algorithm
binary tree search algorithm

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

what is the time complexity of the linear search algorithm

A

O(n)

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

what is the time complexity of binary search algorithm

A

O(logn)

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

what is the time complexity of the binary tree search algorithm

A

O(logn)

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

how does the linear search algorithm work

A

-Linear search works by inspecting every item in a list one by one until the desired item (the target) is found.

-If the target does not exist in the list, the algorithm will check every single item in the list
before finishing

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

how does the binary search algorithm work

A

-The first step is to take the middle piece of data

-To find the midpoint of the data, add the highest position and the lowest position of the array being considered, and divide
by 2.

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

what search algorithm is used for ordered lists

A

binary search algorithms

17
Q

what search algorithm is used for unordered lists

A

linear search algorithms

18
Q

how does the binary tree search algorithm work

A

they function the same as binary search algorithms but are just applied to trees

19
Q

what are sorting algorithms for

A

they are used to sort elements of an array into a specific order.

20
Q

what are the two types of sorting algorithms

A

bubble sort

merge sort

21
Q

what is the time complexity of the merge sort

A

O( n log n )

22
Q

what is the time complexity of the bubble sort

A

O(n^2)

23
Q

how does the bubble sort work

A

bubble sorts makes passes through the data and swaps adjacent items until no swaps can be performed

24
Q

how does the merge sort work

A

merge sorts split arrays into smaller lists and reform them using the divide and conquer method

25
Q

which sorting method is quicker

A

merge sort

26
Q

what is the purpose of the Dijkstra shortest path algorithm

A

to find the shortest path between a particular start node and all other nodes in a weighted graph