Topic Number 2 Efficiency – Complexity Algorithm Analysis



Download 1,07 Mb.
bet2/8
Sana14.06.2022
Hajmi1,07 Mb.
#669861
1   2   3   4   5   6   7   8
Bog'liq
topic2Efficiency Complexity AlgorithmAnalysis (1)

Clicker 2

  • CS 314
  • What is output by the following code? int total = 0; for (int i = 0; i < 13; i++) for (int j = 0; j < 11; j++) total += 2; System.out.println(total);
  • 24
  • 120
  • 143
  • 286
  • 338

Clicker 3

  • What is output when method sample is called? // pre: n >= 0, m >= 0 public static void sample(int n, int m) { int total = 0; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) total += 5; System.out.println(total); }
  • 5 D. nm
  • n * m E. (n * m)5
  • n * m * 5
  • CS 314
  • Efficiency - Complexity

Example

  • CS 314
  • Efficiency - Complexity
  • How many statements are executed by method total as a function of values.length
  • Let N = values.length
  • public int total(int[] values) { int result = 0;
  • for (int i = 0; i < values.length; i++)
  • result += values[i];
  • return result;
  • }

Counting Up Statements

  • CS 314
  • Efficiency - Complexity
  • int result = 0; 1
  • int i = 0; 1
  • i < values.length; N + 1
  • i++ N
  • result += values[i]; N
  • return total; 1
  • T(N) = 3N + 4
  • T(N) is the number of executable statements in method total as function of values.length

Another Simplification

  • CS 314
  • Efficiency - Complexity

Download 1,07 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish