Algorithm Efficiency, Big O Notation, And Role Of Data .

2y ago
16 Views
3 Downloads
346.82 KB
22 Pages
Last View : 14d ago
Last Download : 3m ago
Upload by : Grant Gall
Transcription

Algorithm Efficiency, Big O Notation,and Javadoc Algorithm EfficiencyBig O NotationRole of Data StructuresJavadocReading: L&C 2.1-2.4, HTML Tutorial1

Algorithm Efficiency Let’s look at the following algorithm forinitializing the values in an array:final int N int [] countsfor (int i 0;counts[i]500; new int[N];i counts.length; i ) 0; The length of time the algorithm takes toexecute depends on the value of N2

Algorithm Efficiency In that algorithm, we have one loop thatprocesses all of the elements in the array Intuitively:– If N was half of its value, we would expect thealgorithm to take half the time– If N was twice its value, we would expect thealgorithm to take twice the time That is true and we say that the algorithmefficiency relative to N is linear3

Algorithm Efficiency Let’s look at another algorithm for initializing thevalues in a different array:final int N 500;int [] [] counts new int[N][N];for (int i 0; i counts.length; i )for (int j 0; j counts[i].length; j )counts[i][j] 0; The length of time the algorithm takes toexecute still depends on the value of N4

Algorithm Efficiency However, in the second algorithm, wehave two nested loops to process theelements in the two dimensional array Intuitively:– If N is half its value, we would expect thealgorithm to take one quarter the time– If N is twice its value, we would expect thealgorithm to take quadruple the time That is true and we say that the algorithmefficiency relative to N is quadratic5

Big-O Notation We use a shorthand mathematical notation todescribe the efficiency of an algorithm relativeto any parameter n as its “Order” or Big-O– We can say that the first algorithm is O(n)– We can say that the second algorithm is O(n2) For any algorithm that has a function g(n) of theparameter n that describes its length of time toexecute, we can say the algorithm is O(g(n)) We only include the fastest growing term andignore any multiplying by or adding of constants6

Eight Growth Functions Eight functions O(n) that occur frequentlyin the analysis of algorithms (in order ofincreasing rate of growth relative to n):– Constant 1– Logarithmic log n– Linear n– Log Linear n log n– Quadratic n2– Cubic n3– Exponential 2n– Exhaustive Search n!7

Growth Rates Compared1n 1 n 2 n 4 n 81111n 161n 40320 20.9TDon’t ask!8

Travelling Salesman Problem Joke9

Big-O for a Problem O(g(n)) for a problem means there is someO(g(n)) algorithm that solves the problem Don’t assume that the specific algorithm thatyou are currently using is the best solutionfor the problem There may be other correct algorithms thatgrow at a smaller rate with increasing n Many times, the goal is to find an algorithmwith the smallest possible growth rate10

Role of Data Structures That brings up the topic of the structure ofthe data on which the algorithm operates If we are using an algorithm manually onsome amount of data, we intuitively try toorganize the data in a way that minimizesthe number of steps that we need to take Publishers offer dictionaries with the wordslisted in alphabetical order to minimize thelength of time it takes us to look up a word11

Role of Data Structures We can do the same thing for algorithms inour computer programs Example: Finding a numeric value in a list If we assume that the list is unordered, wemust search from the beginning to the end On average, we will search half the list Worst case, we will search the entire list Algorithm is O(n), where n is size of array12

Role of Data Structures Find a match with value in an unordered listint [] list {7, 2, 9, 5, 6, 4};for (int i 0; i list.length, i )if (value list[i])statement; // found it// didn’t find it13

Role of Data Structures If we assume that the list is ordered, we canstill search the entire list from the beginningto the end to determine if we have a match But, we do not need to search that way Because the values are in numerical order,we can use a binary search algorithm Like the old parlor game “Twenty Questions” Algorithm is O(log2n), where n is size of array14

Role of Data Structures Find a match with value in an ordered listint [] list {2, 4, 5, 6, 7, 9};int min 0, max list.length-1;while (min max) {if (value list[(min max)/2])statement; // found itelseif (value list[(min max)/2])max (min max)/2 - 1;elsemin (min max)/2 1;}statement;// didn’t find it15

Role of Data Structures The difference in the structure of the databetween an unordered list and an orderedlist can be used to reduce algorithm Big-O This is the role of data structures and whywe study them We need to be as clever in organizing ourdata efficiently as we are in figuring out analgorithm for processing it efficiently16

Role of Data Structures The only data structure implemented in theJava language itself is the array using [ ] All other data structures are implemented inclasses – either our own or library classes To properly use a class as a data structure,we must know the Application Programmer’sInterface (API) The API for a class is documented usingJavadoc comments in the source code thatcan be used to auto-create a web page 17

Javadoc Javadoc is a JDK tool that creates HTMLuser documentation for your classes andtheir methods In this case, user means a programmer whowill be writing Java code using your classes You can access Javadoc via the JDK CLI: javadoc MyClass.java You can access Javadoc via Dr Java menu:Tools Javadoc All DocumentsTools Preview Javadoc for Current Document18

Javadoc The Javadoc tool scans your source filefor specialized multi-line style comments:/*** p HTML formatted text here /p */ Your Javadoc text is written in HTML sothat it can appear within a standardizedweb page format19

Block Tags for Classes At the class level, you must include theseblock tags with data (each on a separate line):/*** @author Your Name* @version Version Number or Date*/ You should include HTML text describing theuse of this class and perhaps give examples20

Block Tags for Methods At the method level, you must include theseblock tags with data (each on a separate line):/*******/@param HTML text for 1st parameter@param HTML text for 2nd parameter. . .@return HTML text for return value If there are no parameters or return type, youcan omit these Javadoc block tags21

In Line Tags At any point in your Javadoc HTML text,you may use In-Line Tags such as @link:/*** p See website {@link name url}* for more details. /p */ In-Line tags are always included inside { } These { } are inside the /** and */so the compiler does not see them22

Big-O Notation We use a shorthand mathematical notation to describe the efficiency of an algorithm relative to any parameter n as its “Order” or Big-O –We can say that the first algorithm is O(n) –We can say that the second algorithm is O(n2) For any algorithm that has a

Related Documents:

It's Practice with Scientific Notation! Review of Scientific Notation Scientific notation provides a place to hold the zeroes that come after a whole number or before a fraction. The number 100,000,000 for example, takes up a lot of room and takes time to write out, while 10 8 is much more efficient.File Size: 290KBPage Count: 8People also search forscientific notation worksheet answersscientific notation worksheet keyscientific notation worksheet pdf answersscientific notation worksheet with answersscientific notation worksheetscientific notation worksheet with answer key

Big O notation. We have already seen that efficiency is defined as the number of operations an algorithm has to perform to achieve its result. Big O notation is simply a convenient theoretical way of measuring the execution of an algorithm, therefore expressing its efficiency. A Big O expression always presents the worst-case scenario.

Recall the definition for scientific notation 1. Change these LARGE scientific notation numbers to standard notation and vice versa. Make up a number for the blank cells. Scientific Notation Standard Notation Scientific Notation Standard Notation a. 6.345 10 e. 5,320 b. 8.04 10 % f. 420,000 c. 4.26 10 & g. 9,040,000,000 d. h. 2. Now try .

Scientific Notation (SN)- A shorthanded way of writing really large or really small numbers. In SN a number is written as the product of two factors. !Ex: 280,000,000 can be written in scientific notation as 2.8!!!10. First Factor Regular Notation ! Scientific Notation Regular Notation How to Change Scientific Notation 420,000.

Scientific notation, also called standard exponential notation, is a subset of exponential notation. Scientific notation represents numeric values using a significand that is 1 or greater, but less than 10, multiplied by the base 10 to a whole-number power. This means that to write a number in scientific notation, the decimal point in the .

scientific notation. Operations in Scientific Notation 1. Perform the calculations on the “number” parts in the front of the scientific notation numbers. 2. Use rules of exponents on the 10n parts of the numbers in scientific notation. 3. Make sure your answer is in scientific notation, if

scientific notation. Scientific notation (also known as standard form) is a way of writing very long numbers using the power of 10. Scientific Notation Scientific Notation When writing numbers in scientific notation, we are writing them so that there is a single non - zero digit in front of the decimal point. For numbers greater than 1, b 0.

Tulang rawan yang paling banyak dijumpai pada orang dewasa. Lokasi : - Ujung ventral iga - Larynx,trachea, bronchus - Permukaan sendi tulang - Pada janin & anak yg sedang tumbuh pada lempeng epifisis Matriks tulang rawan hilain mengandung kolagen tipe II, meskipun terdapat juga sejumlah kecil kolagen tipe IX, X, XI dan tipe lainnya. Proteoglikan mengandung kondroitin 4-sulfat, kondroitin 6 .