CSE 1341: CS I (Fall, 1999)
Topics Covered since Exam #2
Tuesday, 11/9/99
- Exam#2 review
- generally result
- distribution and interpretation
- ideas for problem solving
- sample solution e2.c
- discussions
- prime factors (e#2-p#2)
- key idea: unique factor?
- formatted output: first and last?
- efficiency: modified from
prime factorization program
- simple program going up with numbers and checking with IsPrime()
- simple but much less efficient
- flag drawing (e#2-p#4): common problem: off center circle
- personal name (e#2-p#4):
- two parts
- deal as one set of conditions (sample solution)
- better yet: same function for first and last name
- hw#10 questions?
Thursday, 11/11/99
- hw#10 questions?
- two key elements to programs: algorithm + data structure
- simple vs. compound data types
- more (advanced) algorithms
- Knuth book: data structure, numerical algorithm, searching and sorting
- compound data types
- Excel assignment (#6) example
- collection of data, treat as one entity
- storage and computation on them
- statistics example: average, median, std. dev., etc.
- intermediate results: e.g., factorial for combinations
- lists, tables, etc.: general database
- array vs. other structured data (list, record, etc.)
- arrays
- ordered: access by index
- homogeneous: same type for each element
- to specify: element type and size
- declaration: e.g., int exam1_score[CSE1341_802_CLASS_SIZE];
- index: start with 0
- work with conventional start of 1
- index range shift
- skip item with index 0
- selection: exam1_score[i]
- statistics example: variance and std. dev
- operates on individual elements in C not an array as a whole
- computation with arrays
- mostly numerical/scientific computations
- sketches for some computations (statistics, etc.)
Tuesday, 11/16/98
- array usage: declaration, initialization, access, as parameters
- array initialization
- at declaration, small arrays
- implicit size with initialization at declaration
- A[] = {....}
- loops for initialization
- read from user input in gymjudge.c
- more common: read from data file
- real-time/control systems: sensor input
- computation with arrays
- examples: gymjudge.c,
- simple search with array: findcoin.c (from ch.12)
- sorting and advantage of sorted data: median, fast search, etc
- (intermediate) results to avoid repeated computation
- statistics: variance and std. dev, modified gymjudge.c
- strings as special case of arrays
- arrays as parameters
- caller: array name
- number of elements in the array
- allocated size vs. effective size
- example calls with array name and array size
- ret_type funcA(a_type A[MaxSize], int actual_size);
- ret_type funcB(a_type A[], int actual_size);
- ret_type funcC(a_type *A, int actual_size);
- 2nd way preferred (less chance for confusion)
- example: findcoin.c
- combination with other parameters: FindIntegerInArray() in findcoin.c
- mechanism: aliasing
- hw#11
Thursday, 11/18/99
- questions about hw#11?
- more array example: from swap to reverse.c
- swap two values in a program: need for temp var
- functional implementation: need for pointers
- array implementation: any two elements
- generalization: reverse.c
- strings: char string[N]; (Chapter 14)
- representation and storage
- standard I/O for strings (Chapter 15)
- scanf()/printf() -- standard input function
- use of pointers in scanf()
-- scanf("%d", &n)
-- see Table 15-1 (p.541)
- scanf("%s", strN) and printf("%s", strN); for "char strN[N]"
- examples from strlib.h and strlib.c in Appendix B
- space character handling
- %s and GetLine() comparison
- [xyz] and [^xyz]
- e.g., to read a whole line, use: scanf("[^\n]", line);
- string as arrays in computation
- elements: char, use ctype.h
- example: acronym.c
- character by character processing
- string operations (Chapter 14)
- ANSI string library: string.h (Table 14-1, p.503)
- specifically: strcpy(), strcat(), strlen(), strcmp(), .....
- optional homework: hw#12
- 20 bonus points
- keywords storage in program, see example in findcoin.c (ch.12)
- search and compare to keywords using "string.h" function "strcmp()" etc.
- sorting as you read things in or sorting at the end
Tuesday, 11/23/99
- more about strings (Chapter 14 and 9)
- ANSI string library: string.h (Table 14-1, p.503)
- specifically: strcpy(), strcat(), strlen(), strcmp(), .....
- strlib.h/chapter 9 for our text
- example: linelen.c
- examples: ncopies.c
- a more comprehensive example
- palindrome.c
- definition and general idea
- implementation using reverse and strcmp()
- generalization:
- skipping over non-letter character
- case-insensitive comparison
- loop control/exiting conditions
- hw#12
- basic string operations: string.h functions
- searching by one-by-one comparison:
- similar to FindIntegerInArray() (in findcoin.c, ch.12)
- but use strcmp()
- ideas for sorting: insert (during) vs. select (after)
- insertion sort: find the right place, insert, and move the rest
- moving/swapping for strings: strcpy
- idea same for individual (numerical) elements
- final exam: Sat. 12/11, 8-11am, select 2 hour slot
- course evaluation?
Thursday, 11/25/99
- Happy Thanksgiving! (no class)
Tuesday, 11/30/99
- more questions about hw#12
- multidimensional arrays
- array: homogeneous elements -> array as element
- 2-d array: matrix (or commonly used tables)
- memory layout and access
- ideas about bit, byte, word, etc.
- initialization: at declaration, init loop/function
- example: symmetry.c
- other examples
- higher dimensional arrays, 3-d and up
- n-d arrays as parameters:
need to specify all dimension sizes except 1st (1st optional)
- reason: indexing and accessing
- n-d array as (static) global variables
- information units
- bit: binary digit
- byte: 8 bits
- word: n bytes, typically n=1, 2, 4, 8...
- memory address: word addressable (some byte addressable)
- final exam information
Thursday, 12/2/99
- character/string as multidimensional arrays:
palindrome.c
- introduction to sorting
- advantage of sorted data
- data structure and sorting: array, (and list, tree, etc.)
- ideas about sorting:
- insertion sort idea for hw#12,
- selection sort
- other sorting algorithms: bubble, quick, etc.
- efficiency: time and space
- selection sort example in "sort.c" (Fig. 12-5, pp.443-444)
- searching of sorted data and homework#12:
- one-by-one comparison: search keyword list
- similar to FindIntegerInArray() (in findcoin.c, ch.12)
- sorted data: binary search idea
- hw#12 partial solution: particularly IsKeywordB() in
- validB.c
- efficiency O(log(n)) instead of O(n)
- binary trees and B-trees, and indexing hierarchies/files
- review for final
- topics covered: on-line list
- general info: see final exam information
- major topics/programming:
- arrays
- strings,
- searching/sorting
- other things: multiple choice and short answer
- office hours for the next week:
- open office
- early afternoons best time to see me
Saturday, 12/11/99
Prepared by Jeff Tian
(tian@seas.smu.edu).
Last update Dec. 2, 1999.