27.10.2014 Views

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Solutions</strong> to Chapter 16 | Low Level<br />

3 ns after a read begins. Uninteresting time segments are surrounded by [brackets]. Each<br />

character represents 1 ns.<br />

0 - 79 ns 80 - 99 ns 100 - 707 ns 708 - 723 ns<br />

Writer AAAABBBBCCCCDDDDEEEE XXXXYYYYZZZZ____<br />

Worker ____aaaaabbbbbcccccd opppppqqqqqrrrrr<br />

>= 724<br />

Queue<br />

11112221222222223222 3333333343333322 *<br />

Load<br />

Y = Writing word 159 @ 712 ns<br />

Z = Writing word 160 @ 716 ns<br />

q = Processing word 127 @ 714 ns<br />

r = Processing word 128<br />

* = Between 708 <strong>and</strong> 723 ns, <strong>the</strong> queue load is shown as 30 plus <strong>the</strong><br />

digit shown at each ns.<br />

Note that <strong>the</strong> queue load does in fact reach a maximum of 34 at time = 716 ns.<br />

As an interesting note, if <strong>the</strong> problem had required only 2 ns of <strong>the</strong> 5 ns processing time to<br />

complete a read, <strong>the</strong> optimal queue depth would decrease to 33.<br />

The below graphs are unnecessary, but show empirically that adding writes from <strong>the</strong> 3rd<br />

period does not change <strong>the</strong> queue depth required.<br />

< 796 ns 797 - 807 ns 808 - 873 ns 874 - 885 ns<br />

Writer ____AAAABBBB !!@@@@####$$<br />

Worker ^^^&&&&&**** yyyyyzzzzzaa<br />

Queue Load 877788778887 112111221122 *<br />

Writer<br />

Worker<br />

A = Writing word 161<br />

& = Processing word 144<br />

# = Writing word 181<br />

z = Processing word 160 @ 779 ns<br />

* = Between 874 <strong>and</strong> 885 ns, <strong>the</strong> queue load is shown as 20 plus <strong>the</strong><br />

digit shown at each ns.<br />

< 1112 ns 1112 - 1123 ns<br />

YYYYZZZZ____<br />

^^&&&&&%%%%%<br />

Queue Load 333343333322 *<br />

Z = Writing word 240 @ 1116 ns<br />

& = Processing word 207 @ 1114 ns<br />

* = Between 1112 <strong>and</strong> 1123 ns, <strong>the</strong> queue load is shown as 30 plus <strong>the</strong><br />

digit shown at each ns.<br />

ns<br />

CareerCup.com<br />

2 4 6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!