Data Structures and Algorithms: Time Complexities for Arrays, Linked Lists, Stacks, Queues, and Hash Tables

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

1/37

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

38 Terms

1
New cards

What is the worst-case time complexity for inserting into an unordered array?

O(1) (amortized)

2
New cards

What is the worst-case time complexity for finding an element in an unordered array?

O(n)

3
New cards

What is the time complexity for deleting an element from an unordered array?

O(n)

4
New cards

Why is array insertion marked as O(1) (amortized)?

Because actual insertion is O(1), but resizing or finding the position can take longer.

5
New cards

What is the time complexity of inserting at the head of a singly linked list?

O(1)

6
New cards

What is the time complexity of inserting at the tail of a singly linked list (with tail pointer)?

O(1)

7
New cards

What is the time complexity of finding an element in a singly linked list?

O(n)

8
New cards

What is the time complexity of deleting an element in a singly linked list?

O(n)

9
New cards

What is the time complexity of insertion in an ordered array (linear search)?

O(n)

10
New cards

What is the time complexity of searching in an ordered array using linear search?

O(n)

11
New cards

What is the time complexity of searching in an ordered array using binary search?

O(log n)

12
New cards

What is the time complexity of deletion in an ordered array?

O(n)

13
New cards

What is the time complexity of insertion in an ordered singly or doubly linked list?

O(n)

14
New cards

What is the time complexity of searching in an ordered linked list?

O(n)

15
New cards

What is the time complexity of push, pop, and peek in an array-based stack?

O(1) (push is amortized O(1))

16
New cards

What is the time complexity of push, pop, and peek in a linked-list-based stack?

O(1)

17
New cards

Why is stack not created for searching?

Because stacks are LIFO — only top access is allowed.

18
New cards

What is the enqueue complexity for an array-based queue?

O(1) (amortized)

19
New cards

What is the dequeue complexity for an array-based queue?

O(n)

20
New cards

What is the enqueue and dequeue complexity for a circular array queue?

O(1)

21
New cards

What is the enqueue and dequeue complexity for a linked-list-based queue (with tail pointer)?

O(1)

22
New cards

What is the dequeue complexity for a linked-list-based queue (without tail pointer)?

O(1)

23
New cards

What is the time complexity of hash table insert/find/delete (average case)?

O(1)

24
New cards

What is the time complexity of hash table insert/find/delete (worst case)?

O(n)

25
New cards

What algorithm is reminiscent of BFS, but adapted to handle weights?

Dijkstra's Algorithm

26
New cards

What does Dijkstra's Algorithm do?

Find the single-source shortest paths in a weighted graph

27
New cards

What causes an error in Dijkstra's algorithm?

negative-weight edges

28
New cards

In Dijkstra's Algorithm, what is better for a sparse graph?

Priority Queue, O(|V|log|V| + |E|log|V|)

29
New cards

In Dijkstra's Algorithm, what is better for a dense graph?

O(|V|^2)

30
New cards

What algorithm's idea is to grow a forest of edges that does not form a cycle but also considers the edges in order by weight?

Kruskal's Algorithm

31
New cards

What algorithm's idea is to grow a tree by adding an edge from the "known" vertices to the "unknown" vertices, picking the edge with the smallest weight that connects "known" to "unknown."

Prim's Algorithm

32
New cards

What is the run time for Prim's?

O(|E|log|V|) (same as Dijkstra)

33
New cards

What is the time complexity of Kruskals?

O(ElogV)​

34
New cards

Adjacency Matrix or List, which is better for dense graphs?

Adjacency Matrix

35
New cards

Adjacency Matrix or List, which is better for sparse graphs?

Adjacency List, so usually just stick with linked list

36
New cards

What algorithm is used for a DAG, so that no vertex appears before another vertex?

Topological Sort

<p>Topological Sort</p>
37
New cards

What is the worst case run time for topo sort?

O(|E| + |V|) so if dense then O(|V|^2)

38
New cards

What is the worst-case time complexity of union find with path compression?

O(m a(n))​

Explore top flashcards

October exam
Updated 465d ago
flashcards Flashcards (32)
10/6
Updated 218d ago
flashcards Flashcards (62)
PSCH 262 Final Exam
Updated 634d ago
flashcards Flashcards (110)
WWII
Updated 4d ago
flashcards Flashcards (35)
October exam
Updated 465d ago
flashcards Flashcards (32)
10/6
Updated 218d ago
flashcards Flashcards (62)
PSCH 262 Final Exam
Updated 634d ago
flashcards Flashcards (110)
WWII
Updated 4d ago
flashcards Flashcards (35)