일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
- HEAPS
- 데이터 분석가
- Computer Science
- 빅데이터 커리어 가이드북
- Linked List
- Heap
- Newyork
- Preparing for the Google Cloud Professional Data Engineer Exam
- dataStructure
- Algorithms
- binary search tree
- Study
- data
- Data Analyst
- Computer Organization
- exam
- 빅데이터 지식
- hash
- priority queue
- 화장실 지도
- data scientist
- 뉴욕 화장실
- Binary Tree
- 데이터 엔지니어
- BST
- Data Structure
- Restroom
- Data Engineer
- algorithm
- 빅데이터
- Today
- Total
Jaegool_'s log
IT279: Algorithm and Data Structures Recap 2/3 본문
HeapSort
Step1: Heapify O(n)
Step2: n-1 deleteMax operations O(log n) = (n-1) * O(log n)
total: O(n log n)
advantages:
Guaranteed O(n log n)
Space cost of n + 1
disadvantages:
Higher overhead than other n log n sorts
Not a stable sort
ShellSort
avg: O(n(logn)^2)
worst: O(n^2)
inspection gap is reduced at each stage
MergeSort
We have two sorted lists of equal length.
The length is n. What is the time required to merge the two lists into a single sorted list? O(n)
number of division : O(log n)
What is the worst-case running time for mergesort? O(n log n)
10 6 3 5 12 20 4 15 2 11 13 1
Merge Sort: break, sort, merge
10 6 3 5 12 20 / 4 15 2 11 13 1
3 5 6 10 12 20 / 1 2 4 11 13 15
(1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 15, 20)
Top-Down MergeSort (use more memory)
10 6 3 5 12 20 / 4 15 2 11 13 1
10 6 3 / 5 12 20 / 4 15 2 11 13 1
10 6/ 3 / 5 12 20 / 4 15 2 11 13 1
10 / 6 / 3 / 5 12 20 / 4 15 2 11 13 1
6 10 / 3 / 5 12 20 / 4 15 2 11 13 1
3 6 10 / 5 12 20 / 4 15 2 11 13 1
3 6 10 / 5 12 / 20 / 4 15 2 11 13 1
3 6 10 / 5 12 20 / 4 15 2 11 13 1
3 5 6 10 12 20 / 4 15 2 11 13 1
keep doing merge sort on right side.
Bottom-up Mergesort
(6, 10) (3, 5) (12, 20) (4, 15) (2, 11) (1, 13)
(3, 5, 6, 10) (4, 12, 15, 20) (1, 2, 11, 13)
(3, 4, 5, 6, 10, 12, 15, 20) (1, 2, 11, 13)
(1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 15, 20)
QuickSort
select pivot
compare i(from left) and j(from right) with the pivot and swap(i stop when bigger than pivot and j will stop when smaller than pivot)
if i and j counters cross each other swap i and pivot. The pivot is in place at the time.
Then we have the left and right partition divided by the pivot.
The next pivot is the rightmost of the left partition (the left side of the previous pivot.)
time complexity: O(n log n)
Very low overhead
Space cost of only n + 1
Worst case: Performance on presorted data & reverse data: n^2
Improved QuickSort: if partition length <= the cutoff, insertion sort it
Improved Pivot Selection: Median of 3
sort the first, mid, and last elements and swap the middle element with the next-to-last element(now the pivot)
Performance: guaranteed O(n log n) for sorted or reverse data
- pivot is the middle element
Slight constant increase in time to select the pivot
Disjoint Sets(Union-Find)
A root is a negative int in Disjoint Sets.
Union:
- locate the root of each tree
- Point the root of the second argument's tree at the root of the first argument's tree
- Union should only be done after confirming that the items are in different sets
- Union by size vs Union by height
Path Compression: when we do a find all the elements in the path will point to the root. O(1)
Should not be used with union by height.
if array[index] < 0
return index
else
return find(array[index])
Graph
representation: Adjacency matrix & Adjacency list
topological ordering: queue(we push 0 indegree vertex in the queue) & indegree array
Breadth First Search: finding shortest paths in unweighted graphs
- Queue(From, to, Cost)
- Path and Costs Array
Dijkstra's algorithm
- Path and Cost Arrays + priority queue(from, to, cost)
- greedy algorithm: smallest path cost
basic(V^2) vs using priority queue((V+E) log v)
Prim's algorithm
- Edge and Cost Array + priority queue
Very similar to Dijkstra's using a priority queue
The focus is not on paths but on the cost of the individual edge
Pick a starting vertex
Add edges to our priority queue only if the other vertex is not yet part of our tree.
Stop when everything is in the tree
- or the priority queue is empty - meaning we don't have a connected graph
Kruskal's algorithm
- Disjoint Set Array + Edge List
Sort the edges of the tree
Start out with a forest of trees - each with one vertex
Until we're down to one tree (or out of edges)
- if the vertices for the next edge in the list are not in the same tree
- Add that edge to the minimum spanning tree
- connect the two trees
Use disjoint sets where vertices are the objects in the sets
Use union by size to facilitate recognizing when the tree is complete
'Courses' 카테고리의 다른 글
IT279: Algorithm and Data Structures Recap 3/3 (0) | 2023.12.12 |
---|---|
IT279: Algorithm and Data Structures Recap 1/3 (1) | 2023.12.10 |
IT 279: Algorithms and Data Structure EXAM2 prep (0) | 2023.11.06 |
IT 279: Algorithms and Data Structures, Week 6 Heap (1) | 2023.10.05 |
IT 279: Algorithms and Data Structures, Week 5 Hash Tables (1) | 2023.10.05 |