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

Programming Lessons

Programming lessons for algorithms
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Programming Lessons

Programming lessons for algorithms
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

algorithms

Lesson #1

A programming algorithm is a procedure or formula used for solving a problem. It is


based on conducting a sequence of specified actions in which these actions describe
how to do something, and your computer will do it exactly that way every time. An
algorithm works by following a procedure, made up of inputs. Once it has followed
all the inputs, it will see a result, also known as output.
Characteristics of an algorithm:
1. Precision – the steps are precisely stated.
2. Uniqueness – results of each step are uniquely defined and only depend on
the input and the result of the preceding steps.
3. Finiteness – the algorithm stops after a finite number of instructions are
executed.
4. Input – the algorithm receives input.
5. Output – the algorithm produces output.
6. Generality – the algorithm applies to a set of inputs.
There are seven different types of programming algorithms:
1. Sort algorithms
2. Search algorithms
3. Hashing
4. Dynamic Programming
5. Exponential by squaring
6. String matching and parsing
7. Primality testing algorithms
The advantages of programming algorithms include:
 A stepwise representation of a solution to a given problem, making it easy
to understand.
 Uses a definite procedure.
 Not dependent on a particular programming language.
 Every step in an algorithm has its own logical sequence, making it easy to
debug.
Pseudocode
Lesson #2

Pseudocode is a detailed yet readable description of what a computer program or


algorithm should do. It is written in a formal yet readable style that uses a natural
syntax and formatting so it can be easily understood by programmers and others
involved in the development process. Pseudocode is not a programming language
and cannot be compiled into an executable program. Instead, it serves as a blueprint
for translating the code's logic into an actual programming language.

HOW DO WE WRITE A PSEUDOCODE?


The pseudocode begins with a short introductory statement that describes the script's
purpose. Not everyone includes an introductory statement, but it can be useful in
explaining what the code does so it can be more easily and quickly understood. The
statement is followed by the pseudocode itself, which describes the script's logic,
using the following conventions:
 The pseudocode uses plain language mixed with keywords that convey
specific constructs, such as an iteration FOR statement or conditional IF…
ELSE statement.
 Each new statement and statement element starts a new line.
 Keywords that introduce some types of constructs are in uppercase, as in
SET, FOR, IF, SORT and PRINT.
 Code blocks such as conditional statements (e.g., IF…ELSE statement) or
iteration statements (e.g., FOR statement) are closed with an "END"
keyword, as in ENDFOR and ENDIF.
 The elements within code blocks are indented according to the logic flow.
For example, a code block embedded into the outer code block is indented,
as are the elements within the embedded code block.
 Syntax and formatting are consistent throughout, such as using SET for all
variable assignments.
flowchart
Lesson #3

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.

FLOWCHART SYMBOLS

Terminator

Process

Decision
Document

Data, Input or Output

Stored Data

Flow arrow
Comment or Annotation

On-page connector

Off-page connector
Errors in programming
Lesson #5

Errors in programming refer to issues or defects that arise within the program,
resulting in abnormal behavior. Even experienced developers can make these
mistakes, which are also referred to as bugs or faults. The process of eliminating
these errors is called debugging. These errors in Programming can be identified
during the program’s compilation or execution, and it’s crucial to remove them to
ensure the program runs smoothly. Here we will discuss the various types of errors
in programming and some of the common causes behind them. So, let’s dive straight
into the topic of Types of Errors in Programming.

What are the Different Types of Errors in Programming?


As mentioned above errors refers to issues that occur in a program that results in
unwanted behavior of the program. Some common Types of Errors in Programming
are listed below.
 Syntax Error
 Run-Time Error
 Linker Error
 Logical Error
 Semantic Error

Syntax Error
A syntax error is the most common type of error in programming. It occurs when the
programmer writes code that is not in accordance with the syntax of the
programming language. Syntax errors are detected by the compiler, and the compiler
reports an error message to the programmer.
Common examples of syntax errors include,
 Forgetting to add a semicolon,
 Spelling a keyword incorrectly
 Missing a closing brace.
Example of Syntax Error
Here is an example code having a syntax error.

Run-time Error
A run-time error occurs during the execution of a program. These errors occur when
a program tries to perform an illegal operation, such as dividing by zero or
attempting to access an invalid memory address. The program compiles without
errors, but when it runs, it encounters an error that causes it to terminate abnormally.
Run-time errors are often difficult to detect because they do not show up until the
program is executed.
Example of Run-Time Error
Let us see a C++ code that throws a runtime error.

Linker Error
A linker error occurs when a program references a function or variable that is not
defined in the program or the libraries it is linked against. Linker errors typically
occur when a program is compiled and linked. The linker will report an error if it
cannot find the necessary files or libraries to link the program.
Example of Linker Error
Here is the code that will show the linker error.

Logical Error
A logical error occurs when the program compiles and runs without any syntax, run-
time, or linker errors, but the output is incorrect. These errors occur when the
program's logic or algorithms are incorrect. Logical errors are challenging to detect
because the program does not generate any error messages.
Example of Logical Error
Let us understand this error with the help of an example.
Semantic Error
Semantic errors are errors that occur when the code written by the programmer
makes no sense to the compiler, even though it is syntactically correct. They are
different from syntax errors, which indicate errors in the structure of the program, as
semantic errors are related to the meaning and implementation of the program.
For example,
 Using a string instead of an integer or accessing an array index that is out of
bounds can cause semantic errors.
 Uninitialized variables and type incompatibility are other common types of
semantic errors.
Example of Semantic Error
Here is the code for a better understanding of Semantic Errors in Programming.

Introduction to python
Lesson #6

What is Python?
Python is a popular programming language. It was created by Guido van Rossum,
and released in 1991.
It is used for:
 web development (server-side),
 software development,
 mathematics,
 system scripting.
What can Python do?
 Python can be used on a server to create web applications.
 Python can be used alongside software to create workflows.
 Python can connect to database systems. It can also read and modify files.
 Python can be used to handle big data and perform complex mathematics.
 Python can be used for rapid prototyping, or for production-ready software
development.
Why Python?
 Python works on different platforms (Windows, Mac, Linux, etc.).
 Python has a simple syntax similar to the English language.
 Python has syntax that allows developers to write programs with fewer
lines than some other programming languages.
 Python runs on an interpreter system, meaning that code can be executed as
soon as it is written. This means that prototyping can be very quick.
Python Syntax compared to other programming languages
 Python was designed for readability, and has some similarities to the
English language with influence from mathematics.
 Python uses new lines to complete a command, as opposed to other
programming languages which often use semicolons or parentheses.
 Python relies on indentation, using whitespace, to define scope; such as the
scope of loops, functions and classes. Other programming languages often
use curly-brackets for this purpose.
Python syntax
Lesson #7

You might also like