2.3.1- algorithms

0.0(0)
studied byStudied by 0 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

18 Terms

1
New cards

2 considerations when developing an algorithm

  • time complexity

  • space complexity

2
New cards

what is time complexity and what notation does it use

time taken to solve a particular problem, shown using big-O notation

3
New cards

types of time complexities

  • constant time complexity 0(1)

  • linear time complexity 0(n)

  • polynomial 0(n²)

  • exponential 0(2^n)

  • logarithmic 0(logn)

4
New cards

worst to best time complexities

knowt flashcard image
5
New cards

what is depth first traversal for trees?

Go to the furthest node, and then backtrack (outputting the left/right child node first before outputting the current node) using a stack

-same as post order traversal

6
New cards

what is breadth first traversal?

visits current node before going to children (left first) that are directly connected to the current node using a queue

-traverses in layers

7
New cards

process of insertion sort

iterates over the length of the list times and sorts the first n items based on the nth iteration the program is on

-each item in the list is compared to the current items in the list (on left) and inserted into correct position

8
New cards

insertion sort code

knowt flashcard image
9
New cards

process of merge sort

mergeSort divides the input recursively until each sublist has length 1

merge sorts each sublist together until a final whole sorted list is produced

10
New cards

merge sort code

knowt flashcard image
11
New cards

process of quick sort

selecting a pivot of the list recursively and sorting smaller/larger elements on the left/right side of the pivot to form 2 new sublists

-re-repeats until all elements are old pivots (already sorted) or form lists of length 1 (nothing left to sort)

12
New cards

binary search code

knowt flashcard image
13
New cards

time complexity of binary search

O(log n)

14
New cards

2 pathfinding algorithms

dijkstra’s

A* algorithm

15
New cards

purpose and process of dijkstra’s algorithm

-finds the shortest path between 2 nodes in a weighted graph

-implemented using a priority queue (smallest distances from initial node moved to the front)

16
New cards

process of A* algorithm

Has two cost functions:

1) The first cost function is the actual cost between two nodes. This is the same cost as is measured in Dijkstra’s algorithm.

2) The second cost function is an approximate cost from node x to the final node. This is called a heuristic, and aims to make the shortest path finding process more efficient. The approximate cost might be an estimate of the length between x and the final node, calculated using trigonometry

17
New cards

process of finding an unbalanced tree and result on time complexity

from root node, calculate number of left nodes - number of right nodes

-any result that’s not +1, 0 , or -1 is unbalanced and is treated as a linear search

18
New cards

time complexity of DFS/BFS

O(n)