9_alg_analysis

9_alg_analysis - Introduction to Computers and Programming...

Info iconThis 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
3 Complexity Analysis T i m e ( 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
Background 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?
Background image of page 3

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

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

This note was uploaded on 01/28/2012 for the course AERO 16.01 taught by Professor Markdrela during the Fall '05 term at MIT.

Page1 / 11

9_alg_analysis - Introduction to Computers and Programming...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online