CSI

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

1/38

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.

39 Terms

1
New cards

Best to Worst Time Complexities

O(1), O(log n), O(n), O(n log n), O(n²), O(2^n), O(n!)

2
New cards

Linear Search Time Complexities: Best to Worst

O(1), O(n), O(n)

3
New cards

Binary Search Time Complexities: Best to Worst

O(1), O(log n), O(log n)

4
New cards

Insertion Sort Time Complexities: Best to Worst

O(n), O(n²), O(n²)

5
New cards

Merge Sort Time Complexities: Best to Worst

O(n log n), O(n log n), O(n log n)

6
New cards

Quicksort Time Complexities: Best to Worst

O(n), O(n log n), O(n²)

7
New cards

3 types of errors

Syntax, runtime, semantic (bad mental)

8
New cards

Dataclasses

from dataclasses import dataclass

9
New cards

Concatenations (+)

Only works with like types. Concatenation does not change the original variable

10
New cards

Lists (functions)

pop() and insert(). These are destructive, they permanently modify the list

11
New cards

Extending (+=)

Modifies the original variable

12
New cards

Tokens

Each element of a split string. A list of substrings. The original string is not modified. Delimiter is what string is in the split parentheses

13
New cards

Values Types

int, float, bool

14
New cards

Passing by Value

When a value type is passed in as an argument to a function, a copy is made. Changes made to the copy in the function have no permanent effect

15
New cards

Reference Types

lists, dictionaries, sets

16
New cards

Passing by Reference

When a reference type is put in the argument of a function, the original value is referenced and can be changed from the function. The changes are permanent, and not a copy

17
New cards

Create a new list: Big-O

O(n)

18
New cards

append(): Big-O

O(1)

19
New cards

pop(x) or insert(x)

O(n)

20
New cards

pop(-1) or insert(-1)

O(1)

21
New cards

Concatenate (+)

O(n)

22
New cards

Extend n elements

O(n)

23
New cards

Linear Search

Begins at 0 and increases by 1. Compares each value at the index to the target. It returns the found index or None.

24
New cards

Binary Search

Begins looking at the midpoint. If the length is even, it looks at the left element. If the element at the midpoint is greater than the target, the target must be on the left side of the midpoint. If the element is less than the target, it must be on the right of the midpoint. It’s a divide-and-conquer algorithm

25
New cards

Linear Search Code

def linearsearch(arr, target):

for i in range(len(arr)):

if arr[i]==target:

return i

return None

26
New cards

Binary Search Code

def binarysearch(arr, target)

left = 0

right = len(arr)-1

while left<=right:

mid = (left+right)//2

if arr[mid] == target:

return mid

if arr[mid] < targetL

left = mid+1

else:

right = mid-1

return None

27
New cards

Insertion Sort

Divide the array into sorted and unsorted. The left element of unsorted moves to the right of sorted, then starts swapping with neighbors of sorted.

28
New cards

Insertion Sort Code 1

def insertionsort(list):

llist = len(list)

for i in range(1, llist):

insert_index = i

current_value = list[i]

for j in range(i-1, -1, -1):

if list[j] > currentvalue:

list[j+1] = list[j]:

insert_index = j

else:

break

list[insert_index] = current_value

29
New cards

Insertion Sort Code 2

def insert(list, mark):

index = mark

while index > -1 and list[index] >list[index+1]:

swap(list, index, index+1)

index = index-1

def insertionsort(list):

for mark in range(len(list)-1):

insert(list, mark)

30
New cards

Merge Sort

recursively splits the list in half until the length is one, then merges it back together in sorted order. It’s a divide-and-conquer method. It merges small lists together by comparing the first elements in each

31
New cards

Merge Sort Code

def merge(left, right):

sorted_list = []

i = 0

j = 0

while i <len(left) and j <len(right):

if left[i] <right[j]:

sorted_list.append(left[i])

i+=1

else:

sorted_list.append(right[j])

j+=1

sorted_list.extend(left[i:])

sorted_list.extend(right[j:])

return sorted_list

def merge_sort(arr):

if len(arr) <=1:

return arr

mid = len(arr)//2

left_half = merge_sort(arr[:mid])

right_half = merge_sort(arr[mid:])

return merge(left_half, right_half)

32
New cards

Open addressing

Will look for the next open address to put store the value

33
New cards

Chaining

appends the value to the address (making it a list in the values.

34
New cards

Quick sort

Divide-and-conquer method. Pivot value is usually at index 0. Divides the list into three partitions. elements less than pivot, elements equal to pivot, and elements greater than pivot. it sorts smaller lists and merges them back together in sorted order

35
New cards

.sort()

destructive in-place sort

36
New cards

.sorted()

creates a sorted copy

37
New cards

Hash Function

Given an arbitrary input value, produces a number as output. The output is called hash code. Not all types in Python are hashable. A set is a hashing data structure

38
New cards

Indexing function

Makes the hashed code smaller to fit into a smaller array.

39
New cards

Any, Union

from typing import Any, Union