[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

Big-0 Running time

Asked by sidd_barai in Algorithms, Kernel And Operating System Specific Programming, Miscellaneous Programming

Tags: Big-0 Running time

1.  What is the Big-O running time of the following code fragment?


      public static int calc( List<Integer> lst, int N )
      {
         int count = 0;
         for ( int i=0; i<N; i++)
         {
            if (lst.get(i) > 0)
               sum += lst.get(i);
            else
               sum += lst.get(i) * lst.get(i);
         }
         return sum;
      }

   a.  If an ArrayList is passed.  Explain your answer.
   b.  If a LinkedList is passed.  Explain your answer.



2.  What is the Big-O running time of the following code fragment?

   public static void add( List<Integer> lst1, List<Integer> lst2)
   {
      for ( Integer x : lst1 )
         lst2.add(0, x);
   }


   a.  If an ArrayList is passed for lst1 and lst2.  Explain your answer.
   b.  If a LinkedList is passed for lst1 and lst2.  Explain your answer.



3.  What is the Big-O running time of the following code fragment?

   public static int Count( List<Integer> lst1, List<Integer> lst2)
   {
      Iterator<Integer> itr1 = lst1.iterator();

      int count=0;
      while ( itr1.hasNext() )
      {
         Integer x = itr1.next();
         Iterator<Integer> itr2 = lst2.iterator();
         while ( itr2.hasNext() )
            if ( x.equals( itr2.next()) )
               count++;
      }

      return count;
   }


   a.  If an ArrayList is passed for lst1 and lst2.  Explain your answer.
   b.  If a LinkedList is passed for lst1 and lst2.  Explain your answer.
[+][-]09/15/09 11:00 PM, ID: 25342323Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/16/09 12:02 AM, ID: 25342669Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/16/09 01:39 AM, ID: 25343245Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/18/09 09:32 AM, ID: 25367630Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/19/09 10:34 PM, ID: 25375990Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625