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 )
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 ?
- Ask the students .
- Close the entrance and exit doors and probably all windows as well
- Separate the class into two portion ( portion one with student , portion two without any student )
- 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