150 likes | 229 Views
Cosc 1P03. “For myself, I am an optimist--it does not seem to be much use being anything else.” Winston Churchill. Week 1 Lecture slides. COSC 1P03. staff instructors: Dave Bockus, J324 & Dave Hughes, J312 mentor: B. Bork, D328 Tutorial Leader Kelly Moylan, J214
E N D
Cosc 1P03 “For myself, I am an optimist--it does not seem to be much use being anything else.” Winston Churchill Week 1 Lecture slides
COSC 1P03 • staff • instructors: Dave Bockus, J324 & Dave Hughes, J312 • mentor: B. Bork, D328 • Tutorial Leader Kelly Moylan, J214 • planning to major in COSC • prerequisite 1P02 (60%) • outline • labs (J301), tutorials • tests & exam • no electronic devices • WWW and e-mail • assignment submission • disks • plagiarism • students with computers • software • libraries
Arrays(review) • collections of values (objects) • elements • use • declare • create • process • memory model • length attribute • right-sized vs variable-sized arrays • arrays as parameters • Strings as array of char • toCharArray & String(char[]) • palindrome revisited
Multidimensional Arrays • e.g. tables • 2 or more dimensions • enrollment data by university and department • declaration • type ident[]… or type []… ident • creation • new type[expr]… • subscripting • ident[expr]… • length • regular vs irregular arrays • variable-sized • fill upper left corner • one counter for each dimension This form is more consistent with other type declarations. Hence type ident.
Processing 2-Dimensional Arrays • random access • look-up table • sequential access • row-major order • lexicographic order • pattern • column-major order • pattern • regular arrays
E.g. Tabulating Enrolments • data • right-sized array • totals • readStats • row-major processing • sumRows • row processing • sumCols • column processing • sumAll • row-major processing • writeStats • row-major & report generation
Array Representation • contiguous allocation • value/object/array is sequence of consecutive cells • row-major vs column-major • single dimensional • contiguous allocation • address(a[i]) = address(a) + i s • where • s = size of element type • if not zero-based subscripting • address(a[i]) = address(a) + (i-l) s • where • l = lower bound
multi-dimensional • lexicographic (row-major) ordering • consider as array of rows • address(a[i]) = address(a) + i S • where • S = size of row (S=a[0].length s) • start of ith row • address(a[i][j]) = address(a[i]) + j s • substitution gives • address(a[i][j]) = address(a) + i S + j s • for non-zero based • address(a[i][j]) = address(a) + (i-lr) S + (j-lc) s
Arrays of Arrays • non-contiguous allocation • each row contiguous • memory model • addressing • address(a[i][j]) = content(address(a)+i4) + j s • access • row-major order • ragged array • creation
Special Array Forms • large arrays with many zero entries • 1000 1000 double = 8,000,000 bytes • time-space tradeoff • reduce space consumption at cost of time to access
Diagonal Matrix • elements on diagonal, zeros elsewhere • e.g. 1000 1000 has 1000 or 0.1% non-zero • represent as vector of main diagonal • mapping function • address(a[i][i]) = address(d) + i s • class specification • usage
Triangular Matrix • elements above or below diagonal • lower-triangular • 50% elements (n(n+1)/2) filled • n partial rows side-by-side • mapping function • address(a[i][j]) = address(d) + i(i+1)/2 s + j s • also ragged array
TriDiagonal Matrix • one element on either side of diagonal • e.g. 1000 1000 is about 0.3% (3n-2) • place n-partial rows (without zeros) end to end • each offset from last by 2 positions • mapping function • address(a[i][j]) = address(d) + i 2 s + j s
Sparse Matrices • few randomly-distributed non-zero elements • represent only non-zero • cannot use mapping function • Use • Link List Structure • Matrix Compression Algorithms • Covered in Cosc 2P03