diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 0f39ed8..eab2ca7 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -18,19 +18,6 @@ jobs: echo "No batch directories modified." exit 0 fi - for batch in $modified_batches; do - if [ ! -d "$batch/LessonMaterials" ]; then - echo "Error: LessonMaterials directory missing in $batch." >&2 - exit 1 - fi - if [ ! -d "$batch/Assignments" ]; then - echo "Error: Assignments directory missing in $batch." >&2 - exit 1 - fi - if [ ! -d "$batch/Comments" ]; then - echo "Error: Comments directory missing in $batch." >&2 - exit 1 - fi done - name: Check file naming conventions diff --git a/Batch25/Assignments/assignments.txt b/Batch25/Assignments/assignments.txt new file mode 100644 index 0000000..cd1bd25 --- /dev/null +++ b/Batch25/Assignments/assignments.txt @@ -0,0 +1,17 @@ +1. Write a C# program to implement a linear search algorithm. + +Create an integer array of size 10. +Allow the user to input a number to search for in the array. +Display the index of the number if found, or a message if it is not in the array. + +2. Write a C# program to implement a binary search algorithm. + +Use a sorted array of integers [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]. +Allow the user to input a number to search for in the array. +Display the index of the number if found, or a message if it is not in the array. + +3. Write two separate C# methods, one for linear search and one for binary search. + +Use the array [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]. +Search for the number 50 in both methods. +Write a brief explanation comparing the two methods in terms of efficiency. diff --git a/Batch25/Comments/comments.txt b/Batch25/Comments/comments.txt new file mode 100644 index 0000000..9fa6fa7 --- /dev/null +++ b/Batch25/Comments/comments.txt @@ -0,0 +1 @@ +Hassan is struggling to understand the basics of algorithms, while Mubarak grasps and understands the topic well. \ No newline at end of file diff --git a/Batch25/LessonMaterials/Algorithm Basics and Time Complexit.txt b/Batch25/LessonMaterials/Algorithm Basics and Time Complexit.txt new file mode 100644 index 0000000..54315ae --- /dev/null +++ b/Batch25/LessonMaterials/Algorithm Basics and Time Complexit.txt @@ -0,0 +1,78 @@ +Algorithm Basics and Time Complexity + +Introduction to Algorithms +An algorithm is a step-by-step procedure or formula for solving a problem. It serves as a blueprint for tasks ranging from simple calculations to complex data processing. + +Characteristics of a Good Algorithm +1. Clarity: Each step is clear and unambiguous. +2. Finiteness: Must terminate after a finite number of steps. +3. Input: Takes input values (if necessary). +4. Output: Produces at least one output. +5. Efficiency: Makes optimal use of resources like time and memory. + +--- + +Time Complexity +Time complexity measures the amount of time an algorithm takes to complete as a function of the input size (‘n’). It is used to evaluate the efficiency of algorithms. + +Why is Time Complexity Important? +1. Helps compare algorithms for performance. +2. Determines the feasibility of algorithms for large inputs. + +Big-O Notation +Big-O notation describes the upper bound of an algorithm's running time. It represents the worst-case scenario. + +Common Notations: +1. O(1) – Constant Time**: Execution time is independent of input size. + - Example: Accessing an element in an array. +2. O(n) – Linear Time**: Execution time grows linearly with input size. + - Example: Searching for an element in an unsorted list. +3. O(log n) – Logarithmic Time**: Execution time grows logarithmically. Very efficient for large inputs. + - Example: Binary search on a sorted array. +4. O(n²) – Quadratic Time**: Execution time grows quadratically. Common in nested loops. + - Example: Comparing all pairs of elements. +5. O(2ⁿ) – Exponential Time**: Execution time doubles with each additional input. Only feasible for small inputs. + - Example: Solving the Tower of Hanoi. + +--- + +Examples of Time Complexity with Actual Time +Assume a computer can perform 1 million operations per second (1 operation = 1 microsecond). + +O(1) – Constant Time +- Scenario: Fetching an element from an array. +- Observation: Time remains the same regardless of input size. + +O(n) – Linear Time +- Scenario: Searching for an element in an unsorted array. +- Observation: Time grows directly with input size. + +O(log n) – Logarithmic Time +- Scenario: Binary search in a sorted array. +- Observation: Logarithmic growth is highly efficient. + +O(n²) – Quadratic Time +- Scenario: Nested loops comparing all pairs of elements. +- Observation: Becomes impractical for large inputs. + +O(2ⁿ) – Exponential Time +- Scenario: Recursive Fibonacci calculation. +- Observation: Exponential algorithms are impractical for large inputs. + +--- + + +Comparison of Linear Search and Binary Search + +| Aspect | Linear Search | Binary Search | +|--------------------------|-------------------------|---------------------------| +| Time Complexity | O(n) | O(log n) | +| Input Requirement | Unsorted or Sorted | Sorted | +| Efficiency | Slower for large inputs | Faster for large inputs | +| Implementation Simplicity| Simple | Slightly complex | + +--- + +Conclusion +Understanding algorithm basics and time complexity is crucial for writing efficient code. Different algorithms serve different purposes, and choosing the right one depends on the problem at hand and the constraints on time and resources. +