[go: up one dir, main page]

0% found this document useful (0 votes)
6 views76 pages

G11 Topic 4 - Computational Thinking (4)

The document discusses computational thinking, focusing on problem-solving through algorithms, decision-making processes, and various programming concepts. It covers topics such as pseudocode, subroutines, methods, and exceptions, emphasizing the importance of structured approaches like top-down design and abstract thinking. Additionally, it highlights the role of fundamental operations, variables, and the use of tools like Gantt charts in project management.

Uploaded by

74thsm5q95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views76 pages

G11 Topic 4 - Computational Thinking (4)

The document discusses computational thinking, focusing on problem-solving through algorithms, decision-making processes, and various programming concepts. It covers topics such as pseudocode, subroutines, methods, and exceptions, emphasizing the importance of structured approaches like top-down design and abstract thinking. Additionally, it highlights the role of fundamental operations, variables, and the use of tools like Gantt charts in project management.

Uploaded by

74thsm5q95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

Computational

Thinking
Topic 4
Problem
A problem is a situation that needs attention and needs to be dealt with or solved.
Whenever we deal with problems, we have to take one or more decisions.
Decision making process
Algorithm
An algorithm is a series of unambiguous instructions designed in order to solve a problem and
achieve a certain goal in a finite number of steps.
According to Knuth (1968) an algorithm must possess the following properties” :
● Finiteness: "An algorithm must always terminate after a finite number of steps a very finite
number, a reasonable number"
● Definiteness: "Each step of an algorithm must be precisely defined; the actions to be carried
out must be rigorously and unambiguously specified for each case"
● Input: "...quantities which are given to it initially before the algorithm begins. These 0 inputs are
taken from specified sets of objects"
● Output: "...quantities which have a specified relation to the inputs“
● Effectiveness: "... all of the operations to be performed in the algorithm must be sufficiently
basic that they can in principle be done exactly and in a finite length of time by a man using
paper and pencil"
Algorithm
An algorithm may be expressed in a number of ways:
● Simple English (natural language)
● Flowchart:
○ A formalized graphic representation method which avoids most issues of ambiguity.
● Pseudocode:
○ is a generic artificial language that describes computer algorithms but does not use the
syntax of any particular programming language.
● Programming languages:
○ is an artificial language designed in such a way so that it may be used by humans in order to
communicate with a computer system.
Pseudocode
○ The main purpose of pseudocode is to help programmers develop computer programs.
○ Because pseudocode is written for humans the syntax used is not as strict as the one used in
computer languages.
○ Pseudocode normally omits details that are not important for human understanding of the
algorithm. Computers can’t interpret a solution in pseudocode form thus it should be
converted to a computer language. When a programmer develops pseudocode he/she does
not necessarily think of a particular computer language.
○ Normally a pseudocode could be converted to any computer language with relative ease. It
is important to understand that writing pseudocode involves paper and pencil.
Computer program
A computer program is a sequence of instructions, written to instruct a computer to
perform a specified task.
General principles
○ Thinking Procedurally:
○ This refers to breaking down a task into a series of steps or instructions. When
thinking procedurally, you focus on the specific sequence of actions needed to
complete a task. It's about following a set process in a structured way to reach a solution.
In programming, this could mean writing out the steps in an algorithm or designing a
flowchart to represent the process.

○ Thinking Logically:
○ Logical thinking is about using reasoning to make decisions, solve problems, or arrive
at conclusions. In computer science, this involves applying logical operations and reasoning
to ensure that an algorithm or program works correctly and efficiently.
○ For example, conditional statements (like if, else, and switch) rely on logical thinking to
determine which path to follow based on a condition.
General principles
○ Thinking Ahead:
○ Thinking ahead involves anticipating potential problems or considering the future
steps of a solution before you act. This could involve planning out algorithms and
programs to avoid errors and inefficiencies.
○ In software development, thinking ahead might involve considering edge cases, handling
exceptions, or predicting how a program might behave with different inputs.

○ Thinking Concurrently:
○ Thinking concurrently refers to managing multiple processes at the same time. In
computer science, this can relate to multitasking, parallel computing, or dealing with multiple
threads or processes running simultaneously.
○ For example, when developing a program with multiple users interacting at once, thinking
concurrently allows you to design systems that handle these interactions without conflict or
delay.
General principles
○ Thinking Abstractly:
○ Abstract thinking is the ability to focus on the high-level concept rather than the
detailed implementation. In computer science, this means dealing with ideas or structures
that are not directly tied to specific examples or concrete details.
○ For example, when designing a class in object-oriented programming, you may think
abstractly about its properties and behaviors, without worrying about the specifics of how it
will be implemented or used right away.

○ Thinking Recursively:
○ Recursive thinking involves solving a problem by breaking it down into smaller instances of
the same problem. It’s a method of problem-solving where a function calls itself to handle
sub-problems.
○ In computer science, recursion is used in algorithms like sorting or searching, where a
function solves a problem by repeatedly calling itself until a base case is reached.
Fundamentals operation
○ Fundamental Operations
○ These are the basic, low-level operations that a computer can perform directly. They are the
building blocks of more complex actions.
○ Examples include:
■ Addition, subtraction (arithmetic operations)
■ Comparison (e.g., greater than, equal to)
■ Data movement (e.g., moving data between memory and registers)
■ Logical operations (AND, OR, NOT)
Compound operation
Compound Operations
These are combinations of fundamental operations that perform more complex tasks.
They are often created to simplify programming and improve readability.
Examples include:
● Calculating the average of a list of numbers
● Searching or sorting a list
● Copying files or folders

These operations rely on multiple fundamental operations working together


Top down design
○ Top-Down Design is a method of problem-solving where you break down a complex
problem into smaller, more manageable sub-problems. You start by designing the
most general and high-level view of a solution, and then gradually break it down into
detailed parts.
○ Simple Explanation:
■ Start with the Big Picture: You begin by understanding the overall goal or problem.
■ Divide the Problem into Smaller Parts: Then, you divide the problem into smaller tasks
that can be solved individually.
■ Break Each Sub-task Further: If necessary, each smaller part can be broken down even
more until you have tasks that are simple enough to implement.
Why Use Top-Down Design?
○ It helps you manage large and complicated problems by breaking them into smaller,
more manageable tasks.
○ It provides a clear, structured approach to problem-solving, making it easier to plan
and implement.
○ You can focus on one part at a time without getting overwhelmed by the whole
system.
Example of Top Down design
Example: Online Store
Step 1: We want to create an online store where customers can browse products and make
purchases.
Step 2: Break It Down into Smaller Parts
■ Display Products, User Accounts, Shopping Cart, Payment
Step 3: Break Each Part Into Even Smaller Tasks
● Let users create an account and log in,
● Shopping Cart: Add items and remove items from the cart.
● Payment: Let users enter payment details and confirm payment.
Input and Output
○ Logical rules or rules inference are obvious rules to most humans.
○ Input is data which is inserted into a system for processing and/or storage.
○ Data entered into a program, either by the programmer or digitally, are referred to as inputs.
These inputs are stored in variables and used to run the program.
○ In order to keep the user informed about what is happening inside the program, a
programmer may choose to include outputs. This is where the data from the program is
shown to the user, either on screen or in the form of a physical output such as printouts or
signals.
○ Output is data which is sent out of a system.
○ Most programs require data from the user. This is processed and the outcome is outputted
or moved to secondary storage.
Variable
○ Programs interact with users by requesting input using the keyboard.
○ Most data in a program is stored in a variable which can be used to hold data inputted by the
user.
○ Variable is a memory location within computer program where values are stored.
○ In the example below, the program asks the user to enter their name, which is stored in the
variable called ‘name’:
Constant
● In Java, a constant is a variable whose value cannot be changed once it is assigned.
● Constants are typically declared using the final keyword, ensuring that their value remains constant
throughout the program's execution.
● By convention, constant names are written in uppercase letters, with words separated by
underscores for readability.
● Constants are useful for values that are meant to remain unchanged, such as mathematical
constants or configuration settings.
● For example, the mathematical constant for pi can be declared as a constant like this:

final double PI = 3.14159;


Concatenation
○ Inputted data can be joined with an output to create a single string. This process of joining
strings together is called concatenation, for example:
○ Concatenation is the process of connecting string or characters next to each other.
Concatenation
○ Inputted data can be joined with an output to create a single string. This process of joining
strings together is called concatenation, for example:
○ Concatenation is the process of connecting string or characters next to each other.
public class ConcatenationExample {
public static void main(String[] args) {
// Declare two strings
String firstName = "John";
String lastName = "Doe";

// Concatenate strings using the + operator


String fullName = firstName + " " + lastName;

// Display the concatenated string


System.out.println("Full Name: " + fullName);

// Alternatively, you can use the concat() method


String greeting = "Hello, ".concat(firstName).concat(" ").concat(lastName);

// Display the greeting message


System.out.println(greeting);

}
}
Concatenation
public class ConcatenationExample {
public static void main(String[] args) {
// Declare two strings
String firstName = "John";
String lastName = "Doe";

// Concatenate strings using the + operator


String fullName = firstName + " " + lastName;

// Display the concatenated string


System.out.println("Full Name: " + fullName);

// Alternatively, you can use the concat() method


String greeting = "Hello, ".concat(firstName).concat(" ").concat(lastName);

// Display the greeting message


System.out.println(greeting);

}
}
Array
○ A set of data values of the same type, stored in a sequence in a computer program.
○ Also known as a list
Pre-planning in a suggested problem and solution
○ Pre-planning is the process of planning in advance.

○ Prefetching in broad terms means getting data or instructions from memory into the cache
before they are actually needed.
■ When a program requests data that was previously prefetched, it can use the prefetched data
and continue with execution, instead of waiting for the data from RAM.
○ This is a typical example of preplanning an action so as to save time and improve efficiency.
Gantt Chart
○ A Gantt chart is a type of bar chart, named after Henry Gantt. It is widely used for project
schedule and project management, as a way of showing activities, tasks and events against
time.
○ On the left of the chart is a list of the tasks, activities and events. Along the top is an
appropriate time scale.
○ A” tasks, activities and events are represented by bars. Each bar represents the duration,
start day and end day of the task, activity or event.
○ A Gantt chart allows easy inspection of the project’s activities, overlapping activities,
the total duration of the project etc.
Pre-conditions and post-conditions
○ Pre-conditions are the things that must be true before a method is called. The method tells
clients "this is what I expect from you".
○ Post-conditions are the things that must be true after the method is complete. The method
tells clients "this is what I promise to do for you".
Subroutine
○ Subroutine is a sequence of program instructions that performs a specific task, packaged
as a unit. It may return one or more values, but does not have to.
○ In different programming languages, a subroutine may be called a procedure, a function, a
routine, a method, or a subprogram.
○ The generic term 'callable unit' is sometimes used.
○ It may be easier to think of them as mini-programs within a large program.
○ Subroutines consist of modules of code that perform different tasks.
○ If these tasks are repeated throughout the program, they can be written as subroutines.
○ Each subroutine is given a unique name so that it can be called and executed quickly
throughout the program, without having to write the code again.
○ This reduces the size of the code, making the program more logical and easier to read and
maintain.
Subroutine
Subroutine advantages
○ Breaking down or decomposing a complex programming task into smaller sub-tasks and
writing each of these as subroutines, makes the problem easier to solve.
○ Subroutines can be used several times within a program.
○ It saves the programmer time as it reduces the amount of code that needs to be
written or amended by allowing you to reuse code without having to write it again.
○ If you are working as part of a team you can divide a large program into smaller
sections and allow individuals to simultaneously work on those sections.
○ It makes the code easier to read if you use sensible subroutine labels as the headings
tell the reader what that section of code is doing.
○ By reducing the amount of repeating tasks you also reduce the risk of introducing errors
in a program.
○ Easy to maintain as each subroutine can be tested separately.
Methods, Function and procedures
○ A method in Java is a subroutine that is part of a class.
○ The subroutine is like a miniature program that can execute in other parts of the program.
Methods promote code reuse and maintainability.
○ There are two different types of subroutines that mainly use:
● Functions.
● Procedures
○ Functions return values back to the main program.
○ Procedures do not return a value back to the main program.
○ A function would return the returning value/control to the code or calling function.
The procedures perform certain tasks in a particular order on the basis of the given
inputs.
Functions
Procedures
Exception
○ Exception is an act or event that disrupts the anticipated flow of program’s execution.
○ The exceptions take place during the execution of the program and can be effectively
handled by specific mechanisms that most modern programming languages provide.
○ An exception is an event that disrupts the normal flow of execution of a program. It
typically occurs due to an error (like dividing by zero or accessing an invalid array
index) or other exceptional conditions that the program should handle.
○ Occur within the program itself due to certain errors or exceptional conditions during
the program's execution.
○ These errors arise from the logic of the program, such as:
■ Dividing by zero
■ Trying to access an index in an array that doesn't exist
■ Null references
■ File not found (in file operations)
Concurrent
○ Concurrent means something that happens at the same time as something else.
○ In computer science, concurrent processing means the execution of different
instructions simultaneously by multiple processors so as to achieve the best
performance.
○ A simplified explanation of this process is that programs are broken down into procedures
and procedures are broken down to sub-procedures.
○ These are then assigned to separate processing units to perform simultaneously.
○ Sequential processing is the execution of all sub—procedures one after the other by a single
processor.
Abstract Thinking
○ Abstract thinking means reflecting on events, ideas, attributes and relationships in a
general manner that hides all unnecessary details of specific objects. All information,
that is not necessary to accomplish a goal, is removed and ignored and a
generalization technique is implemented.
○ Abstraction is used to hide background details or any unnecessary implementation
about the data so that users only see the required information. It is one of the most
important and essential features of object-oriented programming.
○ The user is only given access to the details that are relevant. Vehicle operations or ATM
operations are classic examples of abstractions in the real world.
Compiler
● A compiler is a translator that executes the translation process only once. It
normally translates the whole source program into the object program.
● The object program is saved and next time a programmer wants to use the object
program no recompilation is necessary.
● Compilers issue error messages for all syntax error found and all errors are
communicated to the programmer after the entire program is checked.
● The compilation ends only when all syntax errors have been corrected. Compilers are
much faster than interpreters.
● Examples: C, C++.
Interpreter
● An interpreter is a translator that goes through the process of translation every
time the program is run.
● Interpretation refers to the process of reading each line (instruction) of the source
program, analyzing it, translating it into the corresponding line of the object
program and executing the line.
● Syntax errors are communicated to the programmer for every instruction that is
interpreted. Example: BASIC.
Interpreter and Compiler
● Java combines compilation and interpretation. Source code is compiled to Java
Virtual Machine bytecode.
● When a Java program is compiled from .java file to a .class file, the class file is Java
Virtual Machine bytecode.
● This Java Virtual Machine bytecode can be interpreted by the Java Virtual Machine
interpreter.
● The Java architecture allows code to run on any machine to which the Java Virtual
Machine interpreter has been installed.
● In Java architecture, all details of making the code function on a specific hardware
platform are handled by the Java Virtual Machine (JVM).
Object-oriented programming
● Object-oriented programming uses abstraction, and is based on the principle that all
everyday tasks éan be considered as entities. These entities are either objects or
events.
● Object-oriented programming uses programming objects that describe data (properties) and
behavior (methods) of real objects, and facilitates code reusability and abstraction.
● It makes complex software faster and easier to develop, and facilitates maintenance. It is an
evolution of procedural (structural) programming, which uses procedures that are able to
interact and exchange data as building blocks of programs.
Collection
○ A collection is a data structure that consists of the data and the predefined methods
which operate on the data.
○ A collection in computer science is an abstract data type like queue and stacks.
○ In programming, a collection is a class used to represent a set of similar data type
items as a single unit. These unit classes are used for grouping and managing related
objects.
Collection advantages:
○ The methods of collections are predefined algorithms that the programmer can immediately
use
○ Performance is increased by the data management capabilities provided by the collection
○ Software reuse is facilitated because the use of methods is based on a common language
and a standard interface
Maps
○ Thematic map is an abstraction of reality that shows the spatial distribution and
emphasizes a particular theme, such as the average distribution of income in a specific
geographic area.

○ Topographic maps show abstractions of selected physical features of the


three—dimensional real world at a reduced scale in two-dimensions, paper or a screen.

○ Political maps are designed to show on data such as the boundaries of countries and states
and the location of major cities. These maps are an abstraction of political territory.
Parallel Array
○ Parallel array also known as structure of an array, multiple arrays of the same size such
that i-th element of each array is closely related and all i-th elements together represent
an object or entity.
○ An example parallel array is two arrays that represent x and y coordinates of n points.
○ Two of the most essential applications performs on an array or a record are searching and
sorting.
○ Examples:
■ first_name = ['Bones', 'Welma', 'Frank', 'Han', 'Jack']
■ last_name = ['Smith', 'Seger', 'Mathers', 'Solo', 'Jackles']
■ height = [169, 158, 201, 183, 172]
Parallel Array - Searching
○ Each index in a parallel array corresponds to the data belonging to the same entity in
a record.
○ Thus, for searching an entity based on a specific value of an attribute, e.g. we need to find
the name of a person having height >200 cms in the above example.
○ Thus, we search for the index in the height array having value greater than 200. Now,
once we have obtained the index, we print the values of the index in the first_name
and last_name arrays. This way searching becomes an easy task in parallel array.
Parallel Array - Sorting
○ Now, using the same fact that each index corresponds to data items in different arrays
corresponding to the same entity.
○ Thus, we sort all arrays based on the same criteria.
○ For example, in the above-displayed example, we need to sort the people in increasing order
of their respective heights. Thus, when we swap the two heights, we even swap the
corresponding values in other arrays using the same index.
○ The arrays can be sorted in any way, numerical, alphabetical or any other way but the
elements are placed at equally spaced addresses. Any of the sorting techniques can be
used to sort the record based on a specified criteria.
Arrays of objects
○ An array of objects is an array of reference variables. Each reference variable is an
element of the array and it’s a reference to an object.
○ Suppose a programmer wants to create an array of vehicle objects named A.
■ Each vehicle object has the following data fields: Colour, Type and Engine.
○ The programmer wants to construct an array of vehicle objects with the following
objects:
■ Vehicle1[Colour: "red”—Type: ”car”-Engine:2000]
■ VehicIe2 [Colour: ”green”-Type: ”bus”-Engine:4000]
■ Vehicle3 [Colour: "blue"-Type: ”motorcycle”-Engine:800]
One dimensional array
○ One-dimensional array in Java programming is an array with a bunch of values having
been declared with a single index.
Two dimensional array
○ A two-dimensional array is an
array which technically has
one row of elements,
however, each row has a
bunch of elements defined by
itself.

○ Basically, you need to define


both the rows and columns and
then go ahead with declaring
the elements in the respective
locations or indexes.
Sequential Search (Linear Search)
○ A sequential search (also known as a linear search) is a basic algorithm used to find a
specific element in an array or list. It works by checking each element of the array, one
by one, starting from the first element and moving to the next, until the desired
element is found or all elements have been checked.
○ Advantages:
■ Simple Method: The algorithm goes through each element of the array (or list) one by
one until it finds the desired element or reaches the end of the array.
■ No Need for Sorted Elements: Linear search works on unsorted arrays as well, so you
don’t need the elements to be ordered (sorted) for it to work.
■ Brute Force Strategy: Linear search checks every element sequentially. If the element is
found, it stops, but if not, it continues until the end of the array. This is considered a brute
force approach because it doesn't involve any shortcuts or optimizations.
Linear Search
○ A linear search is the simplest method of searching a data set.
○ Starting at the beginning of the data set, each item of data is examined until a match
is made. Once the item is found, the search ends. If there is no match, the algorithm
must deal with this.
○ A written description algorithm for a linear search might be:
■ Find out the length of the data set.
■ Set counter to 0.
■ Examine value held in the list at the counter position.
■ Check to see if the value at that position matches the value searched for.
■ If it matches, the value is found. Send a message and end the search.
■ If not, increment the counter by 1 and go back to step 3 until there are no more items to
search.
■ If all the items have been checked and no match is found, send a message.
Linear Search
○ Consider this list of unordered numbers:

○ Suppose we were to search for the value 2 in this list. The search would start at position 0 and
check the value held there, in this case 3. 3 does not match 2, so we move on to the next
position.
○ The value at position 1 is 5. 5 does not match 2, so we move on to the next position.
○ The value at position 2 is 2 - a match. The search ends.
○ A linear search can be quite inefficient. Suppose the data set contained 100 items of data, and the
item searched for happens to be the last item in the set. All of the previous 99 items would have to
be searched through first.
○ However, linear searches have the advantage that they will work on any data set, whether it is
ordered or unordered.
Linear Search
○ A linear search in pseudo-code might look like this:
Binary Search
○ Binary search (or half interval search) algorithm is a searching method used only in
sorted arrays.

○ It relies on divide and conquer strategy to accomplish its purpose. In every search
iteration, half of the elements of the array are eliminated as possible solutions.

○ Binary search is very efficient for large arrays. Its performance makes it ideal when resorting
is not required.
Binary Search
○ A binary search is an efficient method of searching an ordered list. It will not work on a
list that has not been sorted first.

○ A written description of a binary search algorithm is:


■ Start by setting the counter to the middle position in the list.
■ If the value held there is a match, the search ends and a message is sent.
■ If the value at the midpoint is less than the value to be found, the list is divided in half, the
lower half of the list is ignored and the search keeps to the upper half of the list.
■ Otherwise, if the value at the midpoint is greater than the value to be found, the upper half
of the list is ignored and the search keeps to the lower half of the list.
■ The search moves to the midpoint of the remaining items. Steps two to four continue until a
match is made or there are no more items to be found and a message is sent.
Binary Search
○ Consider this list of ordered numbers:

○ Consider searching for the value 11.


○ The midpoint is found by adding the lowest position to the highest position and dividing
by 2.
○ Highest position (8) + lowest position (0) = 8
○ 8/2 = 4

○ NOTE - if the answer is a decimal, round up. For example, 3.5 becomes 4.
■ An alternative is to round down, but be consistent.
■ Check at position 4, which has the value 7.
■ 7 is less than 11, so the bottom half of the list - including the midpoint - is discarded.
Binary Search

○ The new lowest position is 5.


○ Highest position (8) + lowest position (5) = 13
○ 13/2 = 6.5, which rounds up to 7
○ Check at position 7, which has the value 14.
○ 14 is greater than 11, so the top half of the list (including the midpoint) is discarded.

○ The new highest position is 6.


○ Highest position (6) + lowest position (5) = 11
○ 11/2 = 5.5, which rounds up to 6
○ Check at position 6.
○ The value held at position 6 is 11 - a match. The search ends.
Binary Search
○ A binary search in pseudo-code might look like this:
Binary Search
○ A binary search is a much more efficient algorithm than a linear search.
○ In an ordered list of every number from 0 to 100, a linear search would take 99 steps to
find the value 99. A binary search would only require 7 steps.
○ However, a binary search can only work if a list has been sorted into order.
Bubble Sort
○ Bubble sort is a simple sorting algorithm that repeatedly steps through the array to be
sorted. It compares adjacent items (pairs of adjacent array elements) and exchanges
them if they are not in the correct order (ascending or descending).
○ The algorithm makes multiple passes until no swaps are necessary and the elements
of the array are sorted.
○ The algorithm is named for the way elements "bubble" to the top of the array.
○ After each loop, one less element (the leftmost) needs to be compared. The algorithm is very
slow and impractical for most cases.
Bubble Sort
The list of ages is:

41, 15, 17, 32, 18, 28, 77 and 54


Bubble Sort
The list of ages is:

41, 15, 17, 32, 18, 28, 77 and 54


Selection Sort
○ Selection sort is a very simple and inefficient sorting algorithm that divides the input
array into two sub—arrays:
■ the first sub—array contains the already sorted elements, and
■ the second sub-array contains the unsorted element and occupies the rest of array.
○ In selection sort algorithm, we search for the lowest element and arrange it to the
proper location. We swap the current element with the next lowest number.
Selection Sort
○ Selection sort works by selecting the smallest element from an unsorted array and
moving it to the front.

Merge Sort
○ A merge sort is a more complex sort, but also a highly efficient one.
○ A merge sort uses a technique called divide and conquer.
○ The list is repeatedly divided into two until all the elements are separated individually.
Pairs of elements are then compared, placed into order and combined.
○ The process is then repeated until the list is recompiled as a whole.
Merge Sort
Merge Sort
Merge Sort
Terms
○ Efficiency of an algorithm refers to the amount of the computer resources required to
perform its functions. Minimizing the use of various resources such as the CPU and
computer’s memory is very important.
○ Correctness of an algorithm refers to the extent to which the algorithm satisfies its
specification, is free from faults, and fulfils all objectives set during the design and
implementation phase.
○ Reliability refers to the capability of the algorithm to maintain a predefined level of
performance and perform all required functions under stated conditions, having a long
mean time between failures.
○ Flexibility of an algorithm refers to the effort required to modify the algorithm for other
purposes than those for which it was initially developed.
Big O-notation
○ Big O notation is a way to describe how the runtime (or performance) of an algorithm
grows as the input size grows. It helps us understand how efficient an algorithm is,
especially when the input size gets very large.
○ A large O notation description of a function generally only offers an upper constraint on the
function's development rate.
○ In computer science, big O notation is used to classify algorithms according to how
their run time or space requirements grow as the input size grows.
○ In other words, it measures a function's time or space complexity.
○ This means, we can know in advance how well an algorithm will perform in a specific
situation.
Big O-notation
What does O(n) mean?
■ O(n) means that as the size of the input list (n) grows, the time it takes for the algorithm to
complete will grow linearly.
■ If the list size doubles, the time it takes to check the list will also double.

In Big O notation, we express the complexity in terms of the size of the input (denoted by
n), but we don’t specify the actual number (like 10, 100, etc.). We just express it in general
terms as O(n), O(1), O(n²), etc., to indicate the growth rate of the algorithm.
Big O-notation

You might also like