Introduction
Introduction
Fundamentals of Programming
Course Introduction
▸ Syllabus
▸ Course objectives
- The course provides basic knowledge of programming techniques as one of the fundamental
knowledge in the field of Management Information Systems. In addition, the course presents basic
concepts of algorithms and how to develop algorithms. The course also provides knowledge of the C#
programming language, such as data types; declaration of variables, constants, and expressions;
assignment commands; data input and output; branching and loop control structures; 1- and 2-
dimensional arrays; functions/methods; string types; files,... so that students can apply and install
algorithms from basic to advanced levels.
▸ Learning Outcomes
- Knowledge
• CLO1.1: Understand the basic concepts of structured programming.
• CLO1.2: Understand how to build and implement algorithms.
• CLO1.3: Master knowledge of structured programming languages and their components.
- Skill
• CLO2.1: Analyze problems and build algorithms.
• CLO2.2: Proficient in using compilers.
• CLO2.3: Proficient in using structures and data types.
• CLO2.4: Proficient in using functions and files.
• CLO2.5: Build computer programs.
- Autonomy and Responsibility
• CLO3.1: Can analyze and build programs to solve problems.
• CLO3.2: Be responsible and proactive in doing group exercises and homework.
1
05/08/2024
Course Structure
▸Textbook: Mark Michaelis, Essential C# 12.0. 8 Ed, Addison-Wesley
Publisher, 2024.
▸Reference: Joseph Albahari, C# 12 in a Nutshell: The Definitive Reference
1st Edition, O’Reilly Media Publisher, 2024
▸Content:
- Introduction to Computer Programming
- Structure Programming Language Fundamentals (SPL)
- Function in SPL
- Arrays and Strings
- File Handling
- Advance topics
Assessment
Criteria Percentage
Attendance: 10%
Discuss: 0%
Harvest: 0%
Give a talk: 10%
Report: 0%
Mid-term exams: 30%
Exam at the end of the module: 50%
2
05/08/2024
Problem solving
3
05/08/2024
[1] Seel, N.M. (2012). Problems: Definition, Types, and Evidence. In: Seel, N.M. (eds)
Encyclopedia of the Sciences of Learning. Springer, Boston, MA, pp 2690–2693.
https://doi.org/10.1007/978-1-4419-1428-6_914
Problem Solving
▸Workaround
- Initiated by Rene Descartes (1596-1650).
- Observation: the problem solver must go about things in the right way and must use
the right method to arrive at a solution.
- Right method algorithm
- The term of algorithm was introduced by Abu Jafar Muhammad bin Musa al-
Khwarizmi in AD 820
▸Definition 1:
- Problem solving is a process by which a situation is analyzed, and solutions are
formed to solve a problem with identified steps to resolve, eliminate or mitigate the
problem.
▸Definition 2:
- Problem solving is the process of constructing and applying mental representations
of problems to finding solutions to those problems that are encountered in nearly
every context. [1]
[1] Jonassen, D.H., Hung, W. (2012). Problem Solving. In: Seel, N.M. (eds) Encyclopedia of the Sciences of Learning. Springer,
Boston, MA. https://doi.org/10.1007/978-1-4419-1428-6_208, pp 2680–2683
8
4
05/08/2024
Problem Solving
Process
Fig 1. Problem solving process from the initial situation to the final goal
Problem Solving
Strategies
▸There are four basic modelling structures used in solving problems:
- Linear
- Iterative
- Parallel
- Dynamic (based on interactions and interrelations between tasks)
Linear
Parallel
Iterative
10
10
5
05/08/2024
Problem Solving
Real World Problem-Solving (bonus)
▸Definition 4: (Real World Problem-Solving)
- In cognitive psychology, the term 'problem-solving' refers to the mental process that
people go through to discover, analyze, and solve problems. [1]
[1] Sarathy V. Real world problem-solving. Front Hum Neurosci. 2018;12:261. doi:10.3389/fnhum.2018.00261
(https://www.frontiersin.org/articles/10.3389/fnhum.2018.00261/full )
11
11
Problem Solving
Real World Problem-Solving (bonus) - Strategies
▸Algorithms
- An algorithm is a step-by-step procedure that, by following certain "rules" produces
a solution.
▸Heuristics
- Heuristics are shortcut strategies that people can use to solve a problem at hand.
These "rule of thumb" approaches allow you to simplify complex problems, reducing
the total number of possible solutions to a more manageable set.
▸Trial and Error
- A trial-and-error approach to problem-solving involves trying a number of potential
solutions to a particular issue, then ruling out those that do not work.
▸Insight
- In some cases, the solution to a problem can appear as a sudden insight.Insight can
occur when the problem in front of you is similar to an issue that you've dealt with
in the past.
12
12
6
05/08/2024
Funny
13
Source: https://366pi.com/problem-of-defining-the-problem-einsteins-solution/
13
14
14
7
05/08/2024
Algorithm
Definition
▸Definition 1: An algorithm can be defined as "an ordered set of
unambiguous, executable steps that defines a terminating process"
(Brookshear, 2006).
▸Definition 2: “A set of finite rules or instructions to be followed in
calculations or other problem-solving operations”
▸Definition 3: “A procedure for solving a mathematical problem in a finite
number of steps that frequently involves recursive operations”.
15
15
Algorithm
Usage
▸Algorithms are necessary for solving complex problems efficiently and
effectively.
▸They help to automate processes and make them more reliable, faster,
and easier to perform.
▸Algorithms also enable computers to perform tasks that would be
difficult or impossible for humans to do manually.
▸They are used in various fields such as mathematics, computer science,
engineering, finance, and many others to optimize processes, analyze
data, make predictions, and provide solutions to problems.
16
16
8
05/08/2024
Algorithm
Characteristics
17
17
Algorithm
Characteristics
▸Clear and Unambiguous: The algorithm should be clear and unambiguous. Each
of its steps should be clear in all aspects and must lead to only one meaning.
▸Well-Defined Inputs: If an algorithm says to take inputs, it should be well-
defined inputs. It may or may not take input.
▸Well-Defined Outputs: The algorithm must clearly define what output will be
yielded and it should be well-defined as well. It should produce at least 1
output.
▸Feasible: The algorithm must be simple, generic, and practical, such that it can
be executed with the available resources. It must not contain some future
technology or anything.
▸Language Independent: The Algorithm designed must be language-independent,
i.e. it must be just plain instructions that can be implemented in any language,
and yet the output will be the same, as expected.
▸Finiteness: An algorithm must terminate after a finite number of steps in all test
cases. Every instruction which contains a fundamental operator must be
terminated within a finite amount of time. Infinite loops or recursive functions
without base conditions do not possess finiteness.
18
18
9
05/08/2024
Algorithm
Other characteristics
▸Input: An algorithm has zero or more inputs. Each that contains a
fundamental operator must accept zero or more inputs.
▸ Output: An algorithm produces at least one output. Every instruction
that contains a fundamental operator must accept zero or more inputs.
▸Definiteness: All instructions in an algorithm must be unambiguous,
precise, and easy to interpret. By referring to any of the instructions in an
algorithm one can clearly understand what is to be done. Every
fundamental operator in instruction must be defined without any
ambiguity.
▸Effectiveness: An algorithm must be developed by using very basic,
simple, and feasible operations so that one can trace it out by using just
paper and pencil.
19
19
Algorithm
Types of Algorithms
▸Brute Force Algorithm
▸Recursive Algorithm
▸Backtracking Algorithm
▸Searching Algorithm
▸Sorting Algorithm
▸Hashing Algorithm
▸Divide and Conquer Algorithm
▸Greedy Algorithm
▸Dynamic Programming Algorithm
▸Randomized Algorithm
▸…
20
20
10
05/08/2024
Algorithm
Pros/cons
21
21
Algorithm
Strategy
1. Pre-requisite:
1. The problem that is to be solved by this algorithm i.e. clear problem definition.
2. The constraints of the problem must be considered while solving the problem.
3. The input to be taken to solve the problem.
4. The output to be expected when the problem is solved.
5. The solution to this problem, is within the given constraints.
2. Designing the algorithm
- Pseudo code (/steps) or,
- Flow chart
3. Testing the algorithm
- Implementing then testing
- Analyzing/check
• Priori analysis
• Posterior
22
22
11
05/08/2024
Algorithm
Design
Example: Solve the equation 𝑎𝑥 + 𝑏 = 0
▸Pre-requisite
- Constraints 𝑎, 𝑏 ∈ 𝑅
- Input: the values of 𝑎, 𝑏 (e.g., {a=2.0, b=4.0})
- Output: the value of 𝑥
▸Pseudo-code
- If 𝑎 = 0 the
• If b = 0 then x is any values
• If b ≠ 0 the equation has no solution
- If 𝑎 ≠ 0 then
• The equation has only one solution 𝑥 = −𝑏/𝑎
Fig. 1: Flowchart
23
23
Algorithm
Implement
#include <stdio.h>
int main() {
void solve_equation(float a, float b) { float a,b;
if (a == 0) printf("Enter a number a=");
if (b == 0) scanf("%f",&a);
printf("%s", "There is no x."); printf("Enter a number:");
else scanf("%f",&b);
printf("%s", "X can be any number"); solve_equation(a, b);
else { return 0;
float x = -b / a; }
printf("x = %.3f", x);
}
}
24
24
12
05/08/2024
Flowchart
Introduction
▸Flowchart is a diagram of the
sequence of movements or
actions of people or things
involved in a complex system
or activity.
▸OR: A flowchart is a diagram
that depicts a process, system
or computer algorithm. They
are widely used in multiple
fields to document, study,
plan, improve and
communicate often complex
processes in clear, easy-to-
understand diagrams.
https://www.gliffy.com/blog/guide-to-flowchart-symbols
25
25
Developing Environment
▸The Compiler
▸Unit test
26
26
13
05/08/2024
27
27
14