• 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 1 out of 2 pages
Exam (elaborations)

DSA Quiz 11 Questions and Answers

Document preview thumbnail
Preview 1 out of 2 pages

Exam of 2 pages for the course DSA at DSA (DSA Quiz 11)

Content preview

DSA Quiz 11

What is the overall structure of a heap? - answer Elements are stored first on the left,
and leaves are only on the last and second to last layer. For min heaps, children's
values are >= their parent's values. For max heaps, children's values are <= their
parent's values

In a list, what is the index of the root? - answer list[0]

In a list, what is the index of a node's left child? - answer2 * current index

In a list, what is the index of a node's right child? - answer (2 * current index) + 1

In a list, what is the index of a node's parent? – answer Math. Floor(current index / 2)

Why is it preferred to use an array for a binary heap? - answer Saves space (No need
to store pointers, arrays are more compact in memory), Saves time (*2 /2 operations are
faster than dereferences), Parent is easy to locate (free parent "pointer")

What does the push(T data) method do in binary heaps? - answer Adds data to the
heap

What does the poll() method do in binary heaps? - answer Remove next priority item in
the heap

What does the peek() method do in binary heaps? - answerReturn the value of the root

What is the time complexity of push? - answerworst: O(log n) average: O(1)

What is the pseudocode of push? - answer-Add element to the bottom level of the heap
while maintaining the shape property,
-Compare value of element with parent value, if it's in correct order, stop.
- If not in correct order, swap with parent and keep comparing until in correct place (This
is known as percolateUp)

How many of the elements are leaves? - answerHalf

What is the average number of checks for per insert for push? - answer2

What is the pseudocode of poll in a heap? - answer-Remove the root
- Make the last element in the 1D array the new root

Document information

Uploaded on
August 29, 2024
Number of pages
2
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$12.49

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.
Dreamer252
4.0
(117)
Sold
497
Followers
297
Items
21575
Last sold
1 month 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