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

Slides:



Advertisements
Similar presentations
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Advertisements

Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
1 CSE1301 Computer Programming: Revision 1. 2 Topics Type of questions What do you need to know? About the exam Exam technique Staff consultation Sample.
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.
General Computer Science for Engineers CISC 106 Final Exam Review Dr. John Cavazos Computer and Information Sciences 05/18/2009.
CS 206 Introduction to Computer Science II 10 / 14 / 2009 Instructor: Michael Eckmann.
Topic R3 – Review for the Final Exam. CISC 105 – Review for the Final Exam Exam Date & Time and Exam Format The final exam is 120-minutes, closed- book,
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review Topics.
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
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.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 19 Recursion.
Introduction to Data Structures Systems Programming.
1 Chapter 13 Recursion. 2 Chapter 13 Topics l Meaning of Recursion l Base Case and General Case in Recursive Function Definitions l Writing Recursive.
Comp 248 Introduction to Programming Chapter 6 Arrays Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University,
Chapter 14 Dynamic Data Structures Instructor: Kun-Mao Chao ( 台大資工 趙坤茂 )
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 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)
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:
1 Building Java Programs Chapter 7: Arrays These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold, or.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Introduction to Data Structures Systems Programming Concepts.
CHAPTER 3 STACK CSEB324 DATA STRUCTURES & ALGORITHM.
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.
© 2004 Pearson Addison-Wesley. All rights reserved March 10, 2006 Sorting ComS 207: Programming I (in Java) Iowa State University, SPRING 2006 Instructor:
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
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.
CSC Programming for Science Lecture 37 : Course Review.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
MORE POINTERS Plus: Memory Allocation Heap versus Stack.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 11: Pointers.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Recursion COMP x1 Sedgewick Chapter 5. Recursive Functions problems can sometimes be expressed in terms of a simpler instance of the same problem.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
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
The road ahead This class is only the beginning.
Review of C… The basics of C scanf/printf if/elseif statements
C Basics.
CS Week 14 Jim Williams, PhD.
CprE 185: Intro to Problem Solving (using C)
Recursion.
Inheritance April 7, 2006 ComS 207: Programming I (in Java)
Review for the Final Exam
Sorting October 20, 2006 ComS 207: Programming I (in Java)
CprE 185: Intro to Problem Solving (using C)
Instructor: Alexander Stoytchev
CprE 185: Intro to Problem Solving (using C)
CprE 185: Intro to Problem Solving (using C)
Midterm Review October 23, 2006 ComS 207: Programming I (in Java)
EE 312 Exam I Review.
CprE 185: Intro to Problem Solving (using C)
EE 312 Exam I Review.
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

Final Exam Final Exam: Thursday Dec 17: 2:15- 4:15 pm 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 True/False(10 x 1p each = 10p) Fun Stuff( 3 x 5p each = 15p) Short answers( 5 x 3p each = 15p) Code Snippets( 4 x 5p each = 20p) What is the output( 3 x 5p each = 15p) Program 1(15p) Program 2(20p) Program 3(20p) 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

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 road ahead This class is only the beginning. It taught you only the very basics of programming. It taught you very little about many other things. Continue to write programs (even small ones to help you with your other classes or just for fun). Otherwise you’ll forget it all in 1-2 years!

Recommended Books (C language)

Recommended Books (The Unix Operating System)

Recommended Books (algorithms)

Recommended Books (Software Engineering)

Recommended Books (C and Unix)

Recommended Books (Scientific Computing)

Recommended Books (Just for Fun!)

THE END