1 / 15

Week 1 Lecture slides

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

Télécharger la présentation

Week 1 Lecture slides

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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

  3. 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

  4. 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.

  5. Processing 2-Dimensional Arrays • random access • look-up table • sequential access • row-major order • lexicographic order • pattern • column-major order • pattern • regular arrays

  6. 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

  7. 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

  8. 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

  9. Arrays of Arrays • non-contiguous allocation • each row contiguous • memory model • addressing • address(a[i][j]) = content(address(a)+i4) + j  s • access • row-major order • ragged array • creation

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. The End

More Related