Examples of Recursion


Problems

Problem : In binary search, we split the data set in half at each recursive call. One could imagine an algorithm that split the data set up into three or four sets at each recursive call. Provide an argument why, in Big-O notation, binary search is as efficient as ternary search or quaternary search.


Problem : Why is linear search better implemented iteratively rather than recursively?


Problem : You have an array of ints sorted in ascending order. Write a function that recursively does a ternary search (splits the data into three sets instead of two) on the array.


Problem : Your boss tells you to write a function to search for a number in an unbounded array (the array starts at index 0 but goes on forever). He tells you to use the standard binary search algorithm. Explain to him why you can't.


Problem : In a last attempt to show how smart he is, your boss tells you to implement linear search recursively as that is much more efficient than an iterative implementation. Explain to him why he is incorrect.


Take a Study Break

SparkLife

Star Trek gets SEXY

Chris Pine and Zoe Saldana heat up the red carpet!

SparkLife

Are you afraid of relationships?

Auntie SparkNotes can help!

SparkLife

Wanna get JLaw's gorgeous glow?

Click here for simple, sexy makeup tricks!

SparkLife

Sexy starlet style

See every single look from the Met Gala!

SparkLife

Who'd be on your zombie-apocalypse crew?

We already dib'sed Genghis Khan.

Geek out!

The MindHut

Geeky Actors: Then and Now

Travel back in time!

The MindHut

Villains We Want These Actresses to Play

From super cute to super bad!

The MindHut

10 Movies Better Than Their Books

What do you think?

The MindHut

How To Look Like J-Law...

When you don't look like J-Law.

The MindHut

12 Scientific Inaccuracies in Into Darkness

What did Star Trek get wrong?

The Book

Cover image

Read What You Love, Anywhere You Like

Get Our FREE NOOK Reading Apps