Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)

Slides:



Advertisements
Similar presentations
David Notkin Autumn 2009 CSE303 Lecture 13 This space for rent.
Advertisements

Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Week #10 Kyle Dewey. Overview Meeting times Typos Project #3 tidbits Exam Review.
Monday, 12/9/02, Slide #1 CS 106 Intro to CS 1 Monday, 12/9/02  QUESTIONS??  On HW #5 (Due 5 pm today)  Today:  Recursive functions  Reading: Chapter.
Wednesday, 12/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/11/02  QUESTIONS??  Today: CLOSING CEREMONIES!  HW #5 – Back Monday (12/16)
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 19: Recursion.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
1 CSE1301 Computer Programming: Revision. 2 Topics Type of questions What do you need to know? About the exam Exam technique Staff consultation Revision.
CSS 332 PROGRAMMING ISSUES WITH OBJECT-ORIENTED LANGUAGES LECTURE
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Week 6 - Wednesday.  What did we talk about last time?  Exam 1!  And before that…  Review!  And before that…  Arrays and strings.
Instructor: Alexander Stoytchev CprE 281: Digital Logic.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
1 CSE1301 Computer Programming: Revision. 2 Topics Type of questions What do you need to know? About the exam Exam technique Staff consultation Revision.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
© 2004 Pearson Addison-Wesley. All rights reserved October 19, 2007 Sorting ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
Instructor: Alexander Stoytchev CprE 281: Digital Logic.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Introduction to Data Structures Systems Programming Concepts.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 22: Pointers.
Welcome to CISC220H Data Structures in C++ sakai.udel.edu Office Hours: Mon/Wed 3:30PM - 4:30PM TA: Adnan Ozsoy.
© 2004 Pearson Addison-Wesley. All rights reserved March 10, 2006 Sorting ComS 207: Programming I (in Java) Iowa State University, SPRING 2006 Instructor:
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Slides from Shane Griffith (TA and guest instructor in Fall 2008) CprE 185: Intro to Problem Solving.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev CprE 281: Digital Logic.
Instructor: Alexander Stoytchev CprE 281: Digital Logic.
Welcome to CISC220 Data Structures in C++ sakai.udel.edu Office Hours: Tues 3PM - 4PM / Thurs 1PM - 2PM TA: David.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
MORE POINTERS Plus: Memory Allocation Heap versus Stack.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev CprE 281: Digital Logic.
CprE 185: Intro to Problem Solving (using C)
CprE 185: Intro to Problem Solving (using C)
CprE 185: Intro to Problem Solving (using C)
5.13 Recursion Recursive functions Functions that call themselves
Instructor: Alexander Stoytchev
Review of C… The basics of C scanf/printf if/elseif statements
CS Week 14 Jim Williams, PhD.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
CprE 185: Intro to Problem Solving (using C)
Recursion.
Review for the Final Exam
Instructor: Alexander Stoytchev
CSS 161 Fundamentals of Computing Introduction to Computers & Java
Sorting October 20, 2006 ComS 207: Programming I (in Java)
CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev
Instructor: Alexander Stoytchev
CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev
CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev
Midterm Review October 23, 2006 ComS 207: Programming I (in Java)
CprE 185: Intro to Problem Solving (using C)
EE 312 Exam I Review.
CprE 185: Intro to Problem Solving (using C)
CprE 185: Intro to Problem Solving (using C)
Presentation transcript:

Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)

Review for the Final Exam CprE 185: Intro to Problem Solving Iowa State University, Ames, IA Copyright © Alexander Stoytchev

Administrative Stuff HW 10 due 8pm! Ritika will not have office hours this week There will be labs this week (also TA evaluations)

Final Exam Final Exam: Tuesday Dec 16: 9:45am- 11:45am Location: This room.

Final Exam Final Exam: Tuesday Dec 16: 9:45am- 11:45am Location: This room. The final is worth 25% of your grade. The best way to fail this class is to not show up.

Final Format (Tentative) True/False(10 x 1p each = 10p) Short answer( 5 x 3p each = 15p) Code Snippets( 4 x 5p each = 20p) What is the output( 2 x 5p each = 10p) Program 1(20p) Program 2(25p) Program 3(30p) TOTAL (130p)

Final Format You don’t need to get all 130 points to get an A 100 is a 100 You must get at least 65 points in order to pass this exam

Ways to get an ‘A’ on the Final Option 1: –3 programs (75p) –True/False (10p) –Short Answers (15p) –TOTAL: (100p) Option 2: –2 programs(45p) –True/False(10p) –Short Answers(15p) –Code Snippets(20p) –What is the output(10p) –TOTAL: (100p)

General Topics for the Final Everything since midterm2 –Recursion –Stuctures –Strings –Files –Pointers

General Topics for the Final Everything since midterm2 –Recursion –Stuctures –Strihngs –Files –Pointers And everything before midterm2. No topic is off limits!

How to Study for the Final Form a study group. (this will help you overcome your fear) Go back and look at my slides for this class. Go back and look at the sample programs that were demonstrated during the lectures. Programs you wrote during the labs. Homework problems (solve them again). Exercise. And get some sleep.

© 2004 Pearson Addison-Wesley. All rights reserved Recursive Programming // This function returns the sum of 1 to num int sum (int num) { int result; if (num == 1) result = 1; else result = num + sum (n-1); return result; }

sum(1); sum(1)sum(2) Recursive Control Flow In Recursive calls methods can call themselves, but typically with different arguments each time return 1;

Recursive Control Flow In Recursive calls methods can call themselves, but typically with different arguments each time sum(2) sum(1) sum(1); sum(2); sum(3) main() return 1; sum(3);

© 2004 Pearson Addison-Wesley. All rights reserved Recursive Programming main sum sum(3) sum(1) sum(2) result = 1 result = 3 result = 6

Recursion: Fibonacci Numbers The sequence: {0,1,1,2,3,5,8,13,...}

Fibonacci Sequence #include int fib(int n) { int ret; if (n < 2) { ret = 1; } else{ ret= fib(n-1) + fib(n-2); } return ret; } int main() { int i; for(i=0;i<10;i++) printf("%d ", fib(i)); system("pause"); }

Mathematical notation v.s. C code int fib(int n) { if(n <= 1) return n; //base case else return fib(n-1) + fib(n-2); }

Execution Trace

Mystery Recursion void mystery1(int a, int b) { if (a <= b) { int m = (a + b) / 2; printf(“%d “, m); mystery1(a, m-1); mystery1(m+1, b); } } int main() { mystery1(0, 5); system(“pause”); }

Think of recursion as a tree …

… an upside down tree

(a=0, b=5) (a=0, b=1)(a=3, b=5) (a=0, b=-1)(a=1, b=1)(a=3, b=3)(a=5, b=5) (a=1, b=0)(a=2, b=1)(a=3, b=2)(a=4, b=3)(a=6, b=5)(a=5, b=4)

(a=0, b=5) (a=0, b=1)(a=3, b=5) (a=0, b=-1)(a=1, b=1)(a=3, b=3)(a=5, b=5) (a=1, b=0)(a=2, b=1)(a=3, b=2)(a=4, b=3)(a=6, b=5)(a=5, b=4) 2 m=(a+b)/2 => print 2

(a=0, b=5) (a=0, b=1)(a=3, b=5) (a=0, b=-1)(a=1, b=1)(a=3, b=3)(a=5, b=5) (a=1, b=0)(a=2, b=1)(a=3, b=2)(a=4, b=3)(a=6, b=5)(a=5, b=4)

(a=0, b=5) (a=0, b=1)(a=3, b=5) (a=0, b=-1)(a=1, b=1)(a=3, b=3)(a=5, b=5) (a=1, b=0)(a=2, b=1)(a=3, b=2)(a=4, b=3)(a=6, b=5)(a=5, b=4) Traversal Order

Declaring Strings char c[10] = “EE/CprE”; //only 7 chars What about the uninitialized characters in the string?

Array contents Contents of the c array c E E / C p r E \0 ? ? NULL character automatically assigned

Array Contents Program: // character array char c[10] = “EE/CprE”; printf(“%s”, c); //output 1 c[8] = ‘a’; printf(“%s”, c); //output 2 _________________________ Output 1: EE/CprE Output 2: EE/CprE c E E / C p r E \0 a ?

#include … char c[7]; strcpy(c, “Wednesday”); Assign value to a String Watch out for overflow (bad) c W e d n e s d a \0 y overflow a y

#include … char c[7]; strncpy(c, “Wednesday”, 7); Assign value to a String Better to use strncpy  copies up to n characters from the source c W e d n e s d need NULL

#include … char c[7]; strncpy(c, “Wednesday”, 6); c[6] = ‘\0’; //OR c[6] = NULL; //NULL and ‘\0’ are the same Assign value to a String Better to use strncpy  assign NULL to the end afterword c W e d n e s \0

Basic pointer operations int i = 5; Int* ip = &i; printf("%d\n", *ip); [

Basic pointer operations *ip = 7; [

Basic pointer operations int j = 3; ip = &j; [

Basic pointer operations int *ip2; ip2 = ip; [

Basic pointer operations ip = &i; [

Pointers and arrays Array indexing: a[0], a[1], a[2], … int *ip = &a[0]; Pointer indexing: *ip, *(ip+1), *(ip+2), … In general a[i] is “equivalent” to *(ip+i)

Pointer Arithmetic ip2 = ip1 + 3; ip2 - ip1 == 3 (true or false?)

int *ip; int a[10]; ip = &a[3]; ip2 = ip + 1; [

What is the meaning of this? typedef struct node { int value; struct node *next; } node_t; valuenext ?

Inserting a node into a Linked List BeforeAfter [

Deleting a node from a linked list Before: After: [

THE END