|
|
|
|
|
World consists of objects/components and their
interactions with each other |
|
Goal is to be able to have proven, tested
software components that are reusable, wont have to write all code from
scratch speed software development |
|
Came out of Simulation Simula first OO
language |
|
Encapsulation, Inheritance, Polymorphism |
|
|
|
|
Why save time, dont reinvent the wheel! |
|
Three generic entities: |
|
Container a data structure that organizes
objects a specific way, e.g. stack, queue, vector, list |
|
Iterators object used to reference an element
in |
|
a container, like a pointer, just for some
containers like list |
|
Algorithms frequently used functions on
containers e.g. make-heap, find_first, sort ( Appendix B Drozdek) |
|
|
|
|
Used to look at time and space complexity now
just time |
|
As the size of the data set grows, how does the
time the algorithm takes to run grow? |
|
In a formula, take fastest growing term, ignore
constant multipliers |
|
|
|
|
|
Usually use n as the variable to denote size
of the data set |
|
If have expression for run-time complexity |
|
F(n) = 7 e**n + 100 n **2 + 250 n + 1,000,000 |
|
Dominant term above, as n grows large is? |
|
|
|
|
|
|
STL vectors |
|
Lists |
|
Stacks |
|
Queues |
|
|
|
|
|
|
|
|
|
|
#include <list> |
|
list<int>
iList ; iList.push_front(5); iList.pop_back(); |
|
list<char> cList;
cList.clear(); if(cList.empty())
. |
|
list<anyClass> acList; int
size=acList.size(); |
|
|
|
|
|
|
|
#include <stack> |
|
|
|
stack<int> iStack iStack.push(5); |
|
|
|
stack<char> cStack; cStack.pop(); |
|
|
|
stack<anyClass> acStack; |
|
|
|
|
|
|
A problem solving tool as well as a feature
incorporated in programming languages |
|
|
|
Recursive problems have two features |
|
Solutions are easy to give for special states
(stopping states) |
|
For a given state (not a stopping state) there
are clear rules for how to proceed to a new state. This new state is either |
|
a) a stopping state b) leads to a
stopping state |
|
|
|
|
What goes on in memory with a recursive call? |
|
With each recursive call a local environment (or
stack frame) is stacked which includes enough storage for: |
|
1) LOCAL VARIABLES |
|
2) VALUE PARAMETERS |
|
3) REFERENCES (POINTERS) BACK TO
CALL-BY- REFERENCE
PARAMETERS |
|
4) CELL FOR PASSING BACK THE VALUE OF
THE FUNCTION (FOR
NON-VOID FUNCTIONS) |
|
5) THE ADDRESS TO RETURN TO AFTER
COMPLETING THE EXECUTION
OF THE CURRENT RECURSIVE CALL |
|
|
|
|
Recursion exemplifies DIVIDE AND CONQUER problem-solving strategies --- |
|
Example: TOWERS OF HANOI - 19th
century parlor game with 64 disks |
|
|
|
|
|
|
|
|
|
Object: Move all disks from peg1 to peg3 using
peg2 for intermediate storage |
|
Rules: One disk moved at a time, and a disk can
never rest on a smaller disk |
|
|
|
|
|
|
|