• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 3 out of 17 pages
Exam (elaborations)

Dsa Final Exam Questions And Answers

Document preview thumbnail
Preview 3 out of 17 pages

DSA FINAL EXAM QUESTIONS AND ANSWERS

Content preview

DSA FINAL EXAM QUESTIONS AND
ANSWERS

Complexity of Singly Linked-List: time complexity of search - Correct Answers -O(n) -
Worst case: element is at the end, Best case: element is at the beginning

Complexity of Doubly Linked-List: time complexity of search - Correct Answers -O(n) -
worst case: need to traverse whole list, best case: key is head or tail

Complexity of Singly Linked-List: time complexity of adding to head/tail - Correct
Answers -adding to head - O(1) - Same for both best and worst case
adding to tail - O(n) - traverse to tail

Complexity of Doubly Linked-List: time complexity of adding to head/tail - Correct
Answers -head - O(1) - more steps than singly, but same complexity
tail - O(1) - tail pointer

Complexity of Singly Linked-List: time complexity of removing from head/tail - Correct
Answers -head - O(1) - Same for both best and worst case
tail - O(n) - traverse to tail

Complexity of Doubly Linked-List: time complexity of removing from head/tail - Correct
Answers -head - O(1) - more steps than singly, but same complexity
tail - O(1) - tail pointer

Complexity of Both Linked-List: space complexity for storing n nodes - Correct Answers
-O(n) - Linear space complexity

Complexity of Stack and Queue: time complexity for pushing

Assume singly linked list based stack and doubly linked list based queue - Correct
Answers -O(1) - Same for both best and worst case = add head of linked list

Complexity of Stack and Queue: time complexity for popping

Assume singly linked list based stack and doubly linked list based queue - Correct
Answers -O(1) - Same for both best and worst case = remove list head (stack) or list tail
(queue)

Complexity of Stack and Queue: space complexity for storing n objects in linked-list
based implementation

,Assume singly linked list based stack and doubly linked list based queue - Correct
Answers -O(n) - linked list space complexity
*for array-based implementation, space depends on array size (may be > n).

Complexity of Hash Table DAT: time complexity for search - Correct Answers -O(1) -
constant time complexity

Complexity of Hash Table SC: time complexity for search - Correct Answers -O(m) - m:
size of the longest chain, often m = O(n)

Complexity of Hash Table LP: time complexity for search - Correct Answers -O(h) - h:
table size, not necessarily dependent on n

Complexity of Hash Table DAT: time complexity for insertion - Correct Answers -O(1) -
Same for both best and worst case

Complexity of Hash Table SC: time complexity for insertion - Correct Answers -if add
key to head - add to list head - O(1)
if add key to tail - add to list tail - O(m)
m: size of the longest chain

Complexity of Hash Table LP: time complexity for insertion - Correct Answers -worst
case - only empty cell is above so check h cells
- check if cell is empty (T1)
- update index to next cell (T2)
total probing time is (T1 + T2) * n + T1 = O(n)
- after probing, add to empty cell (T3 = O(1))
- total time = O(n) + O(1) = )(n+1) = O(n)
(at most check n + 1 cells before

Complexity of Hash Table DAT: time complexity for deletion - Correct Answers -O(1) -
Same for both best and worst case

Complexity of Hash Table SC: time complexity for deletion - Correct Answers -- search
for node ... time O(m)
- remove node = delete on linked list = O(1)

Complexity of Hash Table LP: time complexity for deletion - Correct Answers -first apply
search ... O(h) in worst case
then delete target node O(1)
total time is O(h + 1) = O(h)
h: table size

Complexity of Hash Table DAT: space complexity for storing n elements - Correct
Answers -O(h) - which is O(k) if h = k + 1

, k: largest key

Complexity of Hash Table SC: space complexity for storing n elements assuming table
stores pointer - Correct Answers -table of h pointers, each 1 space (h * M1)
n nodes outside the table, each
- key integer (M2)
- next pointer (M3)
- any satellite data (M4 in total)
- in total, (M2 + M3 + M4) * n
in total, h * M1 + n * (M2 + M3 + M4) = O(h + n)

h: table size

Complexity of Hash Table SC: space complexity for storing n elements assuming table
stores nodes only - Correct Answers -n nodes outside the table, each
- key integer (M2)
- next pointer (M3)
- any satellite data (M4 in total)
- in total, (M2 + M3 + M4) * n
in total, n * (M2 + M3 + M4) = O(n)

h: table size

Complexity of Hash Table LP: space complexity for storing n elements - Correct
Answers -- no matter how many nodes, we always need to maintain a table size of size
"h".
- assume each object consumes M1 space
- in total, consumes M1 * h = O(h) space

* Space does not necessarily depend on n. However, if we further assume the smallest
necessary table size (which is n), then h = O(n) and therefore space is O(h) = O(n).

Binary tree height h = ? - Correct Answers -h = O(n) = Ω(log 2 n)

Space complexity for list based binary tree - Correct Answers -each node object
consumes space M = M1 + 3*M2

M1: space for interger
M2: space for node pointer

a tree of n nodes consumes space n*M = n*(M1+3*M2) = O(n)

Space complexity for array based binary tree - Correct Answers -space = array size *
cell space
each array cell stores a node object, which consumes M space (same as list based)
array size = max node index + 1

Document information

Uploaded on
March 26, 2026
Number of pages
17
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$14.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
millyphilip
3.7
(560)
Sold
2991
Followers
1963
Items
46798
Last sold
4 days ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions