Chapter1.pdf

# Calculated as the sum of the times to execute each

• 61

This preview shows page 30 - 40 out of 61 pages.

Calculated as the sum of the times to execute each machine language instruction in the algorithm’s translation Simplest case, two types of instructions: The non-memory access instructions The memory access instructions

Subscribe to view the full document.

31 Absolute Speed Calculation Example: Total A Two Dimensional Array This algorithm takes 0.0515 seconds to execute assuming: non-memory access instruction require 0.5 nanoseconds memory access instructions require 50 nanoseconds, the array data is 1,000 x 1,000 elements (n = 1000) row = 0; t = 0 ; while ( row < n ) { column = 0 while ( column < n ) { t = t + data[row, column ] column = column + 1 } row = row + 1 }
32 Average Speed of a Data Structure Calculated as the frequency weighted average of the time to perform the structures four operations t avg = t 1 *p 1 + t 2 *p 2 + t 3 *p 3 + t 4 *p 4 where: t i is the time for the i th operation p i is the probability of the i th operation The sum of the probabilities must add up to 1 (e.g., 0.25 + 0.3 + 0.25 + 0.2).

Subscribe to view the full document.

33 Space Complexity of a Data Structure The memory requirements of a data structure The less memory the better The metric of a data structures space complexity is density
34 Density of a Data Structure Density, D, is a measure of how efficiently the structure uses memory Calculated as: D = information bytes / total bytes = information bytes / (information bytes + overhead) where: overhead is the number of bytes required to maintain the structure Because overhead is always > 0, 0 < D < 1 Efficient structures have densities > 0.8

Subscribe to view the full document.

35 A Density Calculation Example 200 nodes each containing 100 information bytes are stored in a structure that requires 4 additional bytes per node to keep track of the node locations. The structure’s density would be: D = (200*100) /(200*100 + 4*100) = 0.98 This a very efficient structure from a space complexity viewpoint
36 Java Review Arrays of primitives Classes and Objects Method naming prefixes Copying objects Arrays of objects Containership Inheritance Generics End Presentation

Subscribe to view the full document.

37 Arrays of Primitives The primitives types are: boolean, byte, short, long, char, float, double Primitive array declaration syntax dataType[] arrayName; arrayName = new dataType[arraySize]; Or dataType[] arrayName = new dataType[arraySize]; Example, a three element integer array: int [] numbers = new int [3];