0% found this document useful (0 votes)
253 views5 pages

CCDSALG Reviewer

The document discusses algorithms and their analysis. It covers algorithm definition, design issues of correctness and efficiency, and performance analysis in terms of time and space complexity. Methods of analyzing algorithms include studying their behavior as input size increases, predicting execution time and memory usage, and comparing algorithms. Key analysis methods are a priori analysis to predict efficiency and a posteriori analysis using experiments. Searching and sorting arrays are discussed as examples.

Uploaded by

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

CCDSALG Reviewer

The document discusses algorithms and their analysis. It covers algorithm definition, design issues of correctness and efficiency, and performance analysis in terms of time and space complexity. Methods of analyzing algorithms include studying their behavior as input size increases, predicting execution time and memory usage, and comparing algorithms. Key analysis methods are a priori analysis to predict efficiency and a posteriori analysis using experiments. Searching and sorting arrays are discussed as examples.

Uploaded by

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

CCDSALG Reviewer

Contents:

I. Analysis of Algorithms

II. Sorting

III. Growth of Functions

IV. Elementary Data Structures

- Midterm Exam -

V. Searching

VI. Graphs

- Final Exam -

Algorithm Analysis

Algorithm (Definition)

- Defined step-by-step process that operates on certain input values and generates specific output values.
- Serves as a computational procedure with clear instructions on how to transform the given inputs
into the desired outputs.
- It is like a recipe that guides a computer or a person in performing a task by providing a series of well-
defined actions to follow.
- There can be more than one algorithm to solve a given problem.
- An algorithm can be implemented using different programming languages on different platforms.

Example:

Input: a sequence of n numbers {a1,a2,…,an}

Output: a permutation (reordering) {a’1,a’2,…,a’n} such that a’1≤a’2≤…≤a’n

Solution: Sorting Algorithms

Important aspects of designing efficient and effective algorithms:

1. Algorithm Design Issues:


a. Correctness (Does it solve the computational problem?)
b. Efficiency (How fast can it run?)
2. Performance Analysis:
a. Time (What parts of it affect the runtime?)
b. Space (How does the choice of data structure affect the runtime?)
3. Analyzing Algorithms:
a. Study (What happens if the input size is increased?)
b. Predict performance (Predict the execution time and memory consumption of an algorithm)
c. Compare algorithms (Is there a more efficient way of solving the problem?)
d. Design better solutions (Given an existing algorithm, can a modified optimal algorithm be
defined?)
e. Assumptions:
 Instructions are executed ONE AT A TIME, NO CONCURRENT OPERATIONS.
 Instructions are implemented following instructions commonly found in real computers.

Key analysis methods for algorithms:

Both a priori and a posteriori analysis play important roles in understanding and evaluating algorithm
performance.

 Priori analysis helps in predicting and comparing algorithms' efficiency based on theoretical bounds.
 Posteriori analysis provides concrete measurements through practical experiments.

In order to determine the exact execution time of a command, several factors need to be known:

- The specific machine on which the command will be executed.


- The instruction set architecture of that machine.
- The time required for each individual machine instruction to execute.
- The translation process performed by the compiler to convert the source code into machine language.

LINEAR RELATIONSHIP: execution time of an algorithm increases at the same rate as the input size
increases.

BETTER TIME COMPLEXITY: if an algorithm does not have a linear relationship, it means that the execution
time does not increase at the same rate as the input size.

Two common examples of better time complexity:

1. Sublinear: the execution time grows at a slower rate than the input size. For example, if the input size
doubles, the execution time might increase by a smaller factor, like logarithmically.
2. Logarithmic: the execution time increases logarithmically as the input size increases. Logarithmic
growth is slower than linear growth but faster than sublinear growth.

Example: (Posteriori Analysis)

Which of the two algorithms is more efficient?


- Compare the execution time:
For n = 10, Algorithm 1 takes 1 second, while Algorithm 2 takes 3 seconds. Thus, Algorithm 1 is faster.

For n = 100, Algorithm 1 takes 10 seconds, while Algorithm 2 takes 15 seconds. Again, Algorithm 1 is
faster.

Answer: Algorithm 1

- Algorithm 1 has a linear relationship between input size and execution time, suggesting O(n) time
complexity.
- Algorithm 2 does not have a linear relationship, indicating potentially better time complexity, such as
sublinear or logarithmic.
- Based on the given execution times, Algorithm 2 appears more efficient, with lower times for the same
input sizes.

Example: (Priori Analysis)

Let A[i] be the ith number on the list (a1,a2,…,an)

Time taken by an algorithm grows with the input size.

- Input size: number of items in the input


- Running time: number of steps executed

Our concern: Rate of growth or order of growth.

Example (Rate of growth)


If an algorithm takes 1 second to run with problem size 8, what is the time requirement (approximately) for that
algorithm with problem size 16?

SEARCHING AND SORTING ARRAYS

Arrays
- Simple way to store similar data in a list
- The data is placed one after another in the array
- You can find and access each item in the array by using a number called an index or subscript

Example (Searching Arrays)

Problem: Identify the index of the array containing one specific number.

Solution:

1. Start from the beginning of the array and look at each element, one by one.
2. At each element, check if it matches the value you are searching for.
a. If it matches = you have found the value and can stop the search
b. If it does not match = continue to the next element
3. Keep repeating steps 1 and 2 until you reach the end of the array.
4. If you reach the end of the array without finding a match, then the value is not present in the array.
5. In the worst-case scenario, the value you are searching for is located at the very end of the array, so you
must go through every element in the array.

The searching algorithm is known as linear search because it checks each element in a linear manner, one
after another, until the desired value is found, or the end of the array is reached.

LINEAR SEARCH

You might also like