cs2050-02-Complexity

cs2050-02-Complexity - COMPUTATIONAL COMPLEXITY (Chapter 1...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
COMPUTATIONAL COMPLEXITY (Chapter 1 in Main text)
Background image of page 1

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

View Full DocumentRight Arrow Icon
How long does it take? Suppose you have an array of size 100. How long oes it take to access a particular element? does it take to access a particular element? Suppose it takes 1 unit of time to access a single element. What if the size of the array is increased to 5000? It would still take 1 unit of time to access an element. hat if the array has N elements? It would still take What if the array has N elements? It would still take only 1 unit of time to access a single element no atter what the value of N is. matter what the value of N is.
Background image of page 2
How long does it take? Suppose you have an integer array of size 100. How long does it take to sum the 100 elements? If it takes 100 units of time to sum 100 elements, ow long would it take to sum the values in an how long would it take to sum the values in an array of size N? It would take N units of time. It takes 1 unit of time to access a single element of an array – the time is independent of the size of the array. Summing the elements of an array takes time that is proportional to the size of the array .
Background image of page 3

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

View Full DocumentRight Arrow Icon
Algorithm Efficiency How can two different algorithms be compared, i.e., in what sense can one algorithm be said to be "better" – or more efficient - than another lgorithm? algorithm?
Background image of page 4
Consider the layout of a telephone directory: If the listings are not in any useful order (e.g., ordered according to the date on which each person was assigned their phone number), then finding the listing for a specified name would begin with a sequential scan of the entire phone book starting with the first listing on page 1 and ending when the desired listing is found. There is not a more efficient algorithm. If there are N listings, then the number of listings examined during a scan of an unordered phone book is N in the worst case (when the desired listing is the very last one), and is N/2 on average.
Background image of page 5

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

View Full DocumentRight Arrow Icon
If the listings in the phone book are sorted according to urname then it is possible to apply a "binary search" surname, then it is possible to apply a binary search algorithm to find the listing we need: 1. Open the phone book and check the middle page 2. If the surname we want comes before the surnames on the page, then we can ignore all of the subsequent listings and apply binary search to the remaining ones 3. If the surname we want comes after the surnames on the page, then we ignore all of the previous listings and apply binary search to the remaining ones Applying binary search allows us to find the desired listing - or determine it isn’t present - after examining approximately log 2 (N) listings.
Background image of page 6
The decision about how to list names and phone numbers in a phone book comes down to a decision between two ata structures: rdered versus unordered data structures: Ordered versus unordered .
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/06/2010 for the course CS 2050 taught by Professor Uhlmann during the Fall '09 term at Missouri (Mizzou).

Page1 / 88

cs2050-02-Complexity - COMPUTATIONAL COMPLEXITY (Chapter 1...

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

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