Algorithmic Complexity

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

HashMap (Add and Get)

Should be O(1) for all but worst case, which is O(n).

Array (Search-Unsorted)

WC and AC O(n)

Array (Insert & Deletion)

WC and AC: O(n). Should be O(1) in the best case, if you don't need to resize or shift.

Prim's Algorithm

n = # of nodes m = # of edges O(m + n log n) for adjacency list. O(n^2) for adjacency matrix.

Adjacency Matrix

n = # of vertices Uses space O(n^2) Enumerates all edges in time O(n^2) Answers "Does x have an edge to y?" in O(1) Better for dense graphs.

Adjacency List

n = # of vertices m = # of edges Uses space O(m + n) Enumerate all edges in O(n+m) Answers "Is there an edge from x to y?" in O(d(u)). Better for sparse graphs.

Array (Access)

All Cases O(1)

Merge Sort

All Cases O(n log n)

Priority Queue (Peek)

All Cases: O(1)

Array (Search-Sorted)

All cases O(log n), because we're doing binary search.

Selection Sort

All cases are O(n^2)

Quicksort

Average Case O(n log n) Worst Case O(n^2)

Bubble Sort

BC O(n) WC and AC O(n^2)

HashMap (Contains)

BC and AC O(1). Worst case O(n), if absolutely everything got hashed to the same bucket and you have to search a linked list.

Binary Search Tree (Add / Remove)

BC and AC O(log n). WC O(n)

Binary Search Tree (Access / Search)

BC and AC O(log n). Worst case O(n), if all the left fields are empty and its essentially a linked list.

Insertion Sort

BC: O(n) WC and AC: O(n^2)

Stack and Queue (Add / Remove)

O(1)

Doubly Linked List (Add)

O(1) for head and tail, and O(n) for middle of the list.

Singly Linked List (Add and Remove)

O(1) for the head, and O(n) for everything else, because you would have to search to find it.

Priority Queue (Add)

O(log n)

Priority Queue (Poll)

O(log n)

Priority Queue (Remove)

O(log n). This is not poll, we are removing something other than the head.

Heap Sort

O(n log n) all cases.

Priority Queue (Contains)

O(n)

Singly Linked List (Search)

O(n)

Dijkstra's Shortest Path:

O(n^2 log n) for a dense graph. O(n log n) for a sparse graph.


Kaugnay na mga set ng pag-aaral

HZ - Chapter 8 Incident Command System and Action Plan Implementation

View Set

ATI Learning System RN 3.0 Med Surg Cardiovascular and Hematology Dynamic Quiz

View Set

The Logic of American Politics: Chapter 13 Quiz

View Set

Chapter 38: Corporations - Formation and Financing

View Set

Algebra Unit 0 & 1 Semester 1 Exam Review Solving Equations and Inequalities

View Set

8.1 The Structure of Financial Markets and Financial Assets

View Set