মূল বিষয়বস্তু
কম্পিউটার বিজ্ঞান
কোর্স: কম্পিউটার বিজ্ঞান > অধ্যায় 1
পাঠ 6: রিকার্সিভ অ্যালগোরিদম- রিকার্শন
- উৎপাদক ফাংশন
- চ্যালেঞ্জ: পুনরাবৃত্তিমূলক উৎপাদক
- রিকার্সিভ উৎপাদক
- চ্যালেঞ্জ: রিকার্সিভ উৎপাদক
- রিকার্সিভ অ্যালগোরিদমের বৈশিষ্ট্য
- একটি শব্দ প্যালিনড্রোম শব্দ কিনা তা রিকার্শন ব্যবহার করে নির্ধারণ করা
- চ্যালেঞ্জ: একটি স্ট্রিং কি একটি প্যালিনড্রোম?
- একটি সংখ্যার ঘাত হিসাব করা
- চ্যালেঞ্জ: রিকার্সিভ ঘাতসমূহ
- সিয়েরপিন্সকি গ্যাসকেট
- প্রকল্প: রিকার্সিভ কলা
© 2023 Khan Academyব্যবহারের শর্তাদিগোপনীয়তার নীতিমালাকুকি নোটিশ
একটি সংখ্যার ঘাত হিসাব করা
যদিও জাভাস্ক্রিপ্ট-এ একটি
pow
ফাংশন রয়েছে যা একটি নম্বরের সূচক গণনা করে, তুমি একই রকমের ফাংশনকে পুনরাবৃত্তিতে লিখতে পার এবং এটি খুব কার্যকর হতে পারে। একমাত্র বাধা হল যে সূচকটি একটি পূর্ণসংখ্যা হতে হবে।ধর তুমি গণনা করতে চাও , যেখানে যেকোন বাস্তব সংখ্যা এবং কোনো পূর্ণসংখ্যা। এটা খুবই সহজ হয় যদি এর মান 0 হয়, যেহেতু যা এর যেকোনো মানের জন্যই প্রযোজ্য। এটা বেস কেস হিসেবে ধরা যায়।
So now let's see what happens when is positive. Let's start by recalling that when you multiply powers of , you add the exponents: for any base and any exponents and . Therefore, if is positive and even, then . If you were to compute recursively, then you could compute as . What if is positive and odd? Then , and either is 0 or is positive and even. We just saw how to compute powers of when the exponent either is 0 or is positive and even. Therefore, you could compute recursively, and then use this result to compute .
What about when is negative? Then , and the exponent is positive, since it's the negation of a negative number. So you can compute recursively and take its reciprocal.
এইসব পর্যবেক্ষণগুলোকে একসাথে করলে, গণনা করার জন্য আমরা নিম্নলিখিত পুনরাবৃত্তমূলক অ্যালগরিদমটি পাই:
- The base case is when
, and . - If
is positive and even, recursively compute , and then . Notice that you can get away with making just one recursive call in this case, computing just once, and then you multiply the result of this recursive call by itself. - If
is positive and odd, recursively compute , so that the exponent either is 0 or is positive and even. Then, . - If
is negative, recursively compute , so that the exponent becomes positive. Then, .
এই বিষয়বস্তুটি Dartmouth Computer Science এর প্রফেসর Thomas Cormen এবং Devin Balkcom এর সহযোগিতায় এবং একই সাথে খান একাডেমির কম্পিউটিং শিক্ষাক্রম দলের একসাথে কাজ করার মাধ্যমে তৈরি করা হয়েছে। এই বিষয়বস্তু CC-BY-NC-SA দিয়ে লাইসেন্সকৃত।
আলোচনায় অংশ নিতে চাও?
কোন আলাপচারিতা নেই।