{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

9_alg_analysis - Introduction to Computers and Programming...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 9 April 7 2004 So far … • Data structures • Algorithms
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
3 Complexity Analysis T i me ( se c o n d s) 60 50 40 30 20 10 0 1 2 3 4 5 O(C) O(n 2 ) “Just how good is my algorithm?” 4 In-class Exercise and calculates the sum of all integers 1..N • Best case vs. worst case • Storage vs. Computation time • Computing the computation time • Big-O notation • Write a procedure that reads an integer N
Image of page 2
5 Code Comparison linear time? with Ada.Integer_Text_Io, Ada.Text_Io; use Ada.Integer_Text_Io, Ada.Text_Io; procedure CalcSum is N : Integer; Total_Sum : Integer; begin Put_Line( "Enter an Integer: " ); Get(N); Total_Sum := 0 ; for I in 1 ..N loop Total_Sum := Total_Sum + I; ; Put(Total_Sum); end ; 6 Code Comparison with Ada.Integer_Text_Io, Ada.Text_Io; use Ada.Integer_Text_Io, Ada.Text_Io; procedure Calcsum is N : Integer; Total_Sum : Integer; begin Put_Line( "Enter an Integer: " ); Get(N); Total_Sum := 0 ; Total_Sum := (N * (N + 1 )) / 2 ; Put(Total_Sum); end ; N*(N+1) 2 • How many have a solution that runs in end loop • How many have a solution that runs in constant time?
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
7 Complexity Analysis : rate at which storage or time grows as a function of the problem size : describes the
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern