├── .gitignore ├── LICENSE ├── README.md ├── presentations └── templates │ ├── backgrounds │ ├── base_page_16x9.png │ ├── base_page_4x3.png │ ├── title_page_16x9.png │ └── title_page_4x3.png │ ├── logo │ └── logo.png │ ├── template_16x9.odp │ ├── template_16x9.pdf │ ├── template_4x3.odp │ └── template_4x3.pdf ├── static ├── authors │ ├── daniil_devyatkin.png │ └── mikhail_masyagin.png └── logo │ └── logo.png ├── templates ├── README.md ├── backgrounds │ ├── base_page_1_16x9.png │ ├── base_page_1_4x3.png │ ├── base_page_2_16x9.png │ └── base_page_2_4x3.png ├── logo │ └── logo.png ├── template_16x9.odp ├── template_16x9.pdf ├── template_4x3.odp └── template_4x3.pdf ├── week-01 ├── README.md ├── presentation_1_16x9.odp ├── presentation_1_4x3.odp ├── presentation_1_4x3.pdf ├── presentation_2_16x9.odp ├── presentation_2_4x3.odp └── presentation_2_4x3.pdf ├── week-02 ├── README.md ├── presentation_1_16x9.odp ├── presentation_1_4x3.odp ├── presentation_1_4x3.pdf ├── presentation_2_16x9.odp ├── presentation_2_4x3.odp └── presentation_2_4x3.pdf ├── week-03 ├── README.md ├── presentation_week3_4x3.odp └── presentation_week3_4x3.pdf ├── week-05 ├── README.md ├── presentation_week3_4x3.odp ├── presentation_week3_4x3.pdf ├── week5.odp └── week5.pdf └── week-06 ├── presentation_1_16x9.odp ├── presentation_1_4x3.odp ├── presentation_1_4x3.pdf ├── presentation_2_16x9.odp ├── presentation_2_4x3.odp └── presentation_2_4x3.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 BMSTU Department of Fundamental Sciences (FS12) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 01-sem-py-algo 2 | 3 | 4 | 5 | 1 Semester Python and Algorithms and Data Structures Course 6 | 7 | ## Goals 8 | 9 | The main goal of this course is to show first-year FS12 students how to write clean, easy-to-read and easy-to-support code with complete understanding of its algorithmic complexity. During this course students will learn following topics: 10 | 11 | - basics of Python; 12 | - concepts of asymptotic complexity, algorithms and data structures; 13 | - numerous algorithmic areas: sorting algorithms, hashes & hash-maps, trees; 14 | - basics of Object-Oriented Programming (OOP); 15 | - SQL essentials; 16 | - basics of asynchronous and parallel programming; 17 | - usage of GIT & Github; 18 | - small future career tips. 19 | 20 | ## Requirements 21 | 22 | To complete course students have to **pass 3 tests** and do some **coding hometasks**. 23 | 24 | It is highly recommended to have **your own computer** (laptop is better) to complete this course, because you will have to write some code as a homework. 25 | It is worth to use **Unix-like Operating System** (Linux, BSD, MacOS) during this course, because some actions are much easier with it. Window Subsystem for Linux is Okay, but we do not really recommend it. 26 | 27 | **Teamwork is appreciated** during this course, but **not cheating**. 28 | 29 | ## Plan 30 | 31 | Course consists of 34 standard classes (one class - 1.5 hour): 2 classes per week. Most time you will have 2 consecutive classes in one day each week. 32 | 33 | Each week includes two video lectures in russian language and two presentations, worth-to-read links and homework tasks. 34 | 35 | #### Week 01. Python Basics I. 36 | Class 1: 37 | - course description & plan; 38 | - lecturers presentation; 39 | - Python installation and "Hello-World" program; 40 | - Github & README format; 41 | - Linkedin. 42 | 43 | Class 2: 44 | - variables; 45 | - if-elif-else; 46 | - for & while; 47 | - functions; 48 | - recursion. 49 | 50 | #### Week 02. Python Basics II. 51 | Class 1: 52 | - lists & tuples; 53 | - dicts & sets; 54 | - container's iterators; 55 | - type-hints. 56 | 57 | Class 2: 58 | - lambda, map & filter; 59 | - modules, packages & main; 60 | - I/O & files; 61 | 62 | #### Week 03. Object-Oriented Programming. 63 | 64 | Class 1: 65 | - objects and their fields and methods; 66 | - private fields; 67 | - inheritance; 68 | - polymorphism. 69 | 70 | Class 2: 71 | - small OOP examples. 72 | 73 | #### Week 04. Test and Homework check. 74 | 75 | #### Week 05. Asymptotic Complexity. 76 | 77 | Class 1: 78 | - asymptotic complexity & O-notation; 79 | - complexity of loops, inner loops and recursion; 80 | - linear & binary search; 81 | - heap. 82 | 83 | Class 2: 84 | - bubble sort and insertion sort; 85 | - standard Python sorting methods. 86 | 87 | #### Week 06. Sorting Algorithms. 88 | 89 | Class 1: 90 | - best asymptotic complexity for sort with comparator; 91 | - quick-sort; 92 | - heap-sort; 93 | - merge-sort. 94 | 95 | Class 2: 96 | - K-th statistic; 97 | - BPFRT-algorithm; 98 | - sorting algorithms with linear time complexity. 99 | 100 | #### Week 07. String Algorithms. 101 | 102 | Class 1: 103 | - strings in Python & other programming languages; 104 | - mutable & immutable strings; 105 | - naive substring search. 106 | 107 | Class 2: 108 | - Knut-Morris-Pratt algorithm; 109 | - Boyer-Murr algorithm. 110 | 111 | #### Week 08. List, Stack & Queue. 112 | 113 | Class 1: 114 | - single-linked list; 115 | - double-linked list; 116 | - skip-list; 117 | - list sorting. 118 | 119 | Class 2: 120 | - stack; 121 | - queue; 122 | - priority queue. 123 | 124 | #### Week 09. Test and Homework check. 125 | 126 | #### Week 10. Binary Trees and AVL Trees. 127 | 128 | Class 1: 129 | - what is tree in programming? 130 | - binary trees. 131 | 132 | Class 2: 133 | - AVL trees. 134 | 135 | #### Week 11. Trees in Databases. 136 | 137 | Class 1: 138 | - B-tree. 139 | 140 | Class 2: 141 | - B+tree; 142 | - LSM-tree. 143 | 144 | #### Week 12. Hash-Functions & Hash-Maps. 145 | 146 | Class 1: 147 | - Python dict & set implementation; 148 | - examples of hash-functions; 149 | 150 | Class 2: 151 | - naive hash-map; 152 | - opened-key hash-map; 153 | - closed-key hash-map. 154 | 155 | #### Week 13. Join algorithms & SQL Basics I. 156 | 157 | Class 1: 158 | - tables, rows and collumns; 159 | - primary keys, foreign keys and indexes; 160 | - join algorithms. 161 | 162 | Class 2: 163 | - nested-loop join; 164 | - hash join; 165 | - merge join; 166 | - filtering; 167 | 168 | #### Week 14. SQL Basics II. 169 | 170 | Class 1: 171 | - CRUD queries. 172 | 173 | Class 2: 174 | - sub-queries and CTEs. 175 | 176 | #### Week 15. Test and Homework check. 177 | 178 | #### Week 16. Bonus: Parallel and Asynchronous programming. 179 | 180 | Class 1: 181 | - parallel counters; 182 | - parallel merge sort; 183 | - mutexes & atomic variables. 184 | 185 | Class 2: 186 | - parallel programming examples. 187 | 188 | #### Week 17. Bonus: Network Programming and IO-bound vs CPU-bound tasks. 189 | 190 | Class 1: 191 | - TCP & UDP, HTTP; 192 | - sending many-many requests in one second. 193 | 194 | Class 2: 195 | - asynchronous programming essentials; 196 | - IO-bound vs CPU-bound tasks. 197 | 198 | ## Authors 199 | 200 | #### Lecturer 201 | [**Mikhail Masyagin**](https://github.com/masyagin1998) 202 | 203 | 204 | 205 | - Senior Software Engineer at [Anecdote](https://anecdoteai.com); 206 | - Software Engineer at [STC Atlas](https://stcnet.ru); 207 | - Assistant Lecturer at [BMSTU](https://bmstu.ru). 208 | 209 | #### Teacher 210 | [**Daniil Devyatkin**](https://github.com/d3vyatk4ru) 211 | 212 | 213 | 214 | - Data Scientist at [VK](https://vk.company/ru); 215 | - Assistant Lecturer at [BMSTU](https://bmstu.ru). 216 | 217 | ## Presentation colors & fonts 218 | 219 | - First Slide Title: font `Lato 50pt`, color `0xffffff`; 220 | - First Slide Authors: font `Lato 25pt`, color `0x000000`; 221 | - Basic Title: font `Lato 40pt`, color `0xffffff`; 222 | - Basic Text: font `Lato 30pt`, color `0xffffff`; 223 | - Basic Code: font `Courier 30pt`, color `0x00c462`; 224 | - Code Functions: font `Courier 30pt`, color `0xc9211e`; 225 | - Code Variables: font `Courier 30pt`, color `0xea7500`; 226 | - Code Keywords: font `Courier 30pt`, color `0xffff00`; 227 | 228 | ## Thanks to 229 | Many thanks to **Vladimir Goryainov** for being my scientific advisor and for **Vladimir Pankratov** and **Elena Tverskaya** - people without who this course would be impossible. 230 | -------------------------------------------------------------------------------- /presentations/templates/backgrounds/base_page_16x9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/presentations/templates/backgrounds/base_page_16x9.png -------------------------------------------------------------------------------- /presentations/templates/backgrounds/base_page_4x3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/presentations/templates/backgrounds/base_page_4x3.png -------------------------------------------------------------------------------- /presentations/templates/backgrounds/title_page_16x9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/presentations/templates/backgrounds/title_page_16x9.png -------------------------------------------------------------------------------- /presentations/templates/backgrounds/title_page_4x3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/presentations/templates/backgrounds/title_page_4x3.png -------------------------------------------------------------------------------- /presentations/templates/logo/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/presentations/templates/logo/logo.png -------------------------------------------------------------------------------- /presentations/templates/template_16x9.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/presentations/templates/template_16x9.odp -------------------------------------------------------------------------------- /presentations/templates/template_16x9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/presentations/templates/template_16x9.pdf -------------------------------------------------------------------------------- /presentations/templates/template_4x3.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/presentations/templates/template_4x3.odp -------------------------------------------------------------------------------- /presentations/templates/template_4x3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/presentations/templates/template_4x3.pdf -------------------------------------------------------------------------------- /static/authors/daniil_devyatkin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/static/authors/daniil_devyatkin.png -------------------------------------------------------------------------------- /static/authors/mikhail_masyagin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/static/authors/mikhail_masyagin.png -------------------------------------------------------------------------------- /static/logo/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/static/logo/logo.png -------------------------------------------------------------------------------- /templates/README.md: -------------------------------------------------------------------------------- 1 | # Templates. 2 | 3 | ### Backgrounds 4 | 5 | - [Background 1 4x3](backgrounds/base_page_1_4x3.png); 6 | - [Background 2 4x3](backgrounds/base_page_2_4x3.png); 7 | - [Background 1 16x9](backgrounds/base_page_1_16x9.png); 8 | - [Background 2 16x9](backgrounds/base_page_2_16x9.png). 9 | 10 | ### Logo 11 | 12 | - [Logo](logo/logo.png); 13 | 14 | ### Templates 15 | 16 | - [Template 4x3](template_4x3.odp); 17 | - [Template 16x9](template_16x9.odp). 18 | -------------------------------------------------------------------------------- /templates/backgrounds/base_page_1_16x9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/templates/backgrounds/base_page_1_16x9.png -------------------------------------------------------------------------------- /templates/backgrounds/base_page_1_4x3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/templates/backgrounds/base_page_1_4x3.png -------------------------------------------------------------------------------- /templates/backgrounds/base_page_2_16x9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/templates/backgrounds/base_page_2_16x9.png -------------------------------------------------------------------------------- /templates/backgrounds/base_page_2_4x3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/templates/backgrounds/base_page_2_4x3.png -------------------------------------------------------------------------------- /templates/logo/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/templates/logo/logo.png -------------------------------------------------------------------------------- /templates/template_16x9.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/templates/template_16x9.odp -------------------------------------------------------------------------------- /templates/template_16x9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/templates/template_16x9.pdf -------------------------------------------------------------------------------- /templates/template_4x3.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/templates/template_4x3.odp -------------------------------------------------------------------------------- /templates/template_4x3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/templates/template_4x3.pdf -------------------------------------------------------------------------------- /week-01/README.md: -------------------------------------------------------------------------------- 1 | # Week 01. Python Basics I. 2 | 3 | ### Presentations 4 | 5 | - [Class 1 Presentation](presentation_1_4x3.pdf); 6 | - [Class 2 Presentation](presentation_2_4x3.pdf). 7 | 8 | ### Good to Read 9 | 10 | - Class 1: 11 | - [Python](https://www.python.org/); 12 | - [Python Docs](https://docs.python.org/3/index.html); 13 | - [Git Book](https://git-scm.com/book/en/v2); 14 | - [Linkedin Habr I](https://habr.com/ru/articles/653691/); 15 | - [Linkedin Habr II](https://habr.com/ru/articles/674236/). 16 | 17 | - Class 2: 18 | - [Process Memory Organization](https://habr.com/ru/companies/smart_soft/articles/185226/); 19 | - [Difference between Compiler and Interpreter](https://www.interviewbit.com/blog/difference-between-compiler-and-interpreter/); 20 | - [Introduction to Compilers, Interpreters and JIT](https://habr.com/ru/companies/vk/articles/304748/); 21 | - [CPython Mechanism](https://habr.com/ru/companies/yandex/articles/511972/); 22 | - [Data Types in Python](https://skillbox.ru/media/code/tipy-dannykh-v-python-dlya-nachinayushchikh-kakie-byvayut-i-kak-s-nimi-rabotat/?ysclid=lmdndlmi48434433889). 23 | 24 | ### Coding Homework 25 | 26 | ## 1.1 Polynomial (polynom) 27 | Write a program that calculates the value of a polynomial: $$P_n (x) = a_n x^n + a_{n- 1} x^{n -1} + \ldots + a_1 x + a_0$$ 28 | and its derivative at a given point $x_0$. The coefficients of the polynomial and the value of $x_0$ are integers ranging from $-2^{63}$ to $2^{63} - 1$. 29 | The program must read from the standard input the degree of the polynomial **n**, the value of $x_0$ and the coefficients of the polynomial $a_n, ..., a_0$. 30 | You need to print the values of $P_n (x_0), P_n'(x_0)$ to standard output. 31 | To calculate the value of a polynomial, you need to use Horner's scheme: 32 | $$P_n (x) = (...((a_n x + a_{n-1}) x + a_{n-2})x + \ldots + a_1)x +a_0.$$ 33 | 34 | To calculate the value of the derivative of a polynomial, it is necessary to modify Horner's scheme in an obvious way. 35 | 36 | ## 1.2 Product of numbers modulo (mulmod) 37 | Compose a program that evaluates the expression $\left(a\cdot b\right)\textrm{ mod }m$, that is, the remainder of dividing the product of the numbers $a$ and $b$ by $m$. 38 | The program must read the numbers $a$, $b$ and $m$ from the standard input stream, and output the result to the standard output stream. 39 | 40 | Program multiplication to modulo division calculations using a Horner's scheme. Let's represent the number in the binary number system: 41 | $$b=\overline{b_{63}b_{62}\ldots b_{1}b_{0}}.$$ 42 | Here $b_{63},:b_{62},:\ldots:,:b_{1},:b_{0}$ are the binary digits that form the number, that is 43 | $$b=b_{63}\cdot2^{63}+b_{62}\cdot2^{62}+\ldots+b_{1}\cdot2+b_{0}.$$ 44 | Then 45 | $$\left(a\cdot b\right)\textrm{ mod }m=\left[a\cdot b_{63}\cdot2^{63}+a\cdot b_{62}\cdot2^{62}+\ldots+a\cdot b_{1}\cdot2+a\cdot b_{0}\right]\textrm{ mod }m.$$ 46 | Transforming this expression according to Horner’s scheme, we obtain 47 | $$\left(a\cdot b\right)\textrm{ mod }m=\left[\left(\ldots\left(a\cdot b_{63}\cdot2+a\cdot b_{62}\right)\cdot2+\ldots+a\cdot b_{1}\right)\cdot2+a\cdot b_{0}\right]\textrm{ mod }m.$$ 48 | Considering that for any $x$, $y$ and $m$ the identities are valid 49 | $$\left(x+y\right)\textrm{ mod }m\equiv\left(\left(x\textrm{ mod }m\right)+\left(y\textrm{ mod }m\right)\right)\textrm{ mod }m,$$ 50 | When calculating the right side of our formula, we have the right to do the following: if there is a possibility that the sum of two terms will exceed $2^{64}$, we need to add the remainders from dividing these terms by $m$; similarly for the work. This technique guarantees that an overflow will never occur during the calculation. 51 | 52 | ## 1.3 Fibonacci number system (fibsys) 53 | Fibonacci numbers are a sequence of natural numbers $f_i$, in which 54 | 55 | ```math 56 | \begin{cases}f_{0}=f_{1}=1,\\f_{i}=f_{i-2}+f_{i-1}, & \forall i>1.\end{cases} 57 | ``` 58 | According to Zeckendorff's theorem, any positive integer can be uniquely represented as a sum of different Fibonacci numbers that does not include two consecutive Fibonacci numbers. 59 | To factor a positive integer $x$ into a Zeckendorff sum, you need to do the following as long as $x > 0$: 60 | - find the maximum Fibonacci number $f < x$; 61 | - add $f$ to the Zeckendorff sum; 62 | - subtract $f$ from $x$. 63 | 64 | Recall that in a positional number system, the weight of each digit depends on its position in the number notation. Accordingly, the basis of a positional number system is a sequence of numbers that define the weight of each digit. For example, for the decimal system the base is the sequence 1, 10, 100, 1000, 10000, 100000, etc. 65 | 66 | **The Fibonacci number system** is a positional number system with two digits - 0 and 1, the basis of which is the Fibonacci numbers, starting with $f_i$: 1, 2, 3, 5, 8, 13, 21, 34, etc. 67 | In order to guarantee the uniqueness of a number in the Fibonacci number system, the number must not contain two consecutive ones (Zeckendorff's theorem). 68 | 69 | Write a program *fibsys* that converts the integer $0\leq x<2^{63}$ to the Fibonacci number system. The program must read the number $x$ from the standard input stream and output to the standard output stream a sequence of zeros and ones that forms the Fibonacci notation of the number $x$. 70 | 71 | ## 1.4 Intersection of sets (intersect) 72 | Let $\mathbb{N}_{32}$ be the set of natural numbers from 0 to 31. Given two sets $A \subseteq \mathbb{N}\_{32}$ and $B\subseteq\mathbb{N}\_{32}$. Write a program intersect.c that calculates the intersection of the sets $A$ and $B$. The program must output to standard output the elements of set $A\cap B$, sorted in ascending order. It is prohibited to use arrays to store sets: each set must be represented by a 32-bit integer such that if its $i$-th bit is 1, then the number $i$ belongs to the set. 73 | 74 | ## 1.5 Factorial's zeros 75 | Write a function, named `factorial`, that calculates the value of given number's factorial: $n! = 1 \cdot 2 \cdot 3 \cdot ... \cdot (n - 1) \cdot n$. Write a function, named `factorial_zeros`, that calculates how many zeros are in the end of `factorial(n)` without its direct calculation. 76 | 77 | ## 1.6 Josephus Flavius task 78 | In 67 AD during the Jewish-Roman War, Josephus Flavius and forty rebels were trapped in a cave. Preferring being suicided to captivity, they decided to stand in a circle and kill every third of the survivors. Josephus wanted to stay alive and realized where he had to stand in the circle to stay alive in the series of executions. So he lived to tell the tale. 79 | 80 | Let's assume that there are $N$ rebels, numerated from $0$ to $N-1$, and they start to kill themselves starting from $0$ and then killing each $K$'th of them. Write a program, which helps Josephus to survive depending on given $N$ and $K$. 81 | -------------------------------------------------------------------------------- /week-01/presentation_1_16x9.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-01/presentation_1_16x9.odp -------------------------------------------------------------------------------- /week-01/presentation_1_4x3.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-01/presentation_1_4x3.odp -------------------------------------------------------------------------------- /week-01/presentation_1_4x3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-01/presentation_1_4x3.pdf -------------------------------------------------------------------------------- /week-01/presentation_2_16x9.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-01/presentation_2_16x9.odp -------------------------------------------------------------------------------- /week-01/presentation_2_4x3.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-01/presentation_2_4x3.odp -------------------------------------------------------------------------------- /week-01/presentation_2_4x3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-01/presentation_2_4x3.pdf -------------------------------------------------------------------------------- /week-02/README.md: -------------------------------------------------------------------------------- 1 | # Week 02. Python Basics II. 2 | 3 | ### Presentations 4 | 5 | - [Class 1 Presentation](presentation_1_4x3.pdf); 6 | - [Class 2 Presentation](presentation_2_4x3.pdf). 7 | 8 | ### Good to Read 9 | 10 | - Class 1: 11 | - [Collections](https://fadeevlecturer.github.io/python_lectures/notebooks/python/collections.html); 12 | - [Sequences](https://fadeevlecturer.github.io/python_lectures/notebooks/python/sequences.html); 13 | - [List Internals](https://habr.com/ru/articles/273045/) 14 | - [Tuple vs List](https://www.geeksforgeeks.org/python-difference-between-list-and-tuple/); 15 | - [Dict](https://medium.com/@artturi-jalli/python-dictionary-a-complete-guide-538292873053); 16 | - [Dict Internals](https://habr.com/ru/articles/432996/); 17 | - [Iterators](https://habr.com/ru/articles/488112/); 18 | - [Garbage Collector I](https://habr.com/ru/articles/417215/); 19 | - [Garbage Collector II](https://fadeevlecturer.github.io/python_lectures/notebooks/python/garbage_collector.html); 20 | - [Type hints](https://habr.com/ru/companies/lamoda/articles/432656/). 21 | - Class 2: 22 | - [Functional programming](https://habr.com/ru/articles/555378/); 23 | - [Modules & Packages](https://habr.com/ru/articles/718828/); 24 | - [Requirements](https://semakin.dev/2020/04/requirements_txt/?ysclid=lmsfzwiheg711857653); 25 | - [Files & I/O I](https://eldoyle.github.io/PythonIntro/08-ReadingandWritingTextFiles/); 26 | - [Files & I/O II](https://habr.com/ru/companies/selectel/articles/547290/); 27 | - [Files & I/O III](https://fadeevlecturer.github.io/python_lectures/notebooks/python/filesystem.html); 28 | - [Files & I/O IV](https://fadeevlecturer.github.io/python_lectures/notebooks/python/files.html). 29 | 30 | ### Coding Homework 31 | 32 | ## 2.1 Maximum sum of consecutive array elements (maxk). 33 | Given an integer array whose size does not exceed 10000 and a number **k**, which is less than or equal to the length of the array. 34 | Write a *maxk* program that determines which consecutive elements of an array have the maximum sum. 35 | The program must read the size of the array, its elements, and the number **k** from the standard input stream, and then print the maximum sum **k** of consecutive array elements to the standard output stream. 36 | The program is prohibited from accessing the same array element more than twice, as well as declaring any auxiliary arrays. 37 | 38 | ## 2.2 Greatest prime divisor (primediv). 39 | Write a program *primediv* that calculates the greatest prime divisor of a number **x**. 40 | The number **x** is entered from the standard input stream, and it is known that $-2^{31} <= x < 2^{31}$. 41 | The program must use the sieve of Eratosthenes to construct an array of prime numbers. 42 | 43 | ## 2.3 Saddle point in a matrix (saddlepoint). 44 | 45 | **Definition.** An element of a two-dimensional array is called a **saddle element** if it is both the largest in its row and the smallest in its column. 46 | 47 | An integer two-dimensional array is given, the size of which does not exceed $10 \times 10$. It is known that all elements of the array are different. Write a program saddlepoint.c that determines the saddle point in this map. 48 | 49 | The program must read from the standard input the number of rows and columns of a two-dimensional array and its elements. The program should output to the standard stream the coordinates of the found saddle point or the word “none” if the saddle point does not exist. 50 | 51 | The program is prohibited from accessing the same array element twice. 52 | 53 | ## 2.4 Array Reversal Function (revarray). 54 | 55 | TODO 56 | -------------------------------------------------------------------------------- /week-02/presentation_1_16x9.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-02/presentation_1_16x9.odp -------------------------------------------------------------------------------- /week-02/presentation_1_4x3.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-02/presentation_1_4x3.odp -------------------------------------------------------------------------------- /week-02/presentation_1_4x3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-02/presentation_1_4x3.pdf -------------------------------------------------------------------------------- /week-02/presentation_2_16x9.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-02/presentation_2_16x9.odp -------------------------------------------------------------------------------- /week-02/presentation_2_4x3.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-02/presentation_2_4x3.odp -------------------------------------------------------------------------------- /week-02/presentation_2_4x3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-02/presentation_2_4x3.pdf -------------------------------------------------------------------------------- /week-03/README.md: -------------------------------------------------------------------------------- 1 | # Week 03. Object-Oriented Programming. 2 | 3 | ### Presentation 4 | 5 | - [Class 1 Presentation](presentation_week3_4x3). 6 | 7 | ### Good to Read 8 | 9 | - Class 1: 10 | - [Decorators](https://www.geeksforgeeks.org/decorators-in-python/); 11 | - [@property](https://habr.com/ru/companies/otus/articles/557804/); 12 | - [Abstract Base Classes](https://docs.python.org/3/library/abc.html); 13 | - [OOP in Python](https://eldoyle.github.io/PythonIntro/08-ReadingandWritingTextFiles/); 14 | - [Pure Python. The subtleties of programming for the pros](https://kniga.lv/en/shop/chistyj-python-tonkosti-programmirovanija-dlja-profi/); 15 | - [S.O.L.I.D. I](https://habr.com/ru/companies/productivity_inside/articles/505430/); 16 | - [S.O.L.I.D. II](https://habr.com/ru/articles/698786/). 17 | 18 | ### Coding Homework 19 | 20 | TODO -------------------------------------------------------------------------------- /week-03/presentation_week3_4x3.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-03/presentation_week3_4x3.odp -------------------------------------------------------------------------------- /week-03/presentation_week3_4x3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-03/presentation_week3_4x3.pdf -------------------------------------------------------------------------------- /week-05/README.md: -------------------------------------------------------------------------------- 1 | # Week 05. Asymptotic Complexity. 2 | 3 | ### Presentations 4 | 5 | - [Class 1 & 2 Presentation](week5.pdf). 6 | 7 | ### Good to Read 8 | 9 | - [Asymptotic Complexity](https://www.youtube.com/watch?v=cXCuXNwzdfY&t=303s&ab_channel=AlekOS); 10 | - [Python Docs](https://docs.python.org/3/index.html); 11 | - [Binary Search (for int)](https://neerc.ifmo.ru/wiki/index.php?title=%D0%A6%D0%B5%D0%BB%D0%BE%D1%87%D0%B8%D1%81%D0%BB%D0%B5%D0%BD%D0%BD%D1%8B%D0%B9_%D0%B4%D0%B2%D0%BE%D0%B8%D1%87%D0%BD%D1%8B%D0%B9_%D0%BF%D0%BE%D0%B8%D1%81%D0%BA); 12 | - [Heap](https://habr.com/ru/articles/263765/). 13 | - [Bubble Sort](https://habr.com/ru/articles/204600/) 14 | - [Insertion Sort](https://habr.com/ru/articles/181271/) 15 | 16 | ### Coding Homework 17 | 18 | ## 5.1. Binary search. 19 | Let a sorted array of **n** elements be given, where 0 < **n** <= 10^, target value **k** and type of sorting: -1 - descending, 1 - ascending; 20 | Write a function that find for the value of **k** in an array and returns the index of the first occurrence of value, if the value of **k** is not found, return -1. 21 | 22 | ## 5.2. Shortest superstring (superstr). 23 | Let a set of **n** strings be given, where 0 < **n** <= 10. 24 | It is known that none of these strings is a substring of another string. 25 | Write a program function that calculates the length of the shortest string containing all these strings as substrings. 26 | The program must read the number **n** and then **n** strings from the standard input stream. 27 | The length of the shortest line containing all lines read should be printed to standard output. 28 | 29 | ## 5.3. Sums forming powers of two (power2). 30 | Let a sequence of **n** non-repeating integers be given, where 0 < **n** <= 24, and each integer is in the range from $10^{-6}$ to $10^{-6}$. 31 | Write a program function that calculates how many non-empty combinations of numbers from a sequence exist such that the sum of the numbers in the combination is equal to the power of the number **n**. 32 | The program must read from the standard input the number **n**, and then **n** the numbers that form the sequence. The program should print the number of combinations to standard output. 33 | 34 | ## 5.4. Bidirectional bubble sort function (bubblesort). [click](https://en.wikipedia.org/wiki/Cocktail_shaker_sort) 35 | In classical bubble sort, the sequence being sorted is always passed in one direction. 36 | Modify the bubble sort algorithm so that it alternates passes through the sequence from left to right and from right to left. 37 | Write a bubblesort function that performs a bidirectional bubble sort of an arbitrary sequence. The function must be declared as 38 | ```Python 39 | def bubblesort( 40 | nel: int, 41 | compare: Callable[[int, int], int], 42 | swap: Callable[[int, int], None], 43 | ) -> None: 44 | pass 45 | ``` 46 | where, 47 | - nel is number of elements in the sequence; 48 | - compare is a comparison function that returns -1 if the first argument is less than the second, 0 if the elements are equal, 1 otherwise; 49 | - swap — pointer to the function for exchanging i-th and j-th elements of the sequence. 50 | -------------------------------------------------------------------------------- /week-05/presentation_week3_4x3.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-05/presentation_week3_4x3.odp -------------------------------------------------------------------------------- /week-05/presentation_week3_4x3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-05/presentation_week3_4x3.pdf -------------------------------------------------------------------------------- /week-05/week5.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-05/week5.odp -------------------------------------------------------------------------------- /week-05/week5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-05/week5.pdf -------------------------------------------------------------------------------- /week-06/presentation_1_16x9.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-06/presentation_1_16x9.odp -------------------------------------------------------------------------------- /week-06/presentation_1_4x3.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-06/presentation_1_4x3.odp -------------------------------------------------------------------------------- /week-06/presentation_1_4x3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-06/presentation_1_4x3.pdf -------------------------------------------------------------------------------- /week-06/presentation_2_16x9.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-06/presentation_2_16x9.odp -------------------------------------------------------------------------------- /week-06/presentation_2_4x3.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-06/presentation_2_4x3.odp -------------------------------------------------------------------------------- /week-06/presentation_2_4x3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmstu-fs12/01-sem-py-algo/9a82cf6a6f87b3539ae70f88cabf5d0d400b4f14/week-06/presentation_2_4x3.pdf --------------------------------------------------------------------------------