Algorithm is a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.
It is a definite way to accomplish a task with finite number of steps.
Pseudocode is a notation resembling a simplified programming language, used in program design.
For example:
Problem is :
Print the type of a grade of students in a class. If a student failed, remove the student from the class. If he has "excellent" or "good" grade, give him a bonus in the grade (each type of grade will have a different bonus).
The pseudocode is:
1. for student in class.students
1.1. if student.isFailed()
1.1.1 print "fail"
1.1.2 class.removeStudent(student)
1.2. else if student.isEnough()
1.2.1 print "enough"
1.3. else if student.isGood()
1.3.1 print" good"
1.3.2 class.giveBonus(student, "good")
1.4. else
1.4.1 print "excellent"
1.4.2 class.giveBonus(student, "excellent")
A method for problem solving and functions creation:
Also there are these steps for writing a good solution:
Recursion is a method of solving problems that involves breaking a problem down into smaller and smaller subproblems until you get to a small enough problem that it can be solved trivially. Usually recursion involves a function calling itself.
These are the steps for solving recursion problem:
For example, the given problem is to compute factory of a given integer greater than 0.(let's call it "n").
With iterative solution you would solve it like this:
function factory(n)
1. result = 1
2. for (i = 1; i <= n; i++)
2.1 result = result * i
3. return result
In recursive solution you would solve it like this:
function factory(n)
1. if n equals 1
1.1 return 1
2. return factory(n - 1) * n
Here, the stop condition is if n equals 1. If n is 1 then return 1 because factory of 1 is 1.
Then we define the problem of the problem with one less step (that it is factory of number less by 1) and then we adding solution to current step (which is multiplying by the current number).
Recursion is used with data structures such as binary trees and graphs.
You can also use divide and conquer solution method which is dividing the problem to to smaller sub-problems, solving them and eventually combining them to get the desired output. The performance of this solution is very efficient.
Use strategies to divide big tasks into smaller tasks:
Performance is very important for programming. The efficiency of an algorithm depends on the amount of time, storage and other resources required to execute it.
It may not have the same performance for different type of inputs.
There are different asymptotic analysis for different use cases of the algorithm such as:
They represent the growth rate of an algorithm as the input size increases.
For example, if an algorithm has a time complexity of O(n^2), it means that the algorithm's time requirements grow no faster than the square of the input size.
Usually, you should use the Big-O notation to analysis your algorithm in order to make an algorithm to be the most efficient in the worst cases.
Here are more examples about different time complexities:
Here are more tips:
These are some important categories of algorithms used with data structures:
Each process has input, output, and error output.
Standard input is the file handle that a process reads to get information from (can be information from a user).
Standard output is the file handle where the process writes conventional output to.
Standard error is the file handle where the process writes diagnostic output to.
You can modify a program to redirect stderr into stdout.
For example in JavaScript you do this by running npm start 2>&1.
Building upon your algorithmic knowledge, we then explore the world of data structures. Data structures are essential for organizing and managing data efficiently, enabling us to store, retrieve, and manipulate information with ease.