Advanced Course: “Algorithms and Optimization in C++”

hand

This course is designed for experienced programmers who want to deepen their knowledge of complex algorithms and optimization techniques in C++. You will learn how to efficiently implement sorting and search algorithms, analyze their complexity, as well as how to work with memory and use multitasking to speed up computation. We’ll also look at ways to optimize code to improve performance in real-world projects.

Course Topics:

Sorting and Search Algorithms

  • Sorting: Learn basic sorting algorithms: bubble sort, insertion sort, quick sort, merge sort.
  • Search: Search algorithms: linear search, binary search, graph search (depth and width search).

Example of sorting by merge:

void merge(vector<int>& arr, int left, int mid, int right) {
    int n1 = mid - left + 1;
    int n2 = right - mid;

    vector<int> leftArr(n1), rightArr(n2);

    for (int i = 0; i < n1; i++)
        leftArr[i] = arr[left + i];
    for (int i = 0; i < n2; i++)
        rightArr[i] = arr[mid + 1 + i];

    int i = 0, j = 0, k = left;
    while (i < n1 && j < n2) {
        if (leftArr[i] <= rightArr[j])
            arr[k++] = leftArr[i++];
        else
            arr[k++] = rightArr[j++];
    }

    while (i < n1) arr[k++] = leftArr[i++];
    while (j < n2) arr[k++] = rightArr[j++];
}

Analyzing the complexity of algorithms

  • Complexity Theory: Fundamentals of analyzing the complexity of algorithms (O-notation, worst case, best case, and average case).
  • How to analyze the execution time of algorithms and use this information to select the most efficient methods.

Example of complexity analysis:

  • Bubble sort – O(n^2)
  • Fast sorting – O(n log n) in the average case.

Memory management

  • Dynamic memory allocation: Using new, delete, and standard containers such as vector and map.
  • Memory leaks: How to avoid memory leaks and manage dynamic resources.
  • Smart pointers: Using shared_ptr, unique_ptr for memory management and automatic resource release.

Example of using smart pointers:

#include <memory>
class Example {
Public:
    void show() { cout << “Hello, world!” << endl; }
};

int main() {
    unique_ptr<Example> ptr = make_unique<Example>();
    ptr->show();
    return 0; // The smart pointer will automatically free memory
}

Multitasking and Parallel Computing

  • Multitasking: Basics of working with threads, using library.
  • Parallel computing: Using multithreading to speed up calculations, working with asynchronous tasks, error handling in multitasking mode.
  • Parallel Algorithms: Using algorithms to speed up processing of big data.

Multitasking example:

    #include <iostream>
    #include <thread>

    void printHello() {
        std::cout << “Hello from thread!” << std::endl;
    }

    int main() {
        std::thread t(printHello);
        t.join(); // Waiting for thread completion
        return 0;
    }

Code and performance optimization

  • Speeding up execution: Using efficient algorithms and data structures to reduce program execution time.
  • Profiling Tools: How to analyze program performance using tools such as Valgrind or the gprof profiler.
  • Memory caching and optimization: How to minimize memory accesses and use caching to improve performance.

Optimization example:

Replacing nested loops with more efficient algorithms (e.g., using hash tables to search in O(1) instead of O(n)).

What you’ll get after completing the course:

  • An understanding and application of complex sorting and searching algorithms, including algorithms for big data.
  • Skills in analyzing and optimizing the complexity of algorithms, understanding the importance of choosing the right data structures.
  • Experience in working with dynamic memory, preventing memory leaks, using smart pointers.
  • Knowledge and practical skills in multitasking and parallel computing to accelerate computation in real-world projects.
  • Know how to profile and optimize code to achieve maximum performance.

Course fee: $400