Week 2 Module 1 Notes
Week 2 Module 1 Notes
Tags Course 1
2. Brainstorm solutions
3. Evaluate
4. Try it!
5. Check in
Problem-Solving Phase
The student must read the problem statement several times to ensure that he/she
understands what is asked before attempt to solve the problem.
Problem-Solving Phase-Review
1. Algorithm
Derived from the phonetic pronunciation of the last name Abu Ja’far
Mohammed ibn Musa al-Khwarizmi, who was an Arabic mathematician who
invented a set of rules for performing the four basic arithmetic operations on
decimal numbers.
2. Pseudocode
3. Flowchart
Representations
Algorithms are independent from any programming language and can come in
many forms such as:
Recipes
Flowcharts
Concerned about how fast or slow particular algorithm performs with respect to a
given dataset to process.
Properties of an Algorithm
1. Input
2. Output
3. Definiteness
4. Correctness
5. Finiteness
6. Effectiveness
7. Generality
Data Structures
3. Homogeneous - All the elements are of the same type. (eg. Array)
5. Static - Those whose sizes and structures associated memory locations are fixed, at
compile time. (eg. Array)
6. Dynamic - Those which expands or shrinks depending upon the program need and
its execution. Also, associated memory location changes. (eg. Linked Lists)
Implementation
Data Structures are commonly implemented as classes. These classes are the
model of data structure.
Abstraction
Implementation
An abstract class is a class that is declared as abstract- it may or may not include
abstract methods.
An idea or model of a data types is an abstract data type (ADT). It eliminates the
need for users to worry about how a data type has been implemented. The
implementation of the functions on data type is likewise handled by ADT.
Parameters
Parameters are the variables that are listed as part of a method declaration. Each
parameter must have a unique name and a defined data type.
Parameter Passing
It is the method used to pass one or more values (called actual parameters) to a
function by means of a function call.
Parameter Types
1. Formal Parameter - Usually written in the function prototype, and function header of
the definition.
function_name(datatype variable_name)
Pass by Value - Formal parameter changes are not sent back to the caller.
Pass by Reference - Changes to formal parameter do get transmitted back to the caller
through parameter passing.
Processing Techniques
When processing array elements, we often use either for loop or foreach loop
because all of the elements in an array are of the same type and size of the
array is known.
foreach loop - enables you to traverse the complete array sequentially without using
an index variable.
Array Manipulation
3. concat - combines two arrays together or add more items to an array and then
return a new array.
4. push() - add items to the end of an array and changes the original array.
7. unshift() - adds an item to the beginning of an array and changes the original
array.
8. splice() - copies a given part of an array and returns that copied part as a new
array. It does not change the original array.
10. indexOf() - looks for an item in an array and returns the index where it was
found else it returns -1.
12. filter() - creates a new array if the items of an array pass a certain condition.
16. every() - checks if all items in an array pass the specified condition and returns
true if passed, else false.
17. some() - checks if an item (one or more) in an array pass the specified condition
and returns true if passed, else false.