[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Computer Science Help

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 5
Thread images: 2

File: 1500355227884.jpg (244KB, 1485x1680px) Image search: [Google]
1500355227884.jpg
244KB, 1485x1680px
So, in my CS class we're working with Recursion. We were given 4 basic rules:

1. Base Case: You must always have a base case.
2. Making progress: Recursive calls must be simpler instances of the problem
3. Design Rule: Assume Recursive calls work
4. Compound Interest Rule: Never duplicate work by solving the same instances of the problem multiple times.

I don't really understand the 3rd and 4th rules much, could anyone give a better understanding of them?

Also, a little extra question, how do I go about rewritting an expression to another expression of the form 2^f(n)? For example, 1024 * 2^n be rewritten to the form 2^f(n)? Appreciate any help on either of these.
>>
>>372612
Is this data structures? I haven't read the textbook yet desu
>>
>>372622
Yep, Data Structures.
>>
>>372612
These are rules on making recursive functions, I assume. Let's use merge sort as an example.
1) The base case is one item, which is sorted by definition.
2) When you recurse, you're operating on 2 lists with half the size. The size always goes toward 1.
3) When you call merge sort on the left and right halves of a list, and you are creating the code for after the recursive calls return, remember that by definition, those two halves are sorted. This may seem obvious, but some people get confused trying to understand what's going on. It's kind of like a time loop in a movie. This rule (and rule 4) drive your method for constructing the actual solution - in this case, it means you can step through the two halves of the list in linear time to combine them into one. You should be able to articulate how to construct a combined solution given partial solutions, if your procedure actually makes sense to do recursively.
4) This one seems self-explanatory. For merge sort, it means we would never have overlapping lists. A call that operated on indices 0-5 and 5-9, for instance, is performing extra work because index 5 is included in both lists.

As for your second question, I think you can log (base 2) both sides to solve for f(n).
log_2(2^f(n)) = f(n).
log_2(1024*2^n) = log_2(1024) + log_2(2^n) = 10 + n.
I'm sure it gets trickier for other expressions, but that's the idea.
>>
File: IMG_1331.jpg (44KB, 620x346px) Image search: [Google]
IMG_1331.jpg
44KB, 620x346px
>>372635
Ah, I understand now. Thanks anon, you saved my bacon.
Thread posts: 5
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.