31251 Lecture Notes - Lecture 1: Data Structure, In C
Data Structures & Algorithms:
Algorithm: A well defined computation process that takes some input and processes an output. Tool
or process used for solving well specified computational problems.
Data structure: A way to store/organise data. A special type of algorithm.
Ed! > CxxTest //research (using C++ 14)
Assessments:
- 3 short multiple choice quizzes
- 2 programming assignments (implementing data structures/algorithms)
- 1 open book exam (multiple choice and short answer) (any note, even typed)
Luke consultation hours: Thursday 2-4 in FEIT learning precinct
C++: -- www.cplusplus.com/reference Past assignment: create a data structure
Week 1:
Strings:
• Strings in C are null terminated char arrays
• C++ has a proper string class (std::string)
• Conceptually wraps a char[] and fixes null
problems
• null vs null ptr. without null program keeps
reading memory until something is found
Arrays:
Arrays in C++ resemble Java:
The arrays above are statically created
• In the examples on the left, the size of he away
was known at declaration
• In C++ the program does its own memory
management so the size needs to be known
• To find the size, arrays decay to pointers the first
element, i.e. int[] can be treated as int*
Static and Dynamic Allocation:
• Static Allocation:
o Variables are automatically allocated when they go out of scope
• Dynamic Allocation:
o Created on the heap using new keyword, this uses more memory
o Unlike Java, all memory management is now manual
o Only use new when necessary to save on potentially wasted memory space
find more resources at oneclass.com
find more resources at oneclass.com
Document Summary
Algorithm: a well defined computation process that takes some input and processes an output. Tool or process used for solving well specified computational problems. 1 open book exam (multiple choice and short answer) (any note, even typed) Luke consultation hours: thursday 2-4 in feit learning precinct. C++: -- www. cplusplus. com/reference past assignment: create a data structure. Strings: strings in c are null terminated char arrays, c++ has a proper string class (std::string, conceptually wraps a char[] and fixes null problems, null vs null ptr. without null program keeps reading memory until something is found. In the examples on the left, the size of he away was known at declaration. In c++ the program does its own memory management so the size needs to be known: to find the size, arrays decay to pointers the first element, i. e. int[] can be treated as int* Pointer: an address that tells you where something is located in memory.