Data Structures Final

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/39

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.

40 Terms

1
New cards

Sorting algorithms 2 methods

merge sort and quick sort

2
New cards

merge sort

divide and conquer methods that splits list into two halve, then sorts each side, then merges them back together

3
New cards

quick sort

finding pivot, then creating two subarrays: elements less than pivot, elements more than pivot.

4
New cards

best care quick sort

divides into equal halves (O(n log n))

5
New cards

average case quick sort

randomized pivot selection trying to balance sides (O(n log n))

6
New cards

worst case quick sort

when pivot is last or first element, or when all elements are the same (O(n²))

7
New cards

quick sort space complexity

recursive call stack(depth of recursion tree) (O(log n))

8
New cards

best/average/worst merge sort

always divides into two halves, good preformance regardless

9
New cards

merge sort space complexity

requires extra temporary arrray, not in-place like quick sort

10
New cards

Whats a heap

binary tree based data structure that fufills heap property/a complete binary tree:

  • Max-Heap: Parent node ≥ Children (root = max element).

  • Min-Heap: Parent node ≤ Children (root = min element).

  • Shape Property: Must be a complete binary tree (filled left to right).

11
New cards

How to store a heap

heaps are stored in arrays (left to right)

12
New cards

heapify procedure

fix a single violation in a heap tree. (compare parent with children, switch according to max or min heap, then recursively heapify)O(log n)

13
New cards

heapify insertion

increase heap size, add new element to last node (heapify upwards) O(log n)

14
New cards

Heap deletion

remove root max/min, replace with last node, heapify according to heap property

15
New cards

heapsort

comparison base sort using heap (build heap, repeatedly extract max/min and place at end, do so until max=ascending or min=decending

16
New cards

min heap

root node is minimum

17
New cards

max heap

root node is maximum

18
New cards

Binary tree

a tree that can have a max of 2 children

19
New cards

full binary tree

node is a leaf posesses two children

20
New cards

complete binary tree

all nodes have 2 children until last level, last level only have children on left side

21
New cards

perfect binary tree

all internal nodes havwe two leaves and leaves are all even. (N= 2^h – 1) N = nodes, h= tree height

22
New cards

Balanced binary tree

diffrence between HR and HL is not more than 1

23
New cards

in-order traversal

left→root→right

24
New cards

preorder traversal

root→left→right

25
New cards

postorder

left→right→root

26
New cards

BST

Binary search tree, has at most 2 children, left child is smaller than node, right value is larger than node

27
New cards

BST search

finding values using its sorted structure. Compare target with current node: h the current node:

  • If equal → Found!

  • If target < node value → Search left subtree.

  • If target > node value → Search right subtree.

28
New cards

BST insert

start at root, compared in BST form until null spot found

29
New cards

BST delete

no children - delete

1 child - replace node with its child

2 children - replace node with largest in left side or smallest in right side

30
New cards

Time complexity BST Worse case

O(h), h is binary tree height

31
New cards

Why are balanced binary trees good

automatically keeps height small so operation takes less time

32
New cards

AVL tree

self balancing tree

33
New cards

AVL insertion

same as BST

34
New cards

Hashing

changes data to fixed values for efficieny

35
New cards

Hash Function (modulo division)

way to map array keys to hash tables, ndex=key % TableSize

36
New cards

Collision

two different keys produce same hash value, pigeon hole = more keys than hash table slots means sharing must occur,

37
New cards

Linear probe

solution for collision, looks for next available slot sequentially

38
New cards

quadratic probe

sollution for collision, looks for next available slot using quadratic jumps

39
New cards

Double hashing

solution for collision, two hashing values are used to find one key, first is used to compute intital value, second is for computing step size for probing

40
New cards

chaining

solution for multiple collisions, implement array as linked list like chain