Know your code run time.

Good algo exihibt fast runtime with good performance

Bad algo exhibit good or poor perfromace with bad low runtime.

Conside a recursion for studentData and f(s-1)+s^s

note the base call

public static int f( int x )
if ( x == 0 )
return 0;
return 2*f(x-1)+x*x;

if we were to test the method with 10 , a recursive call is performed on 9 as 9f(8) = ( 9-1)+9^2

A similar example is : Suppose a teacher in a class without security camera left his mobile phone on the table while writing on the board , after some minutes, the teacher suddenly can’t find his mobile number , in this case what do you suggest the teacher can do ?

  1. Ask the students .
  2. Close the entrance and exit doors and probably all windows as well
  3. Separate the class into two portion ( portion one with student , portion two without any student )
  4. as a teacher , he will request other staffs to help check the portion without student ,

if found in that portion then the teachers need not to worry about the second portion and may probably decide to punish the whole class ( it’s possible the students were testing the teacher’s recursion knowledge )

— that is the base class

, and if not found in the second portion , he or the called staff will have to check each student one by one , if found with the first student ( then no more search ) this is exactly how recursion occurs.

Now , let’s model an algo for this ( with bad and good runtime )

public class TeacherVsStudent

private static int totalNumOfStudent;
private static double classDimension;
private static String lostItem;
public static String whoTakeTheTeachersMobile ( nt totalNumOfStudent ,double classDimension ,String lostItem )
if ( totalNumberOfStudent > 0 )
// do this

}while ( () && () && );

System.out.println (“Something went wrong …”);
The time taken by an algorithm confronted
with large amounts of input will be an important criterion for deciding if it is a
good algorithm.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

Up ↑

%d bloggers like this: