public static void removeEvensVer1( List<Integer> lst )
 {
     int i = 0;

     while( i < lst.size( ) )
         if( lst.get( i ) % 2 == 0 )
             lst.remove( i );
         else
             i++;
 }

According to my understanding, shouldn't this method be N^3? Since you have a while loop (N) * lst.get(i) which is another N provided lst is a LinkedList, and finally remove which is also N.

the get and the remove are not nested, so you don't multiply them together. Think of it as O N*(N+N) ie O N^2
(Of course, if the list implementation is suitably optimised then get(i+1) immediately following a get(i) could be constant and small. Similarly get(i) followed by remove(i) could be optimised by caching. But let's assume the implementation is just the obvious simple version.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.