Tutorial 6
#include <stdio.h>
int main() {
// Declare an array of five elements
int arr[5] = {10, 20, 30, 40, 50};
int sum = 0; // Variable to store the sum
// Calculate the sum of all array elements
for (int i = 0; i < 5; i++) {
sum += arr[i];
}
// Display the sum
printf("Sum of all array elements: %d\n", sum);
return 0;
}
Tutorial no.9
1)
Big O Notation (O-notation): - Indicates the worst-case complexity of an algorithm.
- This represents the maximum amount of resources consumed.
- O(n^2) represents quadratic temporal complexity.
The Omega Notation (Ω-notation) describes an algorithm's best-case complexity.
- Indicates the lower limit on resources used.
Ω(n) represents linear temporal complexity.
Theta Notation (Θ-notation): - Describes upper and lower boundaries, providing a
precise approximation.
- Represents the exact rate at which resources grow.
Example: Θ(n) represents linear temporal complexity.
2)
English-like Pseudocode:
● Describes algorithmic steps using plain language.
● Example: "Repeat until the list is sorted: Compare adjacent elements. If they're
in the wrong order, swap them."
Flowchart:
● Uses symbols like rectangles and diamonds to represent steps and decisions.
● Example: Rectangles show actions, diamonds represent decisions, and
arrows indicate the flow of steps.
Structured English:
● A bit like simplified C code using words.
● Example: "If temperature is over 30 degrees Celsius, say 'It's hot.' Otherwise,
say 'It's cool.'"
Nassi-Shneiderman Diagrams:
● Similar to flowcharts but with specific symbols.
● Example: Boxes for actions, diamonds for decisions, and arrows to show
order.