Abigale  Yundt

Abigale Yundt

1603537200

While You Don't Understand Recursion, Read Recursion: by Randy Taylor

Recursion is the one idea I constantly use while I solve coding problems. Most of the time I don’t start by thinking “RECURSION WILL SOLVE THIS!”. However recursion just ends up being the logical way to reach an answer. In my professional opinion recursion is the purest form of coding; write a function that will call itself until you get what you want! To implement recursion we will create a helper algorithm. 1) Identify what the smallest input is. 2) Continually break down a larger input into smaller inputs and pass those smaller inputs back into itself until you get the desired answer. 3) Define a “base case” that will stop the Recursion should the answer not be found.

Let’s look at the idea of Recursion first. We are writing code that will execute itself until we get a desired answer or reach a base case. Essentially we are creating a loop. I will illustrate this with pseudo code:

for (let recursion =()=>{ …answer? answer = true : false} ; answer === false; recursion())

Much like a traditional for loop the above pseudo code will continue while the second condition is true; the recursion will continue until answer === true. At this point the second statement of the for loop is false terminating the loop. Above if answer === false recursion will call itself again. This is the general idea of recursion. This is why creating a base case is essential to prevent an infinite loop. The “answer” we are looking for might not be present causing recursion to run until the sun burns out.

#algorithms #javascript #recursion #tutorial-for-beginners #iteration #recursion-explained #what-is-recursion #programming

What is GEEK

Buddha Community

 While You Don't Understand Recursion, Read Recursion: by Randy Taylor
Abigale  Yundt

Abigale Yundt

1603537200

While You Don't Understand Recursion, Read Recursion: by Randy Taylor

Recursion is the one idea I constantly use while I solve coding problems. Most of the time I don’t start by thinking “RECURSION WILL SOLVE THIS!”. However recursion just ends up being the logical way to reach an answer. In my professional opinion recursion is the purest form of coding; write a function that will call itself until you get what you want! To implement recursion we will create a helper algorithm. 1) Identify what the smallest input is. 2) Continually break down a larger input into smaller inputs and pass those smaller inputs back into itself until you get the desired answer. 3) Define a “base case” that will stop the Recursion should the answer not be found.

Let’s look at the idea of Recursion first. We are writing code that will execute itself until we get a desired answer or reach a base case. Essentially we are creating a loop. I will illustrate this with pseudo code:

for (let recursion =()=>{ …answer? answer = true : false} ; answer === false; recursion())

Much like a traditional for loop the above pseudo code will continue while the second condition is true; the recursion will continue until answer === true. At this point the second statement of the for loop is false terminating the loop. Above if answer === false recursion will call itself again. This is the general idea of recursion. This is why creating a base case is essential to prevent an infinite loop. The “answer” we are looking for might not be present causing recursion to run until the sun burns out.

#algorithms #javascript #recursion #tutorial-for-beginners #iteration #recursion-explained #what-is-recursion #programming

BDF.jl: Module to Read Biosemi BDF Files with The Julia

BDF.jl is a Julia module to read/write BIOSEMI 24-bit BDF files (used for storing electroencephalographic recordings)

Usage:

bdfHeader = readBDFHeader("res1.bdf") #read the bdf header
sampRate = bdfHeader["sampRate"][1] #get the sampling rate
#read the data, the event table, the trigger channel and the status channel
dats, evtTab, trigs, statusChan = readBDF("res1.bdf")

Usage

Load the module

using BDF

To read an entire BDF recording


dats, evtTab, trigChan, sysCodeChan = readBDF("res1.bdf")

dats is the nChannelXnSamples matrix containing the data. Note that the triggers are not contained in the dats matrix. The triggers can be retrieved either trough the event table (evtTab), or the raw trigger channel (trigChan). The eventTable is a dictionary containing the trigger codes evtTab["code"], the trigger indexes evtTab["idx"] (i.e. the sample numbers at which triggers occurred in the recording), and the trigger durations evtTab["dur"] (in seconds). The raw trigger channel returned in trigChan contains the trigger code for each recording sample. Additional Biosemi status codes (like CM in/out-of range, battery low/OK) are returned in sysCodeChan.

You can also read only part of a recording, the following code will read the first 10 seconds of the recording:


dats, evtTab, trigChan, statChan = readBDF("res1.bdf", from=0, to=10)

The readBDFHeader function can be used to get information on the BDF recording:


bdfInfo = readBDFHeader("res1.bdf")

Get the duration of the recording:


bdfInfo["duration"]

Get the sampling rate of each channel:


bdfInfo["sampRate"]

Get the channel labels:


bdfInfo["chanLabels"]

To read the information stored in the status channel you can use the decodeStatusChannel function


statusChanInfo = decodeStatusChannel(sysCodeChan)

this will return a dictionary with several arrays that indicate for each sample of the recordings whether CMS was in range, whether the battery charge was low, the speedmode of the system, and other information stored in the status channel.

Beware that BDF.jl does not check that you have sufficient RAM to read all the data in a BDF file. If you try to read a file that is too big for your hardware, your system may become slow or unresponsive. Initially try reading only a small amount of data, and check how much RAM that uses.

Documentation is available here:

http://samcarcagno.altervista.org/BDF/index.html

Download Details:

Author: Sam81
Source Code: https://github.com/sam81/BDF.jl 
License: MIT license

#julia #modules 

Dedric  Reinger

Dedric Reinger

1599158640

Recursion made simple

  1. Recursion made simple

Anybody reading data structures and algorithm would have come across a topic called “Recursion”. Now here is the best way to understand recursion. Read this ’n’ times until your understanding becomes** “True”**. Haha!! now that’s how simple the recursion is.

Well recursion can be implemented in any language and it has the same outcome. Here i’ll be demonstrating few topics and key concepts on recursion in python🐍. Yes, you read it right one love for python❤.

Introduction:

A function calling itself until a condition is set true or false is called recursive function. The below image shows to a simple function called “recursive_fun” calling itself ’n’ times.

Image for post

a simple example of recursion

The output of a recursion can be understood by a concept called as tracing which is done to trace the output by a recursive function.

a tracing tree of recursive_fun(forward phase)

the above tracing tree explains a lot about how the repetitive function call takes place to obtain the desired output. Here the recursive_fun is called 3+1 times where for all the 3 times it prints ’n’ but for the last call it fails to satisfy the condition and returns 0. Hence, in any recursion the function call is made n+1 times. Also, on carefully observing the tracing tree we see that the recursive_fun executes print statement before calling itself, this is known as forward phase. A backward phase of recursion is when a function calls itself before executing any statements, i.e all the other statements are executed until there is no further function calls.

Image for post

#recursive #algorithms #python #recursion #data-structures

August  Larson

August Larson

1622168113

Recursion And Iteration In Python Programming

Acomputer program consists of line-by-line instructions. The computer performs those instructions line-by-line. However, some instructions may be repetitive with a common pattern. Recursion or iteration helps one to write a few lines of codes to perform such repetitive tasks. Suppose a Python list with five-string elements. We wish to print the elements one in a line. This operation needs five lines of codes.

 flowers = ['lily', 'tulip', 'rose', 'lavender', 'dandelion'] 
 print(flowers[0])
 print(flowers[1])
 print(flowers[2])
 print(flowers[3])
 print(flowers[4]) 

Output:

It can be observed that the five lines of codes follow the same pattern. The only difference in each line is the index of the list elements. What if this list contains 100 or 1000 elements? Coding will become a tedious task. These kinds of problems are resolved through either iteration or recursion. Here, the iterative form of the above codes is as follows.

 for flower in flowers:
   print(flower) 

Output:

iteration

These two lines are sufficient to achieve the task even if the list contains a million elements!

#developers corner #backtracking #dynamic programming #factorial #iteration #iterative #python #python programming #quicksort #recursion #recursive #sorting

Jackson  Watson

Jackson Watson

1625631000

What's Recursion and Why use it? Beyond Code Live-X 090

(Previously 002) In the words of Woody: “That’s not Recursion! It’s looping with style!”

Follow Beyond Code:(Learn to Code in 15 Minutes a Day)
Facebook: https://www.facebook.com/beyondcodebootcamp
YouTube: https://www.youtube.com/channel/UC2KJHARTj6KRpKzLU1sVxBA
Twitter: https://twitter.com/_beyondcode

Daily Coding Live Streams:
Facebook: https://facebook.com/coolaj86
YouTube: https://youtube.com/coolaj86
Twitch: https://twitch.tv/coolaj86

Follow Health, Wealth, Commitment
(Daily Lifestyle Chat)
Facebook: https://www.facebook.com/groups/5406824179391158
YouTube: https://www.youtube.com/channel/UCbw2SbqD0OofAEVF_T61wCQ

#recursion #what's recursion