×

### Let's log you in.

or

Don't have a StudySoup account? Create one here!

×

or

by: Nick Rowe

125

0

17

# Data Structures And Algorithms CS 25100

Marketplace > Purdue University > ComputerScienence > CS 25100 > Data Structures And Algorithms
Nick Rowe
Purdue
GPA 3.68

Staff

These notes were just uploaded, and will be ready to view shortly.

Either way, we'll remind you when they're ready :)

Get a free preview of these Notes, just enter your email below.

×
Unlock Preview

COURSE
PROF.
Staff
TYPE
Class Notes
PAGES
17
WORDS
KARMA
25 ?

## Popular in ComputerScienence

This 17 page Class Notes was uploaded by Nick Rowe on Saturday September 19, 2015. The Class Notes belongs to CS 25100 at Purdue University taught by Staff in Fall. Since its upload, it has received 125 views. For similar materials see /class/208082/cs-25100-purdue-university in ComputerScienence at Purdue University.

×

## Reviews for Data Structures And Algorithms

×

×

### What is Karma?

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 09/19/15
ANALYSIS OF ALGORITHMS Quick Mathematical Review Running Time PseudoCode Analysis of Algorithms Asymptotic Notation Asymptotic Analysis T01 Algorithm Output Analysis of Algorithms A Quick Math Review Logarithms and Exponents properties of logarithms 10gbXY10ng 10ng 10gbXY Z 10ng 39 10ng 10ng0 oclogbx 10gba10gax logab properties of exponentials abc abac abc abc abaC ab39c 10gb ba a be 2 a clogab Analysis of Algorithms A Quick Math Review cont Floor Lxl the largest integer S x Ceiling lxl the smallest integer x Summations general de nition fU fsfslfs2 ft is Where f is a function S is the start index and t is the end index Geometric progression i 2 at given an integer n O and a real number 0 lt61 72 l n i 2 n l an1 2alaama 1 a i0 geometric progressions exhibit exponential growth Analysis of Algorithms 3 Average Case vs Worst Case Running Time of an Algorithm An algorithm may run faster on certain data sets than on others Finding the average case can be very di icult so typically algorithms are measured by the worstcase time complexity Also in certain application domains eg air traf c control surgery knowing the worstcase time complexity is of crucial importance worstcase 3V6 ragecase bestcase Running Time U E Input Instance Analysis of Algorithms 4 Measuring the Running Time How should we measure the running time of an algorithm Experimental Study Write a program that implements the algorithm Run the program with data sets of varying size and composition Use a method like SystemcurrentTimeMillis to get an accurate measure of the actual running time The resulting data set should look something like t ms 60 50 I 40 l l 30 I I I I I I I I I 20 I I I I I 10 I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I n 0 50 100 Analysis of Algorithms 5 Beyond Experimental Studies Experimental studies have several limitations It is necessary to implement and test the algorithm in order to determine its running time Experiments can be done only on a limited set of inputs and may not be indicative of the running time on other inputs not included in the experiment In order to compare two algorithms the same hardware and software environments should be used We will now develop a general methodology for analyzing the running time of algorithms that Uses a highlevel description of the algorithm instead of testing one of its implementations Takes into account all possible inputs Allows one to evaluate the ef ciency of any algorithm in a way that is independent from the hardware and software environment Analysis of Algorithms 6 PseudoCode Pseudocode is a description of an algorithm that is more structured than usual prose but less formal than a programming language Example nding the maximum element of an array Algorithm arrayMaxA 11 Input An array A storing n integers Output The maximum element in A currentMax e AO forte l ton l do if currentMax lt Al39 then currentMax e Al39 return currentAax Pseudocode is our preferred notation for describing algorithms However pseudocode hides program design issues Analysis of Algorithms 7 What is PseudoCode A mixture of natural language and highlevel programming concepts that describes the main ideas behind a generic implementation of a data structure or algorithm Expressions use standard mathematical symbols to describe numeric and boolean expressions use 9 for assignment cc77 in Java use for the equality relationship in Java Method Declarations Algorithm nameparam1 param2 decision structures whileloops repeatloops forloop array indexing Methods calls returns Programming Constructs if then else while do repeat until for do Ai object methodargs return value Analysis of Algorithms A Quick Math Review cont Arithmetic progressions An example n 2 11 11 i123n igl 2 two Visual representations A A n1 n n 3 3 2 2 1 I 1 0 o Analysis of Algorithms Analysis of Algorithms Primitive Operations Lowlevel computations that are largely independent from the programming language and can be identi ed in pseudocode eg calling a method and returning from a method performing an arithmetic operation eg addition comparing two numbers etc By inspecting the pseudocode we can count the number of primitive operations executed by an algorithm Example Algorithm arrayMaxA 11 Input An array A storing n integers Output The maximum element in A currentMax e AO forte l ton l do if currentMax lt Al39 then currentMax e Al39 return currentMax Analysis of Algorithms 10 Asymptotic Notation Goal To simplify analysis by getting rid of unneeded information Like rounding 1000001 21000000 3722 z n2 The BigOh Notation given functions fn and gn we say that fn is 0gn if and only if fn S c gn for n no c and n0 are constants fn and gn are functions over nonnegative integers cgm f 74 Running Time n0 Input Size Analysis of Algorithms 11 Asymptotic Notation cont Note Even though 7n 3 is 0075 it is expected that such an approximation be of as small an order as possible Simple Rule Drop lower order terms and constant factors 7n 3 is 0n 8nzlog n 5712 n is 0nzlog n Special classes of algorithms logarithmic 0log n linear 0n quadratic 0n2 polynomial 0nk k 1 exponential 0a ngt l Relatives of the BigOh 2fn Big Omega fn Big Theta Analysis of Algorithms 12 Asymptotic Analysis of The Running Time Use the BigOh notation to express the number of primitive operations executed as a function of the input size For example we say that the arrayMax algorithm runs in 0n time Comparing the asymptotic running time an algorithm that runs in 0n time is better than one that runs in 0n2 time similarly 0log n is better than 0n hierarchy of functions 10gnltltnltltnzltltn3ltlt2n Caution Beware of very large constant factors An algorithm running in time 1000000 72 is still 0n but might be less ef cient on your data set than one running in time 2n which is 0n Analysis of Algorithms 13 Example of Asymptotic Analysis An algorithm for computing pre x averages Algorithm pre xAverages 1 X Input An nelement array X of numbers Output An nelement array A of numbers such that At is the average of elements X0 Xl Let A be an array of 11 numbers forieOtonldo a e 0 forfeOtotdo a e a X39 Ai e al 1 return array A Analysis Analysis of Algorithms 14 Example of Asymptotic Analysis A better algorithm for computing pre x averages Algorithm pre xAverages2X Input An nelement array X of numbers Output An nelement array A of numbers such that At is the average of elements X0 Xl Let A be an array of 11 numbers s e 0 forieOtonldo s e s Xt Ai e sz 1 return array A Analysis Analysis of Algorithms 15 Advanced Topics Simple Justi cation Techniques By Example Find an example Find a counter example The Contra Attack Find a contradiction in the negative statement Contrapositive Induction and LoopInvariants Induction 1 Prove the base case 2 Prove that any case n implies the next case n l is also true Loop invariants Prove initial claim SO Show that SH implies S will be true after iteration i Analysis of Algorithms 16 Advanced Topics Other Justi cation Techniques Proof by Excessive Waving of Hands Proof by Incomprehensible Diagram Proof by Very Large Bribes see instructor after class Proof by Violent Metaphor Don t argue with anyone who always assumes a sequence consists of hand grenades The Emperor s New Clothes Method This proof is so obvious only an idiot wouldn t be able to understand it Analysis of Algorithms 17

×

×

### BOOM! Enjoy Your Free Notes!

×

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

Steve Martinelli UC Los Angeles

#### "There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Jennifer McGill UCSF Med School

#### "Selling my MCAT study guides and notes has been a great source of side revenue while I'm in school. Some months I'm making over \$500! Plus, it makes me happy knowing that I'm helping future med students with their MCAT."

Steve Martinelli UC Los Angeles

#### "There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Parker Thompson 500 Startups

#### "It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!
×

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com