Recursion practice

Recursion is a common topic on the new syllabus and it has feature in every exam since 2014. To get you to think about recursion, here are some simple tasks.

Write the following recursive functions (in Java because the IB’s pseudocode doesn’t have a return statement – doh!):

  • A function that takes an int array argument and returns the maximum int in the list.
  • A function that takes a string and returns true if it is a palindrome.
  • A binary search function to find an int n in an int array.
  • A function that takes an int n and return n factorial.
  • A function that takes an in n and returns the nth Fibonacci number.
  • A function that takes an int n and prints the Fibonacci sequence up to n.
  • A routine in Logo or Python that creates a Koch snowflake.
  • A routine in Logo or Python that creates a Sierpinski triangle.

Look at the following Python code. The “left”, “right” and “forward” commands are just like there are in Logo. Sketch the pattern that the following calls will make:

koch(t, 0, 100)
koch(t, 1, 100)
koch(t, 2, 100)
import turtle

def koch(t, order, size):
    if order == 0:
        t.forward(size)
    else:
        koch(t, order-1, size/3)
        t.left(60)
        koch(t, order-1, size/3)
        t.right(120)
        koch(t, order-1, size/3)
        t.left(60)
        koch(t, order-1, size/3)

# EXECUTION STARTS HERE
t = turtle.Turtle()
koch(t, 3, 300)

Junior Application Development

Deliverables to be put on your website:

  • Video 1-2 minutes
  • Annotated screenshots and code
    • What each class does
    • How classes communicate with each other (specifically what references are passed from where to where)
    • How saving to file works
    • How subforms work

Topic 2 Quiz

There will be a quiz on all aspects of Topic 2 on Monday 18th January.

You must use IB Computer Science Guide (first exams 2014) as your reference for content.

We will cover logic gates and truth tables on Thursday.

Suggested revision technique:

  • For each syllabus point:
    • If the content is on Google presentation that I have given you, learn it.
    • If not, make a note of it and ask me on Thursday 14th, or alternatively research it yourself.
  • Consider
    • Definitions
    • Advantages
    • Disadvantages
    • Examples

Click here.