Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS261 Data Structures Fall 2009 Professor Timothy Budd.

Similar presentations


Presentation on theme: "CS261 Data Structures Fall 2009 Professor Timothy Budd."— Presentation transcript:

1 CS261 Data Structures Fall 2009 Professor Timothy Budd

2 Why data structures By this point, you have learned the mechanics of coding - variables, loops, etc This course will help you take the next step in becoming a programming, learning higher level skills, such as abstraction, modularization, correctness, efficiency.

3 Administrivia Go over administrivia - Two midterms, one final Several programming assignments, several homeworks Recitations used for learning programming skills, course will deal more with concepts

4 More administrivia I’m found in KEC 3049 OH: MWF 1:30 - 3:00 for now Two TA’s: they will each hold office hours as well in KEC lobby (see web page)

5 Textbook Textbook is on-line, also with links to many articles (wikipedia and so on) for further information. You should print it out Textbook begins with material you should already have seen - read chapters 1 to 5 immediately.

6 Active Learning This course uses a technique termed Active Learning We do worksheets most every day. Worksheets can be done in groups, helping each other They are gathered and recorded, but only lightly graded

7 Why Data Structures? The study of data structures is considered the cornerstone and starting point for systematic examination of computer science Notice I said computer science, not just programming

8 Ubiquitous Certain collection classes are found in almost every nontrivial program Knowing these keeps you from having to reinvent the wheel

9 Vocabulary The common data structures have well known names Helps provide a vocabulary that is shared by all computer professionals

10 Abstraction Data structures are one of the easiest ideas to visualize abstractly Abstraction is the key idea used by computer professionals to control complexity.

11 Information Hiding and Large Projects An important part of abstraction is information hiding - what details do you NOT need to know? Key to modern large software projects What does programmer A NOT need to know to use the work of programmer B?

12 Tools and Techniques The analysis of data structures provides a good vehicle to learn a variety of mathematical and other analytical techniques Recursion, big-Oh, counting arguments, proof of correctness

13 Design Pattern format A very useful and recent tool Design patterns provide a way to document proven solutions to common problems More importantly, provide a vocabulary Grew out of OO world, starting to become common everywhere else

14 Features of Design pattern Problem: Short statement of problem Solution: Abstract characteristics Forces: Reasons for using pattern Counter-Forces: Reasons for NOT using pattern Example - Façade (change in interface, not in implementation)

15 Questions?? If not, then we do our first worksheet

16 What is O( ) int countOccurrences (double data [ ], int n, double testValue) { int i; int count = 0; for (i = 0; i < n; i++) { if (data[i] == testValue) count++; } return count; }

17 Btw, arrays and pointers are the same. More common: int countOccurrences (double * data, int n, double testValue) { int i; int count = 0; for (i = 0; i < n; i++) { if (data[i] == testValue) count++; } return count; }

18 A loop that is not an array index. What is O( )? int isPrime (int n) { int i; for (i = 2; i * i <= n; i++) { if (0 == n % i) return 0; } return 1; /* 1 is true */ }

19 Calling a function inside another O( )? void printPrimes (int n) { int i; for (i = 2; i < n; i++) { if (isPrime(i)) printf(“Value %d is prime”, i); }

20 What is printf And older way to do printing (before streams). Don’t remember how to use it? Look in the handy pocket reference.

21 Nexted loop (Note, this is pseudo-code, not C) void matMult (int [][] a, int [][] b, int [][] c) { int n = n; // assume all same size int i, j, k; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { c[i][j] = 0; for (k = 0; k < n; k++) c[i][j] += a[i][k] * b[k][j]; }

22 A more subtle loop void selectionSort (double * storage, int n) { int p, i, indexLargest; for (p = n – 1; p > 0; p--) { indexLargest = 0; for (i = 1; i <= p; i++) { if (storage[i] > storage[indexLargest]) indexLargest = i; } if (indexlargest != position) swap(storage, indexLargest, position); }

23 What is the sum? What is the sum of 1 + 2 + 3 + … + (n - 1) ?

24 An operator you might have never seen for (i = n; i > 0; i = i >> 1) … What is the >> operator? Right shift. Imagine that n starts at 100. What are the values that i will go through?


Download ppt "CS261 Data Structures Fall 2009 Professor Timothy Budd."

Similar presentations


Ads by Google