0% found this document useful (0 votes)
12 views

Week 2 Module 1 Notes

The document discusses problem solving techniques including identifying problems, brainstorming solutions, and evaluating options. It also covers algorithm complexity, data structures, abstraction, parameters, and array processing.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Week 2 Module 1 Notes

The document discusses problem solving techniques including identifying problems, brainstorming solutions, and evaluating options. It also covers algorithm complexity, data structures, abstraction, parameters, and array processing.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Week 2 - Module 1 Notes

Tags Course 1

5 Steps to Problem solve

1. Identify the problem

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.

Read the problem carefully.

Understand what the problem entails.

Only then, write down the steps 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.

It is an unambiguous specification or set of instructions to solve a problem.

It can perform calculation, data processing, and automation.

2. Pseudocode

Week 2 - Module 1 Notes 1


A logic development tool that uses English statements or clauses to present
the logical steps necessary to solve a problem.

“Pseudo” technically means “false”, Pseudocode means “false code”.

3. Flowchart

This is a type of diagram (graphical or symbolic) that represents an


algorithm or a process. Typically showing the flow of data.

Representations

Algorithms are independent from any programming language and can come in
many forms such as:

Recipes

Flowcharts

Manuals/ Instruction sets

A series of verbal order

Week 2 - Module 1 Notes 2


What do we mean by solving a problem?

1. We can obtain a correct answer for any input.

2. It can be obtained with reasonable costs (time).

What if a problem is unsolvable?

1. It takes a long time for some inputs.

2. It takes so much memory for some inputs.

3. We cannot make any dynamic, flexible algorithm for the problem.

Two important factors in problem solving

1. The nature of the problem.

2. The nature of your solution/ algorithm.

Nature of the problem

Also called computation complexity.

Measured by how much time and space(memory) it takes to be solved.

There are problems that are inherently hard or difficult.

Nature of the algorithm

Also called algorithmic complexity.

Concerned about how fast or slow particular algorithm performs with respect to a
given dataset to process.

Measured in terms of best case, average case, and worst case.

Best case - Sorted dataset

Average case - Partially sorted

Worst case - Unsorted

Operations of an Algorithm (DS)

Week 2 - Module 1 Notes 3


Insert a new data item.

Search for a specified item.

Delete a specified item.

Iterate over a set of values.

Properties of an Algorithm

1. Input

2. Output

3. Definiteness

4. Correctness

5. Finiteness

6. Effectiveness

7. Generality

Data Structures

A computer is an electronic machine which is used for data processing and


manipulation. When programmer collects such type of data for processing, he would
require to store all of them in computer’s main memory. This is where we use data
structures.

What are Data Structures?

An arrangement of data in a computer’s memory.

Relationship of data to each other.

Types of Data Structures

1. Linear - Data items are arranged in a linear sequence. (eg. Array)

2. Non-Linear - Data items are not in a sequence. (eg. Tree, Graph)

3. Homogeneous - All the elements are of the same type. (eg. Array)

Week 2 - Module 1 Notes 4


4. Non-Homogeneous - The elements may or may not be of the same type. (eg.
Generic [Object Class])

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.

On the other hand, algorithms such as adding an element, deleting an element,


updating the value of an element, and iterating through the set of values are in the
form of functions/methods.

Instances of a data structure can be called through creating an object and


performing actions can be done through calling the object’s methods.

Abstraction

An abstraction is used to obscure background information or other extraneous data


implementation so that consumers only see the relevant data.

Week 2 - Module 1 Notes 5


Abstraction is linked with data structures as some users expects security and
anonymity exclusively on some of the data types they construct and creating
abstraction can attain this factors.

Implementation

Abstraction is commonly implemented using abstract classes.

An abstract class is a class that is declared as abstract- it may or may not include
abstract methods.

This class cannot be instantiated, but they can be subclassed.

Abstract Data Types (ADT)

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.

Parameters act as variables inside the method.

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)

2. Actual Parameter - The values passed in the call of a function.


function_name(variable name(s));

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.

Week 2 - Module 1 Notes 6


Array Processing

A fixed-size sequential collection of elements of the same type is stored in an array,


a data structure that Java offers. It is a collection of variable of the same type.

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

Arrays can be manipulated by using several actions known as methods. Some of


these methods allow us to add, remove, modify and do lots more to arrays.

1. toString() - converts an array to string separated by comma.

2. join() - combines all array elements into a string.

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.

5. pop() - removes the last item or an array and returns it.

6. shift() - removes the first item of an array and returns it.

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.

9. split() - divides a string into substrings and returns them as an array.

10. indexOf() - looks for an item in an array and returns the index where it was
found else it returns -1.

Week 2 - Module 1 Notes 7


11. lastIndexOf() - looks for an item from right to left and returns the last index
where the item was found.

12. filter() - creates a new array if the items of an array pass a certain condition.

13. map() - creates a new array by manipulating the values in an array.

14. reduce() - calculates a single value based on an array.

15. forEach() - iterates through an array, it applies a function on all items in an


array.

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.

18. includes() - checks if an array contains a certain item.

Week 2 - Module 1 Notes 8

You might also like