ช่วยหน่อยค่ะ! สอนวิธีหาจำนวน Operations กับ ค่าBig O ของโค้ดค่ะ

คำสั่งค่ะ:  How many operations of the following codes and What is the Big-O of each?

อันแรกค่ะ

+code1(){
           i=1;
           while(i<n){
                      output("i = " + i);
                       i++;
             }//end while
}//end code1

เราคิดว่ามีทั้งหมด 3 operation? ค่า Big O คือ O(1)
ถูกต้องมั้ยคะ? 

-----------------------

อันที่สองค่ะ

+code2(){ 
          for(i = n; i>=0; i--){
                    output("i = " + i);
          }//end for
}//end code2

อันนี้ 2 operation, big O คือ O(n)?

-----------------------

อันสุดท้ายค่ะ

+code3(int[] theArray, int n){
            int temp
            for(j = 1; j <= n - 1; ++j){
                        i = j + 1;
                        do{
                                    if (theArray < theArray[j]){
                                    temp = theArray;
                                    theArray = theArray[j];
                                    theArray[j] = temp;
                                     }//end if
                                     ++i;
                        }while (i <= n);
              }//end for
}//end code3 

อันนี้ 7 operation? O(log n) ? 

รบกวนขอคำอธิบายด้วยนะคะ หนูจะได้เอาไปทำความเข้าใจกับโจทย์อื่นๆ เพิ่มเติม 
ขอบคุณทุกคนล่วงหน้านะคะ
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่