lab5 - COP 3502 Lab Notes Introduction to Order Analysis...

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

View Full Document Right Arrow Icon
COP 3502 – Lab Notes Introduction to Order Analysis This week’s lab introduces you to the concept of order analysis. We will see some of this material again in the lecture but this lab will give you a first taste of the topic. This lab should give you a good overview of what Big-Oh notation is and how it is useful when discussing the run-time complexity of algorithms. Algorithmic Analysis We need to have ways to compare algorithms so that we can tell if one is more efficient than another. We also want to have an idea, in advance, of how efficient (or how complex) an algorithm is before we take the time to write a program for it. We often want to know how much longer or shorter the execution time might be if we change the size of the input. We have two basic ways of comparing algorithms: The relative time they need to solve a problem. We count steps to measure this, not seconds. The relative amount of space needed. We look at the amount of memory space needed to store data items. We have found that we often must increase one to reduce the other. We refer to this as making time/space trade-offs . Algorithms We Have Seen or Will See in This Class Algorithms that take a constant number of steps, no matter how big or small the size of the data: adding to a stack or queue or to the head of a list finding the largest or smallest number in a sorted array Algorithms that need around log 2 n steps: finding a value in a Binary Search Tree Algorithms that need around n steps: finding a certain number in an unsorted array finding the end of a linked list printing the contents of an array, linked list or tree (doing a traversal) Algorithms that need around nlog 2 n steps: QuickSort MergeSort Algorithms that need around n 2 steps: SelectionSort BubbleSort 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
2D graphics algorithms (3D algorithms often take n 3 steps) Algorithms that need an exponential number of steps: finding the minimum distance between all nodes in a graph (traveling salesman) Towers of Hanoi Let's look at BubbleSort Algorithm Sort // declare variables procedure BSort(n isoftype Num) // declare variables procedure Bubble(k isoftype Num) // code to do one pass of bubble on k items // we know that this can take up to n steps endprocedure i <- n loop // we are calling Bubble n-1 times exitif (i = 1) Bubble(i) i <- i - 1 endloop endprocedure endalgorithm How many steps does this take? Let t
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 06/12/2011.

Page1 / 6

lab5 - COP 3502 Lab Notes Introduction to Order Analysis...

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

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