GDB break – tell the program to ‘pause’ at a certain point (either a function or a line number) step – ‘step’ to the next executed statement next – moves to the next statement WITHOUT ‘stepping into’ called functions continue – move ahead to the next breakpoint print – display some variable’s value backtrace – trace back up function calls
Arrays • Set of variables of the same type sharing a name. • Access each individual element in an array using an index value. • Passed by reference, rather than by value.
Passing By Reference Pass by Value – passing a copy of the data stored in a variable. Pass by Reference – passing the address at which the original copy of the data is stored.
Passing By Reference Mailing Address vs. Contents of Mailbox
## Mail Center Cambridge, MA 02138
Reference
Value
Arrays • Arrays are passed by reference. • Passing an array gives a function the address of the start of the array. int numbers[6]; numbers[0] numbers[1] numbers[2] numbers[3] numbers[4] numbers[5]
numbers
Arrays • Name of the array refers to starting position. • numbers[i] accesses the ith element int numbers[6]; numbers[0] numbers[1] numbers[2] numbers[3] numbers[4] numbers[5]
numbers
Recursion
What is Recursion? • Recursion - a method of defining functions in which the function being defined is applied within its own definition • A recursive function is a function which calls itself
Components of Recursive Function • Recursive Call – part of function which calls the same function again. • Base Case – part of function responsible for halting recursion when appropriate.
Recursion Example • Natural recursive function: Factorial n! = 1 n * (n-1)!
n=1 n>1
Recursion Example int factorial (int n) { //Base Case if (n == 1) return 1; //Recursive Call else return n * factorial(n - 1); }
Recursion Example
Call Stack • Each call to a function gets its own stack ‘frame’ containing that particular instance’s local variables. • When a function calls a function, it creates a new stack frame ‘below’ the previous one.
Call Stack main() func1()
func2() func3()
INCEPTION
Images: “Inception”, Warner Bros. Pictures
We Need To Go Deeper
INCEPTION reality? dream1
dream2 dream3
“The Kick”
Linear Search • Want to find a particular element in an array? • Search through each element until we find it!
Have you tried linear search?
Binary Search • Like searching through the phone book. • Identify whether it’s in the first or second half, dividing the problem in two. Repeat until we’re down to one element. 1
2
4
8
16
45
72
83
906
4012
Asymptotic Notation • Used to describe the runtime of an algorithm. • Runtime measured in terms of how the amount of time taken changes as input size increases.
Asymptotic Notation • Big O notation describes an upper bound on runtime. • Ω describes a lower bound on runtime. • θ describes both an upper and lower bound.
Asymptotic Notation • • • • • • •
1 – Constant Time log n – Logarithmic Time n – Linear Time n2 – Quadratic Time np – Polynomial Time 2n – Exponential Time n! – Factorial Time
Runtime
Log Linear Quadratic
1
2
3
4
5
6
7
8
9
10
Runtime
Quadratic Exponential Factorial
1
2
3
4
5
6
7
8
9
10
11
12
Runtime of Search So... What’s the asymptotic running time of: • Linear Search? • Binary Search?
Bubble Sort • Sorting an array of size n. • Iterate through the array, comparing each pair as you go. If array[i + 1] < array[i], swap them! • Repeat up to n - 1 times (or until array is completely sorted...).
Selection Sort • Grab the smallest and swap it with whatever is at the front of the array. • Now grab the next smallest and swap with what is in position 2. • Repeat until entire array is sorted (again, up to n – 1 times).
Like searching through the phone book. ⢠Identify ... as you go. If array[i + 1] < array[i], swap them! ... Grab the smallest and swap it with whatever is at the front of ...
break â tell the program to 'pause' at a certain point (either a function or a line number) step â 'step' to the next executed statement next â moves to the next ...
A condi on may have two values: true or false. ⢠May be expressed as a logical expression or a. 'bool' variable. ⢠Can be thought of as a yes/no ques on, or a.
Free Candy. â« Time for Change. â« I Saw You ... Free Candy. â« Seriously, in the CS50 ... ask user for an integer printf("Give me an integer between 1 and 10: ");.
Go to middle if k < value at middle search for k between first and the one before the middle if k > value at middle search for k between one after the middle and last if k = value at middle return true. If you haven't found k after this loop, return
Data stored in memory has both a value and a location. ⢠Pointers contain the memory address of some piece of data. ⢠* pointer contains address to a ...
Oct 8, 2010 - Go ahead and execute the command below: hostname. Recall that cloud.cs50.net is actually a cluster of servers. That command tells you the name of the specific server in the cluster that you happen to be connected to at the moment. Take
Data stored in memory has both a value and a location. ⢠Pointers contain the memory address of some piece of data. ⢠* pointer contains address to a ...
We can still conceptualize & prototype using the right language abstractions. â» If we understand relationships between linguistic abstractions, we can realize ...
What you will learn in. CS 179. ⢠Discover and understand people's latent needs. ⢠Invent and construct prototypes. ⢠Design for people different than yourself.
what type are these values? â« how do we initialize them? â« don't forget! â« swap tiles for even d ... Questions? Please email me feedback: [email protected].
11: * Based on Eric Roberts' genlib.h and simpio.h. 12: *. 13: * The latest version of this file can be found at. 14: * http://www.cs50.net/pub/releases/cs50/cs50.h.
In the context of files, Linux uses \n to end lines, Mac OS uses \r, and Windows ... format string's expectation of a leading %f, and so neither f nor c get filled with a ...
What you will learn in. CS 179. ⢠Discover and understand people's latent needs. ⢠Invent and construct prototypes. ⢠Design for people different than yourself.
Computer Science 124 : Who Should Take It. ⢠CS 124 is all about developing techniques for solving problems. ⢠This is what CS is all about! â Take a problem.
Formal Systems and Computation. ⢠Two ways to look at it. 1. Study of problems and computers with all their physicality abstracted away q0 q1 q2 q3 a a a a b b.
should be prompted to Create an Apple ID or Use an existing Apple ID. Review the explanation beneath each option, select the appropriate one, click Continue, then follow the on-âscreen prompts. If you plan to submit an app to Apple's App Store, whe