Divide & Conquer (Think Like a Programmer)
Vložit
- čas přidán 3. 08. 2016
- This video explores the "divide and conquer" technique of problem solving--mainly a recursive technique, so if you haven't watched it yet, I would start with my earlier video on recursion ( • Recursion (Think Like ... ). Also if you go to my publisher's site (link below), you can download the chapter in the Think Like a Programmer book for free.
Your comments and suggestions for future videos are welcome.
"Think Like a Programmer" is a book I've written to help programmers with problem solving. If you've found that you are able to read programs and understand programming language syntax but aren't always confident writing programs from scratch, my book may be able to help.
For more information on the book head to one of these:
Amazon page for the book: amzn.to/1MZlmlY
My site: www.vantonspraul.com/TLAP
My publisher's site: nostarch.com/thinklikeaprogrammer
Connect with me:
My site: vantonspraul.com
Twitter: / vantonspraul
Facebook: / thinklikeaprog - Věda a technologie
Thanks. I learned a lot from your videos. Your learning style is amazing!!
Unrelated to divide and conquer but a more efficient way to solve the exponential problem is to check binary bits of n, eg. n = 11 = 8 + 2 + 1, so we need x, x^2, x^8, you can update x = x * x at every iteration of looking at the smallest bit of n, and multiply the answer by the current base, then n = n >> 1.
Thank you... just learned pretty much trough your videos
thank you. i love ur way of teaching
Thank you for making these videos. I picked up your book a few weeks back and the videos go very well together. I hope you keep making great material!
Thank you! I'm glad you are enjoying them. I've been pretty busy of late, but I'm hoping to get some new stuff up soon.
I guess Im randomly asking but does any of you know of a way to get back into an instagram account??
I was stupid lost my account password. I appreciate any tricks you can offer me!
@Bobby Dylan instablaster =)
@Saul Layton i really appreciate your reply. I got to the site through google and I'm waiting for the hacking stuff now.
I see it takes quite some time so I will reply here later when my account password hopefully is recovered.
@Saul Layton It did the trick and I finally got access to my account again. I'm so happy:D
Thank you so much you really help me out :D
Could we make a helper function that would check if the starting power is odd? If odd then return (call to recursive function) * base? else return just the call to the recursive function by itself ?
Lifesaver! Thanks for this.
Helpful video. One thing though: I didn't quite get what you meant at 3:44 when you said we should store the "left" and "right" as local variables. Specifically, why would not doing this end up in us calling the recursive function twice?
Isnt Binary exponentiation the best method for calculating exponents of a number.
Thank you
Here's my attempt at the power function iteratively:
static int power(int number, int exponent) {
int answer=1;
int iterations = exponent;
while(iterations > 0) {
answer = answer * number;
iterations--;
}
return answer;
}
public static void main(String[] arg) {
int result = power(2, 0);
System.out.println(result);
int result = power(2, 5);
System.out.println(result);
}
Hi Anton! First i would like to say thxs for sharing these amazing videos!!t hey`ve helped me a lot!!.Is your book translated into spanish?! would be awesome!
You're welcome! Unfortunately, no, Think Like a Programmer has never been translated into Spanish. I'd like to see that happen, but the way translation deals work is, a publisher gets the rights to translate a book and market it in a particular area (for example, a Japanese publisher gets the rights to sell a Japanese language edition in Japan). I think a Spanish edition would be great if it could reach Spanish-speaking programmers wherever they are, but I don't know if there's a way to make that happen.
@@vantonspraul ok then! I'll buy the book in English, i just didn't want to miss anything ;-)... The chapter about recursion is very good!!! I can't wait to put it in practice! Thks again Anton
we can think easily on recursion by assuming that our first recursion call is going to give the answer ...
its normal to be more depressed after watching this playlist?
I certainly hope my videos do not induce depression.
@@vantonspraul your videos are not the peoblem i'm just to dumb to understand then
@@caiquemoa Oh, come on. If any of the concepts seem too advanced, just find a simpler place to start. If there's anything in particular that you have questions on, let me know.
if(arraySize == 0)
{
return array[0]
}
Ah yes... I also did this when I started programming... Actually - I didn't.
this is inspiring video for me to create interesting content for programming topics. I was trying for this, but not given good result enough on my channel. Maybe someone can give feedback to my videos ?...