Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
22 views

Programming Assignment Help

Get well commented code solutions for your programming assignments offered by expert programmers who will ensure you submit quality work on time. Visit https://www.programminghomeworkhelp.com/ and get your assignments done today.

Uploaded by

Hebrew Johnson
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Programming Assignment Help

Get well commented code solutions for your programming assignments offered by expert programmers who will ensure you submit quality work on time. Visit https://www.programminghomeworkhelp.com/ and get your assignments done today.

Uploaded by

Hebrew Johnson
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Submit Assignment For Help

GoGo
ToToAnswer
Code Directly
Directly
info@programminghomeworkhelp.com

Problem 4

Cache-oblivious median finding. Given an unordered array of N elements, develop and ana­
lyze a cache-oblivious algorithm to find the median of the array in O(IN/Bl) memory transfers.

Cache-oblivous queue. Develop and analyze a cache-oblivious FIFO queue. Both the enqueue
and the dequeue operation should take O(1/B) amortized memory transfers.

https://www.programminghomeworkhelp.com
Problem 4 Solution
Cache-oblivious median finding. The standard median of medians algorithm is already a
cache-oblivious algorithm meeting the desired bounds, so all the remains is to prove this can be
done in O(1) passes over the the array for a total of O(IN/Bl) memory transfers. The number of
memory transfers is then

T (N ) = T (N/5) + T (7N/10) + O(IN/Bl).

With a base case of T (B) = O(1) since once the list fits in a single line of cache, the median can
be found with a single memory transfer. T (N ) decreases geometrically from the root, down to
O((N/B)c) (c < 1) work at the leaves. Thus, T (N ) = O(IN/Bl).

Cache-oblivious queue. We will store the items in the queue sequentially in external memory
from an index head to an index tail. Initially, head = tail = 0. To enqueue an item, we store it at
index tail, and we add 1 to tail. To dequeue an item, we report the item stored at index head and
add 1 head. Assuming optimal cache behavior, and M/B ≥ 2, enqueue and dequeue clearly take
an amortized O(1/B) memory transfers per operation. This is because we can just keep the lines
containing head and tail in cache at all times so a memory transfer only occurs one out of every B
enqueues or dequeues.
To fix this, whenever 2 ∗ head > tail, we shift all the elements to the beginning of external
memory. This shift takes O(k/B) memory transfers, where k is the current size of the queue, and
we can charge it to the Ω(k) dequeues that must have occurred between it and the previous shift,
so we still have an amortized O(1/B) memory transfers per operation.

You might also like