Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need an explanation on this. What is S_n? What is the average cost? You already have determined the kthresize cost ( Ox) before. And,
I need an explanation on this. What is S_n? What is the average cost?
You already have determined the kthresize cost ( Ox) before. And, the kth resize cost ( Ox) is also N equal to because the array capacity will double to achieve a size of N and there would be half 2 that number of existing elements to copy to the new array. Putting the two together, you will find out the value of k in terms of N. [Some of you may have noticed that when discussing the total write cost, which is the size of the array, we say that it's N. And now, when discussing Sn, we say that ax = N/2, equating N with the capacity. As N increases, the ratio of capacity to the size varies between 1 and 2 - just before a resize, they're the same, and just after a resize the capacity is twice the size. Sn is the same for any values between resizes (between terms of the geometric sequence), so we could assign to ak any value from N/2 to N. Since the difference is a constant factor, it doesn't affect the big-0, and so we choose N/2 because it makes the algebra come out more neatly.] Now, use the k and sum equation above (Sy) to derive the total copy cost for the given Nappends: SN Recall that total cost = total write cost (Sw) + total copy cost (Sy). As we have conducted N appends, the average cost can be derived from: {Sw + Sy} N This gives us an amortized complexity of O(). You already have determined the kthresize cost ( Ox) before. And, the kth resize cost ( Ox) is also N equal to because the array capacity will double to achieve a size of N and there would be half 2 that number of existing elements to copy to the new array. Putting the two together, you will find out the value of k in terms of N. [Some of you may have noticed that when discussing the total write cost, which is the size of the array, we say that it's N. And now, when discussing Sn, we say that ax = N/2, equating N with the capacity. As N increases, the ratio of capacity to the size varies between 1 and 2 - just before a resize, they're the same, and just after a resize the capacity is twice the size. Sn is the same for any values between resizes (between terms of the geometric sequence), so we could assign to ak any value from N/2 to N. Since the difference is a constant factor, it doesn't affect the big-0, and so we choose N/2 because it makes the algebra come out more neatly.] Now, use the k and sum equation above (Sy) to derive the total copy cost for the given Nappends: SN Recall that total cost = total write cost (Sw) + total copy cost (Sy). As we have conducted N appends, the average cost can be derived from: {Sw + Sy} N This gives us an amortized complexity of O()Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started