Presentation is loading. Please wait.

Presentation is loading. Please wait.

COSC 1P03 Introduction to Data Structures 1.1 COSC 1P03  Audience  planning to major in COSC (prereq. 1P02 60%)  Lectures (AS202, AS217), labs (J301),

Similar presentations


Presentation on theme: "COSC 1P03 Introduction to Data Structures 1.1 COSC 1P03  Audience  planning to major in COSC (prereq. 1P02 60%)  Lectures (AS202, AS217), labs (J301),"— Presentation transcript:

1 COSC 1P03 Introduction to Data Structures 1.1 COSC 1P03  Audience  planning to major in COSC (prereq. 1P02 60%)  Lectures (AS202, AS217), labs (J301), tutorials (AS204), Help Desk (J328)  Web  COSC 1P03: https://lms.brocku.ca/portal/site/COSC1P03D03FW2014MAIN/ https://lms.brocku.ca/portal/site/COSC1P03D03FW2014MAIN/  COSC: http://www.cosc.brocku.ca/ http://www.cosc.brocku.ca/  Course Outline  Textbook  Software  Marking scheme  Assignment submission/return  Plagiarism  Succeeding in COSC 1P03  labs/assignments

2 COSC 1P03 Introduction to Data Structures 1.2 Chapter 1 Arrays

3 COSC 1P03 Introduction to Data Structures 1.3 Arrays  Collection  like Pictures & Sounds  Elements (components)  any type (primitive or object)  Non-sequential processing  not just in order of occurrence  selective (random) processing

4 COSC 1P03 Introduction to Data Structures 1.4 Above-average Rainfall  Months with rainfall above monthly average for year  Non-sequential processing  must process all data to compute average  then process the data to list those above average  12 months  array of 12 double values  declare then create  memory model  Average  loop to read and sum  length attribute  setting element value  getting element value  then compute average  Listing those above average  second loop

5

6 COSC 1P03 Introduction to Data Structures 1.6 Class Statistics  Report with average and standard deviation of student marks  data file  Array of Student objects  Array size not known  choose suitable size (constant)  keep count  Array organization  not all elements used  Standard Deviation formula:

7

8

9 COSC 1P03 Introduction to Data Structures 1.9  Reading data  termination  no more data  no more space  error message?  Computing standard deviation  array as parameter  count also parameter  second traversal

10

11 COSC 1P03 Introduction to Data Structures 1.11 University Statistics  University enrolments at universities in a number of departments  produce summary table  Data  Multi-dimensional  university  department  Multi-dimensional array  declaration  rows are departments  columns are universities

12

13

14 COSC 1P03 Introduction to Data Structures 1.14  Processing  reading statistics  computing department sums  processing by row  computing university sums  processing by column  computing grand total  processing all elements  producing summary table

15

16 Consolidation

17 COSC 1P03 Introduction to Data Structures 1.17 Single-dimensional Arrays  Collection  Use  declaration  creation  subscripting (indexing)  zero-based  NullPointerException  ArrayIndexOutOfBoundsException  length attribute  Memory model  Reference type  array assignment  element assignment

18

19

20 COSC 1P03 Introduction to Data Structures 1.20 Processing One-dimensional Arrays  “Right-Sized”  size known a priori or computable  create with known size  all elements have values  traversal patterns  “Variable-sized”  array size not known  choose arbitrary size (constant)  keep count in ancillary variable  not all elements have values  traversal pattern

21

22

23 COSC 1P03 Introduction to Data Structures 1.23 Multidimensional Arrays  2 or more dimensions  e.g. table  like Picture  Declaration  Creation  Subscripting  length  “Variable-sized”  fill upper left corner  one counter for each dimension

24

25 COSC 1P03 Introduction to Data Structures 1.25 Processing 2-Dimensional Arrays  Random access  a[i][j]  look-up table  Sequential access  row-major order  lexicographic order  algorithm  column-major order  algorithm  regular arrays  Enrolment system example

26

27

28 COSC 1P03 Introduction to Data Structures 1.28 Array Representation  single dimensional  contiguous allocation  value/object/array is sequence of consecutive cells  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

29 COSC 1P03 Introduction to Data Structures 1.29  Multi-dimensional  row-major vs column-major  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 i th 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-l r )  S + (j-l c )  s

30 Row-major Column-major

31 COSC 1P03 Introduction to Data Structures 1.31 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 more efficient  Java uses array-of-arrays allocation  Ragged array

32

33


Download ppt "COSC 1P03 Introduction to Data Structures 1.1 COSC 1P03  Audience  planning to major in COSC (prereq. 1P02 60%)  Lectures (AS202, AS217), labs (J301),"

Similar presentations


Ads by Google