Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831
{"id":14458,"date":"2015-05-06T21:59:49","date_gmt":"2015-05-07T02:59:49","guid":{"rendered":"https:\/\/mitzihernandez.withknown.com\/2015\/mastery21-tc1017"},"modified":"2015-05-06T21:59:49","modified_gmt":"2015-05-07T02:59:49","slug":"mastery21-tc1017-3","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101winter2015\/2015\/mastery21-tc1017-3\/","title":{"rendered":"#mastery21 #TC1017"},"content":{"rendered":"
\n

#mastery<\/a>21 #TC<\/a>1017<\/span><\/span><\/p>\n

\u00a0<\/p>\n

Use of recursion for repetitive algorithms<\/span><\/p>\n

What is recursion? The simple answer is, it\u2019s when a function calls itself. But how does this happen? Why would this happen, and what are its uses?<\/p>\n


When we talk about recursion, we are really talking about creating a loop. <\/span><\/span>Let\u2019s start by looking at a basic loop.<\/span>

<\/span><\/p>\n\n\n\n
\n

#a0a0a0; mso-fareast-language: ES-MX;”>1
2
3<\/span><\/p>\n<\/td>\n

#C0C0D0 1.0pt; mso-border-alt: solid #C<\/a>0C0D0 .75pt; background: #EFEFFF; padding: .75pt .75pt .75pt .75pt;” valign=”top”><\/p>\n

for<\/span>(<\/span>int<\/span> i=0;\u00a0 i<\/span><\/p>\n

\u00a0\u00a0\u00a0\u00a0 cout “The number is: “<\/span> <\/span><\/span><\/p>\n

}<\/span><\/p>\n<\/td>\n

\u00a0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\n

For those who don\u2019t yet know, this basic loop displays the sentence, “The number is: ” followed by the value of \u2018i\u2019. <\/span><\/span>Like this.<\/span><\/p>\n\n\n\n
#E7E7E7; padding: .75pt .75pt .75pt .75pt;” valign=”top”><\/p>\n

\u00a0<\/span><\/p>\n

The number is: 0<\/span><\/p>\n

The number is: 1<\/span><\/p>\n

The number is: 2<\/span><\/p>\n

The number is: 3<\/span><\/p>\n

The number is: 4<\/span><\/p>\n

The number is: 5<\/span><\/p>\n

The number is: 6<\/span><\/p>\n

The number is: 7<\/span><\/p>\n

The number is: 8<\/span><\/p>\n

The number is: 9<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n


Inside the \u2018for loop\u2019 declaration we have the integer variable \u2018i\u2019 and have its starting value of 0. So the first time the sentence is displayed it reads, “The number is: 0”. The part of the \u2018for loop\u2019 declaration that is \u2018i++\u2019 tells the program that each time the loop repeats, the value of \u2018i\u2019 should be increased by 1. So, the next time the sentence is displayed it reads, “The number is: 1”.<\/span>
This cycle will continue to repeat for as long as the value of \u2018i\u2019 is less than 10. The last sentence displayed would read, “The number is: 9”. As you can see the basic \u2018for loop\u2019 has three parts to its declaration, a starting value, what must remain true in order to continue repeating, and a modifying expression. Everything that is contained within the {braces} is what the program performs. Cout stands for console out, and prints words or characters to the screen.<\/span>
So what does this have to do with recursion? Remember recursion is a loop. What if I did not want to just print a message to the screen? A loop can be used to perform other tasks as well.<\/span><\/p>\n

In the following code is the same loop as above only now it is being used to call a function.<\/span>

<\/span><\/p>\n\n\n\n
\n

#a0a0a0; mso-fareast-language: ES-MX;”>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15<\/span><\/p>\n<\/td>\n

#C0C0D0 1.0pt; mso-border-alt: solid #C<\/a>0C0D0 .75pt; background: #EFEFFF; padding: .75pt .75pt .75pt .75pt;” valign=”top”><\/p>\n

#include<\/a> <\/iostream><\/span><\/p>\n

using<\/span> namespace<\/span> std;<\/span><\/p>\n

\u00a0<\/span><\/p>\n

void<\/span> numberFunction(<\/span>int<\/span> i) {<\/span><\/p>\n

\u00a0 cout “The number is: “<\/span> <\/span><\/span><\/p>\n

}<\/span><\/p>\n

\u00a0<\/span><\/p>\n

int<\/span> main() {<\/span><\/p>\n

\u00a0<\/span><\/p>\n

for<\/span>(<\/span>int<\/span> i=0; i<\/span><\/p>\n

\u00a0 <\/span>numberFunction(i);<\/span><\/p>\n

}<\/span><\/p>\n

\u00a0<\/span><\/p>\n

return<\/span> 0;<\/span><\/p>\n

}<\/span><\/p>\n<\/td>\n

\n

Edit & Run<\/span><\/a><\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\n

I have declared a void function, which means it returns nothing, and takes a parameter of \u2018int i\u2019. The function is named \u2018numberFunction\u2019 and as you can see, all it does is display the sentence, “The number is: ” followed by the current value of \u2018i\u2019. The function is called into use by the \u2018for loop\u2019, which continually calls the function as long as the value of \u2018i\u2019 is less than 10.<\/span><\/p>\n

Now with recursion, we won\u2019t need to use a \u2018for loop\u2019 because we will set it up so that our function calls itself. Let\u2019s recreate this same program one more time, only this time we will do it without a \u2018for loop\u2019. <\/span><\/span>We will use a recursion loop instead, like this.<\/span>

<\/span><\/p>\n\n\n\n
\n

#a0a0a0; mso-fareast-language: ES-MX;”>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18<\/span><\/p>\n<\/td>\n

#C0C0D0 1.0pt; mso-border-alt: solid #C<\/a>0C0D0 .75pt; background: #EFEFFF; padding: .75pt .75pt .75pt .75pt;” valign=”top”><\/p>\n

#include<\/a> <\/iostream><\/span><\/p>\n

using<\/span> namespace<\/span> std;<\/span><\/p>\n

\u00a0<\/span><\/p>\n

void<\/span> numberFunction(<\/span>int<\/span> i) {<\/span><\/p>\n

\u00a0\u00a0cout “The number is: “<\/span> <\/span><\/span><\/p>\n

\u00a0 i++;<\/span><\/p>\n

\u00a0 <\/span>if<\/span>(i<\/span><\/p>\n

\u00a0\u00a0\u00a0 numberFunction(i);<\/span><\/p>\n

\u00a0 }<\/span><\/p>\n

}<\/span><\/p>\n

\u00a0<\/span><\/p>\n

int<\/span> main() {<\/span><\/p>\n

\u00a0<\/span><\/p>\n

int<\/span> i = 0;<\/span><\/p>\n

numberFunction(i);<\/span><\/p>\n

\u00a0<\/span><\/p>\n

return<\/span> 0;<\/span><\/p>\n

}<\/span><\/p>\n<\/td>\n

\n

Edit & Run<\/span><\/a><\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u00a0<\/p>\n

<\/p>\n

We did it! We used recursion! You can see the call to \u2018numberFunction\u2019 is made only once in the main part of the program but it keeps getting called again and again from within the function itself, for as long as \u2018i\u2019 is less than 10.<\/span><\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"

\n

#mastery<\/a>21 #TC<\/a>1017<\/span><\/span><\/p>\n

 <\/p>\n

Use of recursion for repetitive algorithms<\/span><\/p>\n

What is recursion? The simple answer is, it’s when a function calls itself. But how does this happen? Why would this happen, and what are its uses?<\/p>\n


When we talk about recursion, we are really talking about creating a loop. <\/span><\/span>Let’s start by looking at a basic loop.<\/span>

<\/span><\/p>\n\n\n\n
\n

#a0a0a0; mso-fareast-language: ES-MX;”>1
2
3<\/span><\/p>\n<\/td>\n

#C0C0D0 1.0pt; mso-border-alt: solid #C<\/a>0C0D0 .75pt; background: #EFEFFF; padding: .75pt .75pt .75pt .75pt;” valign=”top”><\/p>\n

for<\/span>(<\/span>int<\/span> i=0;  i<\/span><\/p>\n

     cout “The number is: “<\/span> <\/span><\/span><\/p>\n

}<\/span><\/p>\n<\/td>\n

 <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\n

For those who don’t yet know, this basic loop displays the sentence, “The number is: ” followed by the value of ‘i’. <\/span><\/span>Like this.<\/span><\/p>\n\n\n\n
#E7E7E7; padding: .75pt .75pt .75pt .75pt;” valign=”top”><\/p>\n

 <\/span><\/p>\n

The number is: 0<\/span><\/p>\n

The number is: 1<\/span><\/p>\n

The number is: 2<\/span><\/p>\n

The number is: 3<\/span><\/p>\n

The number is: 4<\/span><\/p>\n

The number is: 5<\/span><\/p>\n

The number is: 6<\/span><\/p>\n

The number is: 7<\/span><\/p>\n

The number is: 8<\/span><\/p>\n

The number is: 9<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n


Inside the ‘for loop’ declaration we have the integer variable ‘i’ and have its starting value of 0. So the first time the sentence is displayed it reads, “The number is: 0”. The part of the ‘for loop’ declaration that is ‘i++’ tells the program that each time the loop repeats, the value of ‘i’ should be increased by 1. So, the next time the sentence is displayed it reads, “The number is: 1”.<\/span>
This cycle will continue to repeat for as long as the value of ‘i’ is less than 10. The last sentence displayed would read, “The number is: 9”. As you can see the basic ‘for loop’ has three parts to its declaration, a starting value, what must remain true in order to continue repeating, and a modifying expression. Everything that is contained within the {braces} is what the program performs. Cout stands for console out, and prints words or characters to the screen.<\/span>
So what does this have to do with recursion? Remember recursion is a loop. What if I did not want to just print a message to the screen? A loop can be used to perform other tasks as well.<\/span><\/p>\n

In the following code is the same loop as above only now it is being used to call a function.<\/span>

<\/span><\/p>\n\n\n\n
\n

#a0a0a0; mso-fareast-language: ES-MX;”>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15<\/span><\/p>\n<\/td>\n

#C0C0D0 1.0pt; mso-border-alt: solid #C<\/a>0C0D0 .75pt; background: #EFEFFF; padding: .75pt .75pt .75pt .75pt;” valign=”top”><\/p>\n

#include<\/a> <\/span><\/p>\n

using<\/span> namespace<\/span> std;<\/span><\/p>\n

 <\/span><\/p>\n

void<\/span> numberFunction(<\/span>int<\/span> i) {<\/span><\/p>\n

  cout “The number is: “<\/span> <\/span><\/span><\/p>\n

}<\/span><\/p>\n

 <\/span><\/p>\n

int<\/span> main() {<\/span><\/p>\n

 <\/span><\/p>\n

for<\/span>(<\/span>int<\/span> i=0; i<\/span><\/p>\n

  <\/span>numberFunction(i);<\/span><\/p>\n

}<\/span><\/p>\n

 <\/span><\/p>\n

return<\/span> 0;<\/span><\/p>\n

}<\/span><\/p>\n<\/td>\n

\n

Edit & Run<\/span><\/a><\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\n

I have declared a void function, which means it returns nothing, and takes a parameter of ‘int i’. The function is named ‘numberFunction’ and as you can see, all it does is display the sentence, “The number is: ” followed by the current value of ‘i’. The function is called into use by the ‘for loop’, which continually calls the function as long as the value of ‘i’ is less than 10.<\/span><\/p>\n

Now with recursion, we won’t need to use a ‘for loop’ because we will set it up so that our function calls itself. Let’s recreate this same program one more time, only this time we will do it without a ‘for loop’. <\/span><\/span>We will use a recursion loop instead, like this.<\/span>

<\/span><\/p>\n\n\n\n
\n

#a0a0a0; mso-fareast-language: ES-MX;”>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18<\/span><\/p>\n<\/td>\n

#C0C0D0 1.0pt; mso-border-alt: solid #C<\/a>0C0D0 .75pt; background: #EFEFFF; padding: .75pt .75pt .75pt .75pt;” valign=”top”><\/p>\n

#include<\/a> <\/span><\/p>\n

using<\/span> namespace<\/span> std;<\/span><\/p>\n

 <\/span><\/p>\n

void<\/span> numberFunction(<\/span>int<\/span> i) {<\/span><\/p>\n

  cout “The number is: “<\/span> <\/span><\/span><\/p>\n

  i++;<\/span><\/p>\n

  <\/span>if<\/span>(i<\/span><\/p>\n

    numberFunction(i);<\/span><\/p>\n

  }<\/span><\/p>\n

}<\/span><\/p>\n

 <\/span><\/p>\n

int<\/span> main() {<\/span><\/p>\n

 <\/span><\/p>\n

int<\/span> i = 0;<\/span><\/p>\n

numberFunction(i);<\/span><\/p>\n

 <\/span><\/p>\n

return<\/span> 0;<\/span><\/p>\n

}<\/span><\/p>\n<\/td>\n

\n

Edit & Run<\/span><\/a><\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n

<\/p>\n

We did it! We used recursion! You can see the call to ‘numberFunction’ is made only once in the main part of the program but it keeps getting called again and again from within the function itself, for as long as ‘i’ is less than 10.<\/span><\/span><\/p>\n<\/div>\n

Continue reading →<\/span><\/a><\/p>\n","protected":false},"author":165,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3,26],"tags":[318,330,144,398,328,325,219,326,399,327,95,335,486,40,287],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts\/14458"}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/users\/165"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/comments?post=14458"}],"version-history":[{"count":6,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts\/14458\/revisions"}],"predecessor-version":[{"id":19505,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts\/14458\/revisions\/19505"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/media?parent=14458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/categories?post=14458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/tags?post=14458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}