├── .gitignore ├── 0_intro ├── lection │ ├── 0_0_plan.md │ ├── 0_1_algorithms.md │ ├── 0_2_computers.md │ ├── 0_3_programms.md │ ├── 0_4_variables.md │ ├── 0_full_lecture.md │ ├── images │ │ ├── abacus.jpg │ │ ├── ada_byron.png │ │ ├── analytical_engine_cards.jpg │ │ ├── and_truth_table.png │ │ ├── ascii_table.png │ │ ├── assembler_code_example.jpg │ │ ├── babbage.png │ │ ├── bit_byte_nibble_word.png │ │ ├── bit_shift_example.png │ │ ├── bit_shift_example_result.png │ │ ├── bitmask_simple.png │ │ ├── bitmask_simple_result.png │ │ ├── bitwise_operator_example.png │ │ ├── bitwise_operator_example_result.png │ │ ├── compiler_code_stage.png │ │ ├── compiler_run_stage.png │ │ ├── cormen_4_cover.jpg │ │ ├── cpp_how_compile.png │ │ ├── dasgupta_cover.jpg │ │ ├── diff_engine.jpg │ │ ├── different_data_interpretation.png │ │ ├── differential_engine.png │ │ ├── eniac.png │ │ ├── fp_conversions.png │ │ ├── fp_half_precision_structure.png │ │ ├── hex_digits.png │ │ ├── hex_hw.png │ │ ├── int_types_example.png │ │ ├── int_types_mem_example.png │ │ ├── interpreter_code_stage.png │ │ ├── interpreter_run_stage.png │ │ ├── literals_example.png │ │ ├── literals_example_result.png │ │ ├── memory_example.png │ │ ├── not_truth_table.png │ │ ├── old_geek.png │ │ ├── or_truth_table.png │ │ ├── pascal_calc.jpg │ │ ├── pascal_calc.xcf │ │ ├── pascal_code_example.jpg │ │ ├── processor_unit.jpg │ │ ├── programming_translation.png │ │ ├── schedule.png │ │ ├── sedgewick_cover.jpg │ │ ├── signed_16bit_example.png │ │ ├── signed_all_table.png │ │ ├── signed_int_types.png │ │ ├── signed_magn_example.png │ │ ├── simple_prog.png │ │ ├── tony_start.png │ │ ├── transistor_team.jpg │ │ ├── transistor_team.png │ │ ├── unsigned_int_types.png │ │ ├── vars_simple_programm.png │ │ ├── women_eniac.png │ │ └── xor_truth_table.png │ └── slides │ │ ├── 0_introduction.pdf │ │ ├── 0_introduction.tex │ │ ├── HSE-theme │ │ ├── 01_Logo_HSE_full_eng_CMYK.pdf │ │ ├── 01_Logo_HSE_full_rus_CMYK.pdf │ │ ├── 01_Znak_CMYK.pdf │ │ └── beamerthemeHSE.sty │ │ ├── beamerthemeHSE.sty │ │ └── images │ │ └── pascal_calc.xcf ├── practice │ ├── CMakeLists.txt │ ├── build.sh │ ├── md │ │ ├── 0.md │ │ ├── 1.md │ │ ├── 2.md │ │ ├── 3.md │ │ ├── 4.md │ │ ├── 5.md │ │ ├── 6.md │ │ ├── 7.md │ │ └── images │ │ │ ├── addresses_code.png │ │ │ ├── addresses_out.png │ │ │ ├── bitop_oneline_alt_code.png │ │ │ ├── bitop_oneline_alt_out.png │ │ │ ├── bitop_oneline_code.png │ │ │ ├── bitop_oneline_out.png │ │ │ ├── bitwise_operator_example_code.png │ │ │ ├── bitwise_operator_example_out.png │ │ │ ├── compilation_single.png │ │ │ ├── find_unique.png │ │ │ ├── int_and_float_code.png │ │ │ ├── int_and_float_out.png │ │ │ ├── literals_example_code.png │ │ │ ├── literals_example_out.png │ │ │ ├── print_bits.png │ │ │ ├── signed_unsigned_code.png │ │ │ ├── signed_unsigned_out.png │ │ │ ├── swap_variables_code.png │ │ │ └── swap_variables_out.png │ ├── practice.md │ └── src │ │ ├── addresses.c │ │ ├── bitmask_simple_example.c │ │ ├── bitmasks.c │ │ ├── bitop_oneline.c │ │ ├── bitop_oneline_alternative.c │ │ ├── bitwise_operator_example.c │ │ ├── check_overflow.c │ │ ├── check_pwr_of_two.c │ │ ├── decimal_to_octal.c │ │ ├── find_unique.c │ │ ├── int_and_float.c │ │ ├── literals_example.c │ │ ├── print_bits.c │ │ ├── signed_unsigned.c │ │ └── swap_variables.c └── src │ ├── bitmask_simple_example_output.txt │ ├── bitwise_operator_example_output.txt │ ├── bitwise_shift_example.c │ ├── bitwise_shift_example_output.txt │ └── literals_example_output.txt ├── 1_arrays_complexity_testing ├── lection │ ├── 1_0_plan.md │ ├── 1_1_arrays.md │ ├── 1_2_problems.md │ ├── 1_3_complexity.md │ ├── 1_4_testing.md │ ├── images │ │ ├── array_access.png │ │ ├── array_complexity_table2.png │ │ ├── array_dynamic.png │ │ ├── array_dynamic_example.png │ │ ├── array_example.png │ │ ├── array_insert.png │ │ ├── array_intro.png │ │ ├── array_ndim.png │ │ ├── array_ndim2.png │ │ ├── array_pros_cons.png │ │ ├── array_remove.png │ │ ├── array_rowcolumn.png │ │ ├── array_search.png │ │ ├── array_search_special.png │ │ ├── array_structure 1.png │ │ ├── array_structure.png │ │ ├── array_types.png │ │ ├── bigo_complexity_chart.png │ │ ├── bigo_example.png │ │ ├── bigo_rules.png │ │ ├── bigo_test.png │ │ ├── complexity_table.png │ │ ├── cvrp.png │ │ ├── cvrp_math.png │ │ ├── elementary_ops.png │ │ ├── small_o.png │ │ ├── testing_max.png │ │ └── testing_statement.png │ └── slides │ │ ├── 1_arrays_complexity_testing.pdf │ │ ├── 1_arrays_complexity_testing.tex │ │ ├── HSE-theme │ │ ├── 01_Logo_HSE_full_eng_CMYK.pdf │ │ ├── 01_Logo_HSE_full_rus_CMYK.pdf │ │ ├── 01_Znak_CMYK.pdf │ │ └── beamerthemeHSE.sty │ │ └── beamerthemeHSE.sty └── practice │ ├── CMakeLists.txt │ ├── build.sh │ ├── md │ ├── 0.md │ ├── 1.md │ ├── 10.md │ ├── 2.md │ ├── 3.md │ ├── 4.md │ ├── 5.md │ ├── 6.md │ ├── 7.md │ ├── 8.md │ ├── 9.md │ └── images │ │ ├── 2D_rows_cols_sum.png │ │ ├── 2D_rows_cols_sum_simple_code.png │ │ ├── addresses_arrays_code.png │ │ ├── addresses_arrays_out.png │ │ ├── delete_element_alg_code.png │ │ ├── delete_element_alg_out.png │ │ ├── delete_element_perf_out.png │ │ ├── find_element_index_alg_code.png │ │ ├── find_element_index_alg_out.png │ │ ├── find_element_index_perf_out.png │ │ ├── get_element_by_index_perf_out.png │ │ ├── insert_element_alg_code.png │ │ ├── insert_element_alg_out.png │ │ ├── insert_element_perf_out.png │ │ ├── test_input.png │ │ └── test_sums.png │ ├── practice.md │ └── src │ ├── 2D_rows_cols_sum.c │ ├── 2D_rows_cols_sum_simple.c │ ├── D_two_dim_array_sum.c │ ├── addresses_arrays.c │ ├── cols_rows_perf.c │ ├── delete_element_alg.c │ ├── delete_element_perf.c │ ├── find_element_index_alg.c │ ├── find_element_index_perf.c │ ├── get_element_by_index_perf.c │ ├── insert_delete.c │ ├── insert_delete_global.c │ ├── insert_element_alg.c │ └── insert_element_perf.c ├── 2_sorting_simple ├── lection │ ├── images │ │ ├── bubble_sort.png │ │ ├── bucket_sort.png │ │ ├── bucket_sort_2.png │ │ ├── bucket_sort_pseudo.png │ │ ├── counting_sort.png │ │ ├── insertion_sort.png │ │ ├── radix_sort.png │ │ ├── radix_sort_step1.png │ │ ├── radix_sort_step2.png │ │ ├── radix_sort_step3.png │ │ └── selection_sort.png │ └── slides │ │ ├── 2_sorting_simple.pdf │ │ ├── 2_sorting_simple.tex │ │ ├── HSE-theme │ │ ├── 01_Logo_HSE_full_eng_CMYK.pdf │ │ ├── 01_Logo_HSE_full_rus_CMYK.pdf │ │ ├── 01_Znak_CMYK.pdf │ │ └── beamerthemeHSE.sty │ │ └── beamerthemeHSE.sty └── practice │ ├── CMakeLists.txt │ ├── build.sh │ ├── md │ ├── 0.md │ ├── 1.md │ ├── 2.md │ ├── 3.md │ ├── 4.md │ ├── 5.md │ ├── 6.md │ └── images │ │ ├── bubble_sort_code.png │ │ ├── bucket_sort_code.png │ │ ├── counting_sort_code.png │ │ ├── insertion_sort_code.png │ │ ├── radix_sort_code.png │ │ ├── recursion.jpg │ │ ├── recursive_callstack_code.png │ │ ├── recursive_factorial_code.png │ │ └── selection_sort_code.png │ ├── practice.md │ └── src │ ├── bubble_sort.c │ ├── bucket_sort.c │ ├── counting_sort.c │ ├── insertion_sort.c │ ├── radix_sort.c │ ├── recursive_callstack.c │ ├── recursive_factorial.c │ └── selection_sort.c ├── 3_sorting_recursion ├── lection │ ├── images │ │ ├── bubble_sort.png │ │ ├── bucket_sort.png │ │ ├── bucket_sort_2.png │ │ ├── bucket_sort_pseudo.png │ │ ├── compare_based_proof.png │ │ ├── compare_based_tree.png │ │ ├── compare_based_tree_2.png │ │ ├── counting_sort.png │ │ ├── insertion_sort.png │ │ ├── merge_accesses.png │ │ ├── merge_already_sorted.png │ │ ├── merge_compares_1.png │ │ ├── merge_example.png │ │ ├── merge_extra_space.png │ │ ├── merge_insertion.png │ │ ├── merge_insertion_full.png │ │ ├── merge_iterative.png │ │ ├── merge_merge_1.png │ │ ├── merge_merge_2.png │ │ ├── merge_recursive_main.png │ │ ├── qs_common.png │ │ ├── qs_complexity_cases.png │ │ ├── qs_example.png │ │ ├── qs_example.tif │ │ ├── qs_hoare.png │ │ ├── qs_lomuto.png │ │ ├── qs_lomuto_pseudo.png │ │ ├── qs_main_pseudo.png │ │ ├── qs_pseudo.png │ │ ├── qselect.png │ │ ├── radix_sort.png │ │ ├── radix_sort_step1.png │ │ ├── radix_sort_step2.png │ │ ├── radix_sort_step3.png │ │ ├── selection_sort.png │ │ ├── stability_example.png │ │ ├── stability_insertion.png │ │ ├── stability_merge.png │ │ ├── stability_qs.png │ │ ├── stability_selection.png │ │ ├── summary_all.png │ │ └── summary_sedgewick.png │ └── slides │ │ ├── .3_sorting_recursion.tex.swp │ │ ├── 3_sorting_recursion.pdf │ │ ├── 3_sorting_recursion.tex │ │ ├── HSE-theme │ │ ├── 01_Logo_HSE_full_eng_CMYK.pdf │ │ ├── 01_Logo_HSE_full_rus_CMYK.pdf │ │ ├── 01_Znak_CMYK.pdf │ │ └── beamerthemeHSE.sty │ │ └── beamerthemeHSE.sty └── practice │ ├── CMakeLists.txt │ ├── build.sh │ ├── md │ ├── 0.md │ ├── 1.md │ ├── 2.md │ ├── 3.md │ ├── 4.md │ └── images │ │ ├── merge_sort_code.png │ │ ├── nth_element_code.png │ │ ├── nth_element_out.png │ │ ├── qsort_generic_code.png │ │ ├── qsort_hoar_code.png │ │ ├── qsort_lomuto_code.png │ │ ├── req_1_to_n_code.png │ │ ├── req_a_to_b_code.png │ │ ├── req_check_pwr_2_code.png │ │ ├── req_num_ones_code.png │ │ ├── req_rotate_digits_code.png │ │ ├── req_sum_digits_code.png │ │ └── timsort_code.png │ ├── practice.md │ └── src │ ├── merge_sort.c │ ├── nth_element.c │ ├── qsort_hoar.c │ ├── qsort_lomuto.c │ ├── req_1_to_n.c │ ├── req_a_to_b.c │ ├── req_check_pwr_2.c │ ├── req_num_ones.c │ ├── req_rotate_digits.c │ ├── req_sum_digits.c │ └── tim_sort.c ├── 4_search ├── lection │ ├── images │ │ ├── bs_iterative_c_impl.png │ │ ├── bs_pseudo_iter.png │ │ ├── bs_rec_tree.png │ │ ├── bs_recursive_c_impl.png │ │ ├── doubling.png │ │ ├── doubling_complexity.png │ │ ├── doubling_pseudo.png │ │ ├── interpolation_formula.png │ │ ├── interpolation_pseudo.png │ │ ├── jump_search.jpg │ │ ├── linear_search.png │ │ ├── monsters_meme.jpg │ │ ├── ternary.png │ │ ├── ternary_iterative.png │ │ └── ternary_recursive.png │ └── slides │ │ ├── .3_sorting_recursion.tex.swp │ │ ├── 4_search.pdf │ │ ├── 4_search.tex │ │ ├── HSE-theme │ │ ├── 01_Logo_HSE_full_eng_CMYK.pdf │ │ ├── 01_Logo_HSE_full_rus_CMYK.pdf │ │ ├── 01_Znak_CMYK.pdf │ │ └── beamerthemeHSE.sty │ │ └── beamerthemeHSE.sty └── practice │ ├── CMakeLists.txt │ ├── build.sh │ ├── md │ ├── 0.md │ ├── 1.md │ ├── 2.md │ ├── 3.md │ ├── 4.md │ ├── 5.md │ ├── 6.md │ ├── 7.md │ ├── 8.md │ └── images │ │ ├── binary_search_code.png │ │ ├── exponential_search_code.png │ │ ├── interpolation_search_code.png │ │ ├── jump_search_code.png │ │ ├── linear_search_code.png │ │ ├── ternary_search_code.png │ │ └── ternary_search_for_unimodal_func_code.png │ ├── practice.md │ └── src │ ├── benchmark.c │ ├── binary_search.c │ ├── exponential_search.c │ ├── interpolation_search.c │ ├── jump_search.c │ ├── linear_search.c │ ├── ternary_search.c │ └── ternary_search_for_unimodal_func.c ├── 5_simple_data_structures ├── lection │ ├── images │ │ ├── ll_circular_variant.png │ │ ├── ll_doubly_complexity_table.png │ │ ├── ll_doubly_variant.png │ │ ├── ll_node_code.png │ │ ├── ll_node_create.png │ │ ├── ll_pros_cons.png │ │ ├── ll_single.png │ │ ├── ll_single_variant.png │ │ ├── ll_singly_complexity_table.png │ │ ├── ll_traverse.png │ │ ├── queue.png │ │ ├── queue_array.png │ │ ├── queue_array_create.png │ │ ├── queue_array_enqueue.png │ │ ├── queue_complexity_table.png │ │ ├── queue_example.png │ │ ├── queue_ll.png │ │ ├── stack.png │ │ ├── stack_arrays.png │ │ ├── stack_complexity_table.png │ │ ├── stack_empty.png │ │ ├── stack_full.png │ │ ├── stack_ll.png │ │ ├── stack_ll_picture.png │ │ ├── stack_peek.png │ │ ├── stack_pop.png │ │ ├── stack_push.png │ │ └── stack_usage.png │ └── slides │ │ ├── .3_sorting_recursion.tex.swp │ │ ├── 5_simple_data_structures.pdf │ │ ├── 5_simple_data_structures.tex │ │ ├── HSE-theme │ │ ├── 01_Logo_HSE_full_eng_CMYK.pdf │ │ ├── 01_Logo_HSE_full_rus_CMYK.pdf │ │ ├── 01_Znak_CMYK.pdf │ │ └── beamerthemeHSE.sty │ │ └── beamerthemeHSE.sty └── practice │ ├── CMakeLists.txt │ ├── build.sh │ ├── md │ ├── 0.md │ ├── 1.md │ ├── 2.md │ ├── 3.md │ ├── 4.md │ ├── 5.md │ ├── 6.md │ └── images │ │ ├── linked_list_add_after_before_code.png │ │ ├── linked_list_add_code.png │ │ ├── linked_list_create_delete_code.png │ │ ├── linked_list_data_structures_code.png │ │ ├── linked_list_delete_element_code.png │ │ ├── linked_list_search_code.png │ │ ├── queue_code.png │ │ └── stack_code.png │ ├── practice.md │ └── src │ ├── array_queue.c │ ├── array_stack.c │ ├── linked_list.c │ ├── list_queue.c │ └── list_stack.c ├── README.md ├── TOC.md ├── config ├── carbon_source_config.json └── presets │ └── build.sh ├── generate_build_scripts.py ├── generate_practice_md.py ├── links.md └── old ├── lections ├── 0_intro+arrays.pptx ├── 1_types_arrays_complexity.pptx ├── 2_sorts.pptx ├── 3.5_cryptography_101.pptx ├── 3_number_theory.pptx ├── 4_data_structures_1.pptx └── 5_data_structures_2.pptx ├── practice ├── 10_graphs │ ├── Makefile │ ├── adjacency_list.c │ ├── adjacency_matrix.c │ └── edges_list.c ├── 11_graph_path │ ├── Makefile │ ├── bellman_ford │ ├── bellman_ford.c │ ├── dijkstra │ ├── dijkstra.c │ ├── floyd_warshall │ ├── floyd_warshall.c │ ├── graph.c │ └── graph.h ├── 12_graph_MST │ ├── Makefile │ ├── kruskal.cpp │ └── prima.cpp ├── 12_two_pointers │ ├── CMakeLists.txt │ ├── Readme.md │ ├── min_k_sum.cc │ ├── most_close.cc │ └── sum_of_two.cc ├── 13_substr │ ├── Makefile │ ├── kmp.c │ ├── main.c │ ├── naive.c │ ├── rabin_karp.c │ └── substr.h ├── 15_dynamic │ ├── Makefile │ ├── README_EN.md │ ├── README_RU.md │ ├── knapsack.h │ ├── knapsack_0_1.c │ ├── knapsack_unbounded.c │ └── lcm.c ├── 2_sorting │ ├── Makefile │ ├── counting_sort.c │ ├── readme_RU.md │ ├── sorting.c │ ├── sorting.h │ └── utility_demo.c ├── 3_search │ ├── Makefile │ ├── exponential_search_w_itr_binary.c │ ├── exponential_search_w_rec_binary.c │ ├── interpolation_search.c │ └── linear_search.c ├── 4_numbers_and_ciphers │ ├── one_time_pad_cipher.c │ ├── prime_numbers.c │ ├── shift_cipher.c │ ├── subs_cipher.c │ └── vigenere_cipher.c ├── 5_bitmanip │ ├── Makefile │ └── bitmanip.c ├── 7_hash_table │ ├── Makefile │ └── main.c ├── 9_disjoint_set_union │ ├── Makefile │ └── dsu.c └── cpp │ ├── binary_search_tree │ ├── README_EN.md │ ├── README_RU.md │ └── binary_search_tree.cpp │ ├── hash_map │ ├── Makefile │ ├── README_EN.md │ ├── README_RU.md │ ├── hash_map_with_diff_key_value_types.cpp │ └── outputs.txt │ └── topological_sort │ ├── MakeLists.txt │ ├── README_EN.md │ ├── README_RU.md │ ├── dfs_topsort.cpp │ └── kahn.cpp └── snippets └── time.c /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.out 3 | *.a 4 | .vscode 5 | 6 | practice/2_sorting/* 7 | !practice/2_sorting/*.c 8 | !practice/2_sorting/*.h 9 | !practice/2_sorting/*.md 10 | !practice/2_sorting/Makefile 11 | 12 | practice/3_search/* 13 | !practice/3_search/*.c 14 | !practice/3_search/*.h 15 | !practice/3_search/*.md 16 | !practice/3_search/Makefile 17 | 18 | practice/5_bitmanip/* 19 | !practice/5_bitmanip/*.c 20 | !practice/5_bitmanip/*.h 21 | !practice/5_bitmanip/*.md 22 | !practice/5_bitmanip/Makefile 23 | 24 | practice/6_simple_data_structures/* 25 | !practice/6_simple_data_structures/*.c 26 | !practice/6_simple_data_structures/*.h 27 | !practice/6_simple_data_structures/*.md 28 | !practice/6_simple_data_structures/Makefile 29 | 30 | practice/7_hash_table/* 31 | !practice/7_hash_table/*.c 32 | !practice/7_hash_table/*.h 33 | !practice/7_hash_table/*.md 34 | !practice/7_hash_table/Makefile 35 | 36 | practice/8_heap/* 37 | !practice/8_heap/*.c 38 | !practice/8_heap/*.h 39 | !practice/8_heap/*.md 40 | !practice/8_heap/Makefile 41 | 42 | practice/9_disjoint_set_union/* 43 | !practice/9_disjoint_set_union/*.c 44 | !practice/9_disjoint_set_union/*.h 45 | !practice/9_disjoint_set_union/*.md 46 | !practice/9_disjoint_set_union/Makefile 47 | 48 | practice/10_graphs/* 49 | !practice/10_graphs/*.c 50 | !practice/10_graphs/*.h 51 | !practice/10_graphs/*.md 52 | !practice/10_graphs/Makefile 53 | 54 | build 55 | *build* 56 | !*build.sh* 57 | *bin* 58 | !binary_search.c 59 | !binary_search_code.png 60 | !generate_build_scripts.py 61 | -------------------------------------------------------------------------------- /0_intro/lection/0_0_plan.md: -------------------------------------------------------------------------------- 1 | # Лекция 0. Алгоритмы, задачи, вычислительные машины. 2 | 3 | ### Часть 0 - План 4 | 5 | ### Часть 1. [Понятие алгоритма](0_1_algorithms.md) 6 | #TODO: Добавить оглавление части 7 | 8 | ### Часть 2. [Вычислительные машины](0_2_computers.md) 9 | #TODO: Добавить оглавление части 10 | 11 | ### Часть 3. [Алгоритмы и программы](0_3_programms.md) 12 | #TODO: Добавить оглавление части 13 | 14 | ### Часть 4. [Алгоритмы и данные](0_4_variables.md) 15 | #TODO: Добавить оглавление части 16 | 17 | ### Часть 5. [Двоичные операторы](0_5_binary_operators.md) 18 | #TODO: Добавить оглавление части 19 | 20 | 21 | -------------------------------------------------------------------------------- /0_intro/lection/0_full_lecture.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/0_full_lecture.md -------------------------------------------------------------------------------- /0_intro/lection/images/abacus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/abacus.jpg -------------------------------------------------------------------------------- /0_intro/lection/images/ada_byron.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/ada_byron.png -------------------------------------------------------------------------------- /0_intro/lection/images/analytical_engine_cards.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/analytical_engine_cards.jpg -------------------------------------------------------------------------------- /0_intro/lection/images/and_truth_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/and_truth_table.png -------------------------------------------------------------------------------- /0_intro/lection/images/ascii_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/ascii_table.png -------------------------------------------------------------------------------- /0_intro/lection/images/assembler_code_example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/assembler_code_example.jpg -------------------------------------------------------------------------------- /0_intro/lection/images/babbage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/babbage.png -------------------------------------------------------------------------------- /0_intro/lection/images/bit_byte_nibble_word.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/bit_byte_nibble_word.png -------------------------------------------------------------------------------- /0_intro/lection/images/bit_shift_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/bit_shift_example.png -------------------------------------------------------------------------------- /0_intro/lection/images/bit_shift_example_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/bit_shift_example_result.png -------------------------------------------------------------------------------- /0_intro/lection/images/bitmask_simple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/bitmask_simple.png -------------------------------------------------------------------------------- /0_intro/lection/images/bitmask_simple_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/bitmask_simple_result.png -------------------------------------------------------------------------------- /0_intro/lection/images/bitwise_operator_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/bitwise_operator_example.png -------------------------------------------------------------------------------- /0_intro/lection/images/bitwise_operator_example_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/bitwise_operator_example_result.png -------------------------------------------------------------------------------- /0_intro/lection/images/compiler_code_stage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/compiler_code_stage.png -------------------------------------------------------------------------------- /0_intro/lection/images/compiler_run_stage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/compiler_run_stage.png -------------------------------------------------------------------------------- /0_intro/lection/images/cormen_4_cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/cormen_4_cover.jpg -------------------------------------------------------------------------------- /0_intro/lection/images/cpp_how_compile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/cpp_how_compile.png -------------------------------------------------------------------------------- /0_intro/lection/images/dasgupta_cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/dasgupta_cover.jpg -------------------------------------------------------------------------------- /0_intro/lection/images/diff_engine.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/diff_engine.jpg -------------------------------------------------------------------------------- /0_intro/lection/images/different_data_interpretation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/different_data_interpretation.png -------------------------------------------------------------------------------- /0_intro/lection/images/differential_engine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/differential_engine.png -------------------------------------------------------------------------------- /0_intro/lection/images/eniac.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/eniac.png -------------------------------------------------------------------------------- /0_intro/lection/images/fp_conversions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/fp_conversions.png -------------------------------------------------------------------------------- /0_intro/lection/images/fp_half_precision_structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/fp_half_precision_structure.png -------------------------------------------------------------------------------- /0_intro/lection/images/hex_digits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/hex_digits.png -------------------------------------------------------------------------------- /0_intro/lection/images/hex_hw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/hex_hw.png -------------------------------------------------------------------------------- /0_intro/lection/images/int_types_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/int_types_example.png -------------------------------------------------------------------------------- /0_intro/lection/images/int_types_mem_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/int_types_mem_example.png -------------------------------------------------------------------------------- /0_intro/lection/images/interpreter_code_stage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/interpreter_code_stage.png -------------------------------------------------------------------------------- /0_intro/lection/images/interpreter_run_stage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/interpreter_run_stage.png -------------------------------------------------------------------------------- /0_intro/lection/images/literals_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/literals_example.png -------------------------------------------------------------------------------- /0_intro/lection/images/literals_example_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/literals_example_result.png -------------------------------------------------------------------------------- /0_intro/lection/images/memory_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/memory_example.png -------------------------------------------------------------------------------- /0_intro/lection/images/not_truth_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/not_truth_table.png -------------------------------------------------------------------------------- /0_intro/lection/images/old_geek.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/old_geek.png -------------------------------------------------------------------------------- /0_intro/lection/images/or_truth_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/or_truth_table.png -------------------------------------------------------------------------------- /0_intro/lection/images/pascal_calc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/pascal_calc.jpg -------------------------------------------------------------------------------- /0_intro/lection/images/pascal_calc.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/pascal_calc.xcf -------------------------------------------------------------------------------- /0_intro/lection/images/pascal_code_example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/pascal_code_example.jpg -------------------------------------------------------------------------------- /0_intro/lection/images/processor_unit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/processor_unit.jpg -------------------------------------------------------------------------------- /0_intro/lection/images/programming_translation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/programming_translation.png -------------------------------------------------------------------------------- /0_intro/lection/images/schedule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/schedule.png -------------------------------------------------------------------------------- /0_intro/lection/images/sedgewick_cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/sedgewick_cover.jpg -------------------------------------------------------------------------------- /0_intro/lection/images/signed_16bit_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/signed_16bit_example.png -------------------------------------------------------------------------------- /0_intro/lection/images/signed_all_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/signed_all_table.png -------------------------------------------------------------------------------- /0_intro/lection/images/signed_int_types.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/signed_int_types.png -------------------------------------------------------------------------------- /0_intro/lection/images/signed_magn_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/signed_magn_example.png -------------------------------------------------------------------------------- /0_intro/lection/images/simple_prog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/simple_prog.png -------------------------------------------------------------------------------- /0_intro/lection/images/tony_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/tony_start.png -------------------------------------------------------------------------------- /0_intro/lection/images/transistor_team.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/transistor_team.jpg -------------------------------------------------------------------------------- /0_intro/lection/images/transistor_team.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/transistor_team.png -------------------------------------------------------------------------------- /0_intro/lection/images/unsigned_int_types.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/unsigned_int_types.png -------------------------------------------------------------------------------- /0_intro/lection/images/vars_simple_programm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/vars_simple_programm.png -------------------------------------------------------------------------------- /0_intro/lection/images/women_eniac.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/women_eniac.png -------------------------------------------------------------------------------- /0_intro/lection/images/xor_truth_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/images/xor_truth_table.png -------------------------------------------------------------------------------- /0_intro/lection/slides/0_introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/slides/0_introduction.pdf -------------------------------------------------------------------------------- /0_intro/lection/slides/HSE-theme/01_Logo_HSE_full_eng_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/slides/HSE-theme/01_Logo_HSE_full_eng_CMYK.pdf -------------------------------------------------------------------------------- /0_intro/lection/slides/HSE-theme/01_Logo_HSE_full_rus_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/slides/HSE-theme/01_Logo_HSE_full_rus_CMYK.pdf -------------------------------------------------------------------------------- /0_intro/lection/slides/HSE-theme/01_Znak_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/slides/HSE-theme/01_Znak_CMYK.pdf -------------------------------------------------------------------------------- /0_intro/lection/slides/images/pascal_calc.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/lection/slides/images/pascal_calc.xcf -------------------------------------------------------------------------------- /0_intro/practice/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rdf build 4 | cmake . -Bbuild 5 | cd build 6 | make -j8 7 | make install 8 | cd .. 9 | -------------------------------------------------------------------------------- /0_intro/practice/md/0.md: -------------------------------------------------------------------------------- 1 | _Практика 0. Трансляция, переменные, типы данных, битовые операции._ 2 | 3 | # Cекция 0 - Введение в трансляцию, компиляция и линковка на языке C. 4 | 5 | ## Цели секции: 6 | 7 | 1. Посмотреть как исходный код на языке программирования C превращается в исполнямый машинный код 8 | 9 | ## Сценарий 1. Один файл 10 | - Создаем файл с исходным кодом на языке C 11 | - Запускаем компилятор, получаем объектный файл 12 | - Запускаем линковщик, получаем исполняемый файл 13 | - Запускаем исполняемый файл, проверяем результат работы кода 14 | 15 | ![compilation_single](./images/compilation_single.png) 16 | 17 | 18 | ## Сценарий 2. Несколько файлов + библиотека (опционально) 19 | - Создаем нейсколько файлов с исходным кодом на языке C 20 | - Создаем библиотеку (опционально) 21 | - Запускаем компилятор, получаем объектные файлы 22 | - Запускаем линковщик, получаем исполняемый файл 23 | - Запускаем исполняемый файл, проверяем результат работы кода 24 | 25 | [plan](../practice.md) | [>](1.md) 26 | -------------------------------------------------------------------------------- /0_intro/practice/md/1.md: -------------------------------------------------------------------------------- 1 | _Практика 0. Трансляция, переменные, типы данных, битовые операции._ 2 | 3 | # Секция 1 - Адреса и переменные. 4 | 5 | ## Цели секции: 6 | 7 | 1. Изучить как размер и адрес переменной в памяти зависит от её типа 8 | 9 | ## Пример с переменными разных типов и их адресами 10 | 11 | Исходный код - [addresses.c](../src/addresses.c) 12 | 13 | ### Исходный код программы: 14 | ![](images/addresses_code.png) 15 | 16 | ### Результат выполнения программы: 17 | ![](images/addresses_out.png) 18 | 19 | [<](0.md) | [plan](../practice.md) | [>](2.md) 20 | -------------------------------------------------------------------------------- /0_intro/practice/md/3.md: -------------------------------------------------------------------------------- 1 | _Практика 0. Трансляция, переменные, типы данных, битовые операции._ 2 | 3 | # Секция 3 - Битовые операции. 4 | 5 | ## Цели секции: 6 | 7 | 1. Изучить различные числовые литералы 8 | 2. Изучить битовые операции 9 | 10 | ## Пример числовых литералов 11 | Исходный код - [literals_example.c](../src/literals_example.c) 12 | 13 | ### Исходный код программы: 14 | ![](images/literals_example_code.png) 15 | 16 | ### Результат выполнения программы: 17 | ![](images/literals_example_out.png) 18 | 19 | ## Пример битовых операторов 20 | Исходный код - [bitwise_operator_example.c](../src/bitwise_operator_example.c) 21 | 22 | ### Исходный код программы: 23 | ![](images/bitwise_operator_example_code.png) 24 | 25 | ### Результат выполнения программы: 26 | ![](images/bitwise_operator_example_out.png) 27 | 28 | ## Пример обмена значениями (числа + произвольные биты) 29 | Исходный код - [swap_variables.c](../src/swap_variables.c) 30 | 31 | ### Исходный код программы: 32 | ![](images/swap_variables_code.png) 33 | 34 | ### Результат выполнения программы: 35 | ![](images/swap_variables_out.png) 36 | 37 | ## Пример двоичных масок и сдвигов 38 | Исходный код - [print_bits.c](../src/print_bits.c) 39 | 40 | ### Исходный код программы: 41 | ![](images/print_bits.png) 42 | 43 | [<](2.md) | [plan](../practice.md) | [>](4.md) 44 | -------------------------------------------------------------------------------- /0_intro/practice/md/4.md: -------------------------------------------------------------------------------- 1 | _Практика 0. Трансляция, переменные, типы данных, битовые операции._ 2 | 3 | # Задача 0 - Формулировка задачи. 4 | 5 | Выполнить операции: 6 | * Установка значения бита `n` в байте 7 | * Очистка бита `n` в байте 8 | * Инверсия бита `n` в байте 9 | * Проверка бита `n` в байте 10 | 11 | Реализация всех операций должна занимать не более чем одну строчку кода. 12 | 13 | [<](3.md) | [plan](../practice.md) | [>](5.md) 14 | -------------------------------------------------------------------------------- /0_intro/practice/md/5.md: -------------------------------------------------------------------------------- 1 | _Практика 0. Трансляция, переменные, типы данных, битовые операции._ 2 | 3 | # Задача 0 - Решение. 4 | 5 | Исходный код - [bitop_oneline.c](../src/bitop_oneline.c)\ 6 | 7 | ### Исходный код программы: 8 | ![](images/bitop_oneline_code.png) 9 | 10 | ### Результат выполнения программы: 11 | ![](images/bitop_oneline_out.png) 12 | 13 | # Задача 0 - Альтернативное решение. 14 | 15 | Исходный код - [bitop_oneline_alternative.c](../src/bitop_oneline_alternative.c) 16 | 17 | ### Исходный код программы: 18 | ![](images/bitop_oneline_alt_code.png) 19 | 20 | ### Результат выполнения программы: 21 | ![](images/bitop_oneline_alt_out.png) 22 | 23 | ### Замечание 24 | pow(2, n) можно заменить эквивалентным побитовым сдвигом: 1 << n.\ 25 | В реальных проектах лучше использовать побитовый сдвиг, так как он реализуются на уровне процессора как очень быстрая машинная инструкция, а возведение в степень требует большего числа операций, что негативно влияет на производительность. 26 | 27 | [<](4.md) | [plan](../practice.md) | [>](6.md) 28 | -------------------------------------------------------------------------------- /0_intro/practice/md/6.md: -------------------------------------------------------------------------------- 1 | _Практика 0. Трансляция, переменные, типы данных, битовые операции._ 2 | 3 | # Задача 1 - Формулировка задачи 4 | 5 | Дан массив, в котором одно число уникально, а остальные встречаются ровно два раза. Найти уникальное число. 6 | 7 | [<](5.md) | [plan](../practice.md) | [>](7.md) 8 | -------------------------------------------------------------------------------- /0_intro/practice/md/7.md: -------------------------------------------------------------------------------- 1 | _Практика 0. Трансляция, переменные, типы данных, битовые операции._ 2 | 3 | # Задача 1 - Решение 4 | 5 | Исходный код - [find_unique.c](../src/find_unique.c) 6 | 7 | ### Исходный код программы: 8 | ![](images/find_unique.png) 9 | 10 | [<](6.md) | [plan](../practice.md) 11 | -------------------------------------------------------------------------------- /0_intro/practice/md/images/addresses_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/addresses_code.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/addresses_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/addresses_out.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/bitop_oneline_alt_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/bitop_oneline_alt_code.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/bitop_oneline_alt_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/bitop_oneline_alt_out.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/bitop_oneline_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/bitop_oneline_code.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/bitop_oneline_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/bitop_oneline_out.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/bitwise_operator_example_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/bitwise_operator_example_code.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/bitwise_operator_example_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/bitwise_operator_example_out.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/compilation_single.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/compilation_single.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/find_unique.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/find_unique.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/int_and_float_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/int_and_float_code.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/int_and_float_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/int_and_float_out.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/literals_example_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/literals_example_code.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/literals_example_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/literals_example_out.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/print_bits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/print_bits.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/signed_unsigned_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/signed_unsigned_code.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/signed_unsigned_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/signed_unsigned_out.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/swap_variables_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/swap_variables_code.png -------------------------------------------------------------------------------- /0_intro/practice/md/images/swap_variables_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/practice/md/images/swap_variables_out.png -------------------------------------------------------------------------------- /0_intro/practice/practice.md: -------------------------------------------------------------------------------- 1 | # Практика 0. Трансляция, переменные, типы данных, битовые операции. 2 | 3 | ## План практики 4 | 5 | ### Секция 0 - [Введение в трансляцию, компиляция и линковка на языке C.](md/0.md) 6 | ### Секция 1 - [Адреса и переменные.](md/1.md) 7 | ### Секция 2 - [Типы данных.](md/2.md) 8 | ### Секция 3 - [Битовые операции.](md/3.md) 9 | ### Задача 0 - [Формулировка задачи.](md/4.md) 10 | ### Задача 0 - [Решение.](md/5.md) 11 | ### Задача 1 - [Формулировка задачи.](md/6.md) 12 | ### Задача 1 - [Решение.](md/7.md) 13 | 14 | [к лекции](../0_0_plan.md) | [к оглавлению](../../TOC.md) 15 | -------------------------------------------------------------------------------- /0_intro/practice/src/addresses.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // - пример с переменными разных типов и их адресами 4 | 5 | int main() { 6 | // Create 4 variables of different types 7 | int intVariable = 30; 8 | float floatVariable = 1.1; 9 | double doubleVariable = 1.1; 10 | char charVariable = 'c'; 11 | 12 | printf("int start address = %p\n", &intVariable); 13 | printf("int size = %lu\n", sizeof(int)); 14 | // Int variable - address + 1 = address + one int 15 | printf("int end address = %p\n\n", &intVariable + 1); 16 | 17 | printf("float start address = %p\n", &floatVariable); 18 | printf("float size = %lu\n", sizeof(floatVariable)); 19 | // Float variable - address + 1 = address + one float 20 | printf("float end address = %p\n\n", &floatVariable + 1); 21 | 22 | printf("double start address = %p\n", &doubleVariable); 23 | printf("double size = %lu\n", sizeof(doubleVariable)); 24 | // Double variable - address + 1 = address + one double 25 | printf("double end address = %p\n\n", &doubleVariable + 1); 26 | 27 | printf("char start address = %p\n", &charVariable); 28 | printf("char size = %lu\n", sizeof(charVariable)); 29 | // Char variable - address + 1 = address + one char 30 | printf("char end address = %p\n\n", &charVariable + 1); 31 | } 32 | -------------------------------------------------------------------------------- /0_intro/practice/src/bitmask_simple_example.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | const unsigned int MASK1 = 0x0000000F; 5 | const unsigned int MASK2 = 0x000000FF; 6 | const unsigned int MASK3 = 0x000F0000; 7 | 8 | unsigned int a = 0x0ACE; 9 | 10 | printf("%d & %d = %d\n", a, MASK1, a & MASK1); 11 | printf("%d & %d = %d\n", a, MASK2, a & MASK2); 12 | printf("%d & %d = %d\n", a, MASK3, a & MASK3); 13 | 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /0_intro/practice/src/bitmasks.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // need explicit size types here 5 | uint8_t get_byte(int value) { 6 | return value & 0xFF; 7 | } 8 | 9 | int main() { 10 | int value = 0xA1B2C3D4; 11 | 12 | printf("full value = 0x%x\n", value); 13 | printf("byte 0 = 0x%x\n", get_byte(value)); 14 | printf("byte 1 = 0x%x\n", get_byte(value >> 8)); 15 | printf("byte 2 = 0x%x\n", get_byte(value >> 8 * 2)); 16 | printf("byte 3 = 0x%x\n", get_byte(value >> 8 * 3)); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /0_intro/practice/src/bitop_oneline.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void print_bits_hi_to_lo(uint8_t value) { 5 | printf("0b"); 6 | 7 | 8 | for (int j = 8 - 1; j >= 0; j--) { 9 | printf("%d", (value >> j) & 0x1); 10 | } 11 | 12 | printf("\n"); 13 | } 14 | 15 | uint8_t set_bit(uint8_t value, size_t bit) { 16 | return value |= 1 << bit; 17 | } 18 | 19 | uint8_t clear_bit(uint8_t value, size_t bit) { 20 | return value &= ~(1 << bit); 21 | } 22 | 23 | uint8_t flip_bit(uint8_t value, size_t bit) { 24 | return value ^= 1 << bit; 25 | } 26 | 27 | uint8_t check_bit(uint8_t value, size_t bit) { 28 | return (value & (1 << bit)) >> bit; 29 | } 30 | 31 | 32 | int main() { 33 | uint8_t value = 0b00100100; 34 | 35 | size_t bit2 = 2; 36 | size_t bit3 = 3; 37 | size_t bit5 = 5; 38 | 39 | printf("initial value = "); 40 | print_bits_hi_to_lo(value); 41 | 42 | value = set_bit(value, bit3); 43 | printf("value after set bit %d = ", bit3); 44 | print_bits_hi_to_lo(value); 45 | 46 | value = clear_bit(value, bit2); 47 | printf("value after clear bit %d = ", bit2); 48 | print_bits_hi_to_lo(value); 49 | 50 | value = flip_bit(value, bit2); 51 | printf("value after flip bit %d = ", bit2); 52 | print_bits_hi_to_lo(value); 53 | 54 | value = flip_bit(value, bit3); 55 | printf("value after flip bit %d = ", bit3); 56 | print_bits_hi_to_lo(value); 57 | 58 | printf("is bit %d set = %d\n", bit5, check_bit(value, bit5)); 59 | 60 | return 0; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /0_intro/practice/src/bitop_oneline_alternative.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int x = 0b11001; //25 6 | int n = 2; //bit, starts from 1 7 | int mask = pow(2, n - 1); 8 | 9 | printf("Add n bit: %d\n", mask | x); 10 | printf("Remove n bit: %d\n", ~mask & x); 11 | printf("Inversion n bit: %d\n", mask ^ x); 12 | printf("Check n bit: %s\n", mask & x ? "yes" : "no"); 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /0_intro/practice/src/bitwise_operator_example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void print_bits_hi_to_lo(uint8_t value) { 5 | printf("0b"); 6 | 7 | 8 | for (int j = 8 - 1; j >= 0; j--) { 9 | printf("%d", (value >> j) & 0x1); 10 | } 11 | 12 | printf("\n"); 13 | } 14 | 15 | // - пример битовых операторов (AND, OR, XOR, NOT) 16 | 17 | int main() 18 | { 19 | uint8_t a = 9; // 0b1001 20 | uint8_t b = 0b111; 21 | 22 | printf("Bitwise AND result = "); 23 | print_bits_hi_to_lo(a & b); 24 | printf("Bitwise OR result = "); 25 | print_bits_hi_to_lo(a | b); 26 | printf("Bitwise XOR result = "); 27 | print_bits_hi_to_lo(a ^ b); 28 | printf("Bitwise NOT result = "); 29 | print_bits_hi_to_lo(~ a); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /0_intro/practice/src/check_overflow.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int check_overflow(int a, int b) { 5 | return (b > INT_MAX - a) || (a > INT_MAX - b); 6 | } 7 | 8 | int main() { 9 | int a = 30; 10 | int b = 35; 11 | 12 | 13 | printf("a = %d \n", a); 14 | printf("b = %d \n", b); 15 | 16 | printf("will addition overflow - %d\n", check_overflow(a, b)); 17 | 18 | printf("a + b = %d \n", a + b); 19 | printf("\n"); 20 | 21 | a = INT_MAX - 30; 22 | b = 35; 23 | 24 | 25 | printf("a = %d \n", a); 26 | printf("b = %d \n", b); 27 | 28 | printf("will addition overflow - %d\n", check_overflow(a, b)); 29 | 30 | printf("a + b = %d \n", a + b); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /0_intro/practice/src/check_pwr_of_two.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int check_is_pwr_of_two_naive(int val) { 4 | int n_bits = sizeof(int) * 8; 5 | int n_one_bits = 0; 6 | 7 | for (int i = 0; i < n_bits; i++) { 8 | n_one_bits += (val >> i) & 0x1; 9 | } 10 | 11 | if (n_one_bits == 1) { 12 | return 1; 13 | } 14 | 15 | return 0; 16 | } 17 | 18 | int check_is_pwr_of_two_substraction(int val) { 19 | 20 | if (val == 0) { 21 | return 0; 22 | } 23 | 24 | if ((val & (val - 1)) == 0) { 25 | return 1; 26 | } 27 | 28 | return 0; 29 | } 30 | 31 | int main() { 32 | int pwr = 128; 33 | int not_pwr = 345; 34 | 35 | printf("check by naive method\n"); 36 | printf("value %d - check result %d\n", pwr, check_is_pwr_of_two_naive(pwr)); 37 | printf("value %d - check result %d\n", not_pwr, check_is_pwr_of_two_naive(not_pwr)); 38 | 39 | printf("check by substruction method\n"); 40 | printf("value %d - check result %d\n", pwr, check_is_pwr_of_two_substraction(pwr)); 41 | printf("value %d - check result %d\n", not_pwr, check_is_pwr_of_two_substraction(not_pwr)); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /0_intro/practice/src/decimal_to_octal.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void print_octal(int value) { 4 | 5 | if(value > 1073741823) { 6 | return; 7 | } 8 | 9 | printf("octal = 0oct"); 10 | 11 | int buffer[10]; 12 | int buffer_index = 0; 13 | 14 | while (value != 0) { 15 | buffer[buffer_index] = value % 8; 16 | buffer_index++; 17 | 18 | value = value / 8; 19 | } 20 | 21 | for (int i = buffer_index - 1; i >= 0; i--) { 22 | printf("%d", buffer[i]); 23 | } 24 | 25 | printf("\n"); 26 | } 27 | 28 | int main() { 29 | int value = 7; 30 | 31 | printf("decimal = %d\n", value); 32 | print_octal(value); 33 | 34 | value = 8; 35 | 36 | printf("decimal = %d\n", value); 37 | print_octal(value); 38 | 39 | value = 9; 40 | 41 | printf("decimal = %d\n", value); 42 | print_octal(value); 43 | 44 | value = 64 * 3 + 8 * 5 + 4; 45 | 46 | printf("decimal = %d\n", value); 47 | print_octal(value); 48 | 49 | 50 | return 0; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /0_intro/practice/src/find_unique.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() { 5 | 6 | int arr[11] = {1, 3, 2, 2, 1, 3, 7, 9, 8, 8, 9}; 7 | 8 | int unique = 0; 9 | 10 | for (size_t i = 0; i < sizeof(arr)/sizeof(arr[0]); i++){ 11 | unique ^= arr[i]; 12 | } 13 | 14 | printf("unique = %d\n", unique); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /0_intro/practice/src/literals_example.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | unsigned int aBin = 0b1010; 5 | unsigned int aOct = 0101; 6 | unsigned int aHex = 0xFF; 7 | 8 | printf("Binary 0b1010 = %d\n", aBin); 9 | printf("Oct 0101 = %d\n", aOct); 10 | printf("Hex 0xFF = %d\n", aHex); 11 | 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /0_intro/practice/src/print_bits.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // - пример двоичных масок (выделение байт) 5 | // - примеры двоичных сдвигов (лево, право) 6 | 7 | uint8_t get_byte(int value) { 8 | return value & 0xFF; 9 | } 10 | 11 | void print_bytes_hi_to_lo(int value) { 12 | 13 | printf("0x"); 14 | 15 | for (int i = sizeof(int) - 1; i >= 0; i--) { 16 | // printf("%d\n", i); 17 | printf("%02x", get_byte(value >> i * 8)); 18 | } 19 | 20 | printf("\n"); 21 | } 22 | 23 | void print_bits_hi_to_lo(int value) { 24 | printf("0b"); 25 | 26 | for (int i = sizeof(int) - 1; i >= 0; i--) { 27 | uint8_t byte = get_byte(value >> i * 8); 28 | 29 | for (int j = 8 - 1; j >= 0; j--) { 30 | printf("%d", (byte >> j) & 0x1); 31 | } 32 | } 33 | 34 | printf("\n"); 35 | } 36 | 37 | int main() { 38 | int value = 12; 39 | 40 | printf("0x%08x\n", value); 41 | 42 | print_bytes_hi_to_lo(value); 43 | print_bits_hi_to_lo(value); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /0_intro/practice/src/signed_unsigned.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void print_bits_hi_to_lo(uint8_t value) { 5 | printf("0b"); 6 | 7 | 8 | for (int j = 8 - 1; j >= 0; j--) { 9 | printf("%d", (value >> j) & 0x1); 10 | } 11 | 12 | printf("\n"); 13 | } 14 | 15 | int main() { 16 | 17 | uint8_t two = 2; 18 | int8_t plus_two = 2; 19 | int8_t minus_two = -2; 20 | 21 | printf("unsigned %d = ", two); 22 | print_bits_hi_to_lo(two); 23 | 24 | printf("signed %d = ", plus_two); 25 | print_bits_hi_to_lo(plus_two); 26 | 27 | printf("signed %d = ", minus_two); 28 | print_bits_hi_to_lo(minus_two); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /0_intro/practice/src/swap_variables.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // - пример обмена значениями (числа + произвольные биты) 5 | 6 | void swap_add_sub(int* x, int* y) { 7 | 8 | *x = *x + *y; // x = x + y 9 | *y = *x - *y; // y = (x + y) - y = x 10 | *x = *x - *y; // x = x + y - x = y 11 | } 12 | 13 | void swap_xor(int* x, int* y) { 14 | *x = *x ^ *y; // x = x ^ y 15 | *y = *x ^ *y; // y = (x ^ y) ^ y = x 16 | *x = *x ^ *y; // x = (x ^ y) ^ x = y 17 | } 18 | 19 | void swap_xor_array(void* x, void* y, int bytelen) { 20 | // need explicit size types here 21 | uint8_t* p_x = (char*)x; 22 | uint8_t* p_y = (char*)y; 23 | 24 | for (size_t i = 0; i < bytelen; i++) { 25 | p_x[i] = p_x[i] ^ p_y[i]; // x = x ^ y 26 | p_y[i] = p_x[i] ^ p_y[i]; // y = (x ^ y) ^ y = x 27 | p_x[i] = p_x[i] ^ p_y[i]; // x = (x ^ y) ^ x = y 28 | } 29 | 30 | } 31 | 32 | // mul div swap also exists, but ommitted here because it is uneffective 33 | 34 | int main() { 35 | int x = 128; 36 | int y = 345; 37 | 38 | int* p_x = &x; 39 | int* p_y = &y; 40 | 41 | printf("initial values\n"); 42 | printf("%d, %d\n", x, y); 43 | 44 | swap_add_sub(p_x, p_y); 45 | 46 | printf("values after swap_add_sub\n"); 47 | printf("%d, %d\n", x, y); 48 | 49 | swap_xor_array(p_x, p_y, sizeof(int)); 50 | 51 | printf("values after swap_xor\n"); 52 | printf("%d, %d\n", x, y); 53 | 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /0_intro/src/bitmask_simple_example_output.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/0_intro/src/bitmask_simple_example_output.txt -------------------------------------------------------------------------------- /0_intro/src/bitwise_operator_example_output.txt: -------------------------------------------------------------------------------- 1 | Bitwise AND result = 1 2 | Bitwise OR result = 15 3 | Bitwise XOR result = 14 4 | Bitwise NOT result = -10 5 | 6 | -------------------------------------------------------------------------------- /0_intro/src/bitwise_shift_example.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a = 3; 6 | int b = -3; 7 | 8 | printf("Unsigned left shifts\n"); 9 | printf("%d << %d = %d \n", a, 1, a << 1); 10 | printf("%d << %d = %d \n", a, 2, a << 2); 11 | 12 | printf("Signed left shifts\n"); 13 | printf("%d << %d = %d \n", b, 1, b << 1); 14 | printf("%d << %d = %d \n", b, 2, b << 2); 15 | 16 | printf("Unsigned right shifts\n"); 17 | printf("%d >> %d = %d \n", a, 1, a >> 1); 18 | printf("%d >> %d = %d \n", a, 2, a >> 2); 19 | 20 | printf("Signed right shifts\n"); 21 | printf("%d >> %d = %d \n", b, 1, b >> 1); 22 | printf("%d >> %d = %d \n", b, 2, b >> 2); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /0_intro/src/bitwise_shift_example_output.txt: -------------------------------------------------------------------------------- 1 | Unsigned left shifts 2 | 3 << 1 = 6 3 | 3 << 2 = 12 4 | Signed left shifts 5 | -3 << 1 = -6 6 | -3 << 2 = -12 7 | Unsigned right shifts 8 | 3 >> 1 = 1 9 | 3 >> 2 = 0 10 | Signed right shifts 11 | -3 >> 1 = -2 12 | -3 >> 2 = -1 13 | 14 | -------------------------------------------------------------------------------- /0_intro/src/literals_example_output.txt: -------------------------------------------------------------------------------- 1 | Binary 0b1010 = 10 2 | Oct 0101 = 65 3 | Hex 0xFF = 255 4 | 5 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/1_0_plan.md: -------------------------------------------------------------------------------- 1 | # Лекция 1. Массивы, вычислительная сложность, тестирование. 2 | 3 | ### Часть 0 - [План](algorithms_course/repo/algorithms_course/1_arrays_complexity_testing/lection/1_0_plan.md) 4 | 5 | ### Часть 1. [Структура данных: массив](1_1_arrays.md) 6 | #TODO: Добавить оглавление части 7 | 8 | ### Часть 2. [Вычислительные задачи и корректность алгоритмов](1_2_problems.md) 9 | #TODO: Добавить оглавление части 10 | 11 | ### Часть 3. [Вычислительная сложность алгоритмов](1_3_complexity.md) 12 | #TODO: Добавить оглавление части 13 | 14 | ### Часть 4. [Тестирование программ](1_4_testing.md) 15 | #TODO: Добавить оглавление части 16 | 17 | 18 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_access.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_access.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_complexity_table2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_complexity_table2.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_dynamic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_dynamic.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_dynamic_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_dynamic_example.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_example.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_insert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_insert.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_intro.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_ndim.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_ndim.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_ndim2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_ndim2.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_pros_cons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_pros_cons.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_remove.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_rowcolumn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_rowcolumn.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_search.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_search_special.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_search_special.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_structure 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_structure 1.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_structure.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/array_types.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/array_types.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/bigo_complexity_chart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/bigo_complexity_chart.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/bigo_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/bigo_example.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/bigo_rules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/bigo_rules.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/bigo_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/bigo_test.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/complexity_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/complexity_table.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/cvrp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/cvrp.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/cvrp_math.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/cvrp_math.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/elementary_ops.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/elementary_ops.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/small_o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/small_o.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/testing_max.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/testing_max.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/images/testing_statement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/images/testing_statement.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/slides/1_arrays_complexity_testing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/slides/1_arrays_complexity_testing.pdf -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/slides/HSE-theme/01_Logo_HSE_full_eng_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/slides/HSE-theme/01_Logo_HSE_full_eng_CMYK.pdf -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/slides/HSE-theme/01_Logo_HSE_full_rus_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/slides/HSE-theme/01_Logo_HSE_full_rus_CMYK.pdf -------------------------------------------------------------------------------- /1_arrays_complexity_testing/lection/slides/HSE-theme/01_Znak_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/lection/slides/HSE-theme/01_Znak_CMYK.pdf -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rdf build 4 | cmake . -Bbuild 5 | cd build 6 | make -j8 7 | make install 8 | cd .. 9 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/1.md: -------------------------------------------------------------------------------- 1 | _Практика 1. Тестирование. Работа с массивами._ 2 | 3 | # Cекция 1 - Адреса и массивы.. 4 | 5 | ## Цели секции: 6 | 7 | 1. Изучить как массивы располагаются в памяти 8 | 9 | Исходный код - [addresses_arrays.c](../src/addresses_arrays.c) 10 | 11 | ### Исходный код программы: 12 | ![](images/addresses_arrays_code.png) 13 | 14 | ### Результат выполнения программы: 15 | ![](images/addresses_arrays_out.png) 16 | 17 | [<](0.md) | [plan](../practice.md) | [>](2.md) 18 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/10.md: -------------------------------------------------------------------------------- 1 | _Практика 1. Тестирование. Работа с массивами._ 2 | 3 | # Задача 1 - Решение. 4 | 5 | Обращение по строкам будет быстрее. 6 | 7 | Это связано с тем как массивы хранятся в памяти. Современные компьютеры могут выполнять доступ к последовательным участкам памяти более эффективно чем к непоследовательным. Каждая строка двумерного массива представляет собой последовательную память, по этому доступ по строкам будет быстрее. 8 | 9 | [<](9.md) | [plan](../practice.md) 10 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/5.md: -------------------------------------------------------------------------------- 1 | _Практика 1. Тестирование. Работа с массивами._ 2 | 3 | # Cекция 5 - Массивы - получение элемента по смешению (индексу). Измерение производительности получения элемента. 4 | 5 | ## Цели секции: 6 | 7 | 1. Измерить производительность операции получения элемента 8 | 9 | ## Производительность операции получения элемента по смешению (индексу) 10 | 11 | Исходный код - [get_element_by_index_perf.c](../src/get_element_by_index_perf.c) 12 | 13 | ### Сценарий измерения производительности 14 | * написан специальный код для экспериментов 15 | * операция взятия по смещению будет рассмотрена для следующих значений смещений: 0, средний индекс, последний индекс 16 | * для каждой позиции на одних и тех же данных будет произведено последовательно по несколько операций чтения по смещению (100 в параметрах), затем время суммируется 17 | 18 | > Несколько повторений операции нужны для того чтобы нивелировать возможный задержки со стороны операционной системы - для 100 экспериментов средний результат (как и сумма) должны быть более устойчивы к случайным зависаниям по вине ОС 19 | 20 | ### Ожидаемый результат выполнения программы 21 | Для всех смещений время чтения данных должно быть константным = `O(1)`. 22 | 23 | ### Реальный результат выполнения программы 24 | 25 | ### Результат выполнения программы: 26 | ![](images/get_element_by_index_perf_out.png) 27 | 28 | [<](4.md) | [plan](../practice.md) | [>](6.md) 29 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/6.md: -------------------------------------------------------------------------------- 1 | _Практика 1. Тестирование. Работа с массивами._ 2 | 3 | # Cекция 5 - Работа с двумерными массивами. 4 | 5 | ## Цели секции: 6 | 7 | 1. Измерить работу с двумерными массивами 8 | 9 | ## Вычисление суммы элемента массива по строкам и столбцам 10 | 11 | Исходный код - [2D_rows_cols_sum_simple.c](../src/2D_rows_cols_sum_simple.c) 12 | 13 | ### Исходный код программы: 14 | ![](images/2D_rows_cols_sum_simple_code.png) 15 | 16 | [<](5.md) | [plan](../practice.md) | [>](7.md) 17 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/7.md: -------------------------------------------------------------------------------- 1 | _Практика 1. Тестирование. Работа с массивами._ 2 | 3 | # Задача 0 - Формулировка задачи. 4 | 5 | Как можно ускорить работу кода для нахождения суммы элемента массива по строкам и столбцам? 6 | 7 | [<](6.md) | [plan](../practice.md) | [>](8.md) 8 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/8.md: -------------------------------------------------------------------------------- 1 | _Практика 1. Тестирование. Работа с массивами._ 2 | 3 | # Задача 0 - Решение. 4 | 5 | Исходный код - [2D_rows_cols_sum.c](../src/2D_rows_cols_sum.c) 6 | 7 | ### Исходный код программы: 8 | ![](images/2D_rows_cols_sum.png) 9 | 10 | [<](7.md) | [plan](../practice.md) | [>](9.md) 11 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/9.md: -------------------------------------------------------------------------------- 1 | _Практика 1. Тестирование. Работа с массивами._ 2 | 3 | # Задача 1 - Формулировка задачи. 4 | 5 | Есть два сценария обращения к элементам двумерного массива: 6 | 7 | 1) обращение по строкам 8 | 2) обращение по столбцам 9 | 10 | Какой из двух сценариев будет быстрее и почему? 11 | 12 | [<](8.md) | [plan](../practice.md) | [>](10.md) 13 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/2D_rows_cols_sum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/2D_rows_cols_sum.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/2D_rows_cols_sum_simple_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/2D_rows_cols_sum_simple_code.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/addresses_arrays_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/addresses_arrays_code.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/addresses_arrays_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/addresses_arrays_out.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/delete_element_alg_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/delete_element_alg_code.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/delete_element_alg_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/delete_element_alg_out.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/delete_element_perf_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/delete_element_perf_out.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/find_element_index_alg_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/find_element_index_alg_code.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/find_element_index_alg_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/find_element_index_alg_out.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/find_element_index_perf_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/find_element_index_perf_out.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/get_element_by_index_perf_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/get_element_by_index_perf_out.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/insert_element_alg_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/insert_element_alg_code.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/insert_element_alg_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/insert_element_alg_out.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/insert_element_perf_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/insert_element_perf_out.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/test_input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/test_input.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/md/images/test_sums.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/1_arrays_complexity_testing/practice/md/images/test_sums.png -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/practice.md: -------------------------------------------------------------------------------- 1 | # Практика 1. Тестирование. Работа с массивами. 2 | 3 | ## План практики 4 | 5 | ### Секция 0 - [Тестирование.](md/0.md) 6 | ### Секция 1 - [Адреса и массивы.](md/1.md) 7 | ### Секция 2 - [Массивы - вставка элемента. Измерение производительности вставоки.](md/2.md) 8 | ### Секция 3 - [Массивы - удаление элемента. Измерение производительности удаления.](md/3.md) 9 | ### Секция 4 - [Массивы - поиск элемента. Измерение производительности поиска.](md/4.md) 10 | ### Секция 5 - [Массивы - получение элемента по смешению (индексу). Измерение производительности получения элемента.](md/5.md) 11 | ### Секция 6 - [Работа с двумерными массивами.](md/6.md) 12 | ### Задача 0 - [Формулировка задачи.](md/7.md) 13 | ### Задача 0 - [Решение.](md/8.md) 14 | ### Задача 1 - [Формулировка задачи.](md/9.md) 15 | ### Задача 1 - [Решение.](md/10.md) 16 | 17 | [к оглавлению](../../TOC.md) 18 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/src/2D_rows_cols_sum.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define N_MAX 500 5 | #define M_MAX 500 6 | 7 | int main() 8 | { 9 | int n, m; 10 | scanf("%d", &n); 11 | scanf("%d", &m); 12 | 13 | // Two arrays to store our sums 14 | 15 | int64_t sum_rows[N_MAX] = {0}; 16 | int64_t sum_cols[M_MAX] = {0}; 17 | 18 | // This algorithm does one single pass over all elements 19 | int64_t temp; 20 | for(int i = 0; i < n; i++) 21 | { 22 | for(int j = 0; j < m; j++) 23 | { 24 | // Scanf current number and store it in int64_t variable. lld - long long decimal IS IMPORTANT 25 | scanf("%lld", &temp); 26 | sum_rows[i] += temp; 27 | sum_cols[j] += temp; 28 | } 29 | } 30 | 31 | // Now just print all the sums computed 32 | 33 | printf("\n"); 34 | 35 | for(int i = 0; i < n; i++) { 36 | // lld - long long decimal IS IMPORTANT 37 | printf("%lld ", sum_rows[i]); 38 | } 39 | printf("\n"); 40 | 41 | for(int i = 0; i < m; i++) { 42 | // lld - long long decimal IS IMPORTANT 43 | printf("%lld ", sum_cols[i]); 44 | } 45 | printf("\n"); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/src/2D_rows_cols_sum_simple.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define N_MAX 500 5 | #define M_MAX 500 6 | 7 | int main() 8 | { 9 | int n, m; 10 | scanf("%d", &n); 11 | scanf("%d", &m); 12 | 13 | // The most simple way is to allocate a big array, read all the number and then compute + print 14 | int64_t arr[N_MAX][M_MAX]; 15 | 16 | // Two arrays to store our sums 17 | int64_t sum_rows[N_MAX] = {0}; 18 | int64_t sum_cols[M_MAX] = {0}; 19 | 20 | // Read the input array 21 | for(int i = 0; i < n; i++) 22 | { 23 | for(int j = 0; j < m; j++) 24 | { 25 | // lld - long long decimal IS IMPORTANT 26 | scanf("%lld", &arr[i][j]); 27 | } 28 | } 29 | 30 | // Now traverse the array and compute all the sums 31 | for(int i = 0; i < n; i++) 32 | { 33 | for(int j = 0; j < m; j++) 34 | { 35 | sum_rows[i] += arr[i][j]; 36 | sum_cols[j] += arr[i][j]; 37 | } 38 | } 39 | 40 | // Then just print the results 41 | 42 | printf("\n"); 43 | 44 | for(int i = 0; i < n; i++) { 45 | // lld - long long decimal IS IMPORTANT 46 | printf("%lld ", sum_rows[i]); 47 | } 48 | printf("\n"); 49 | 50 | for(int i = 0; i < m; i++) { 51 | // lld - long long decimal IS IMPORTANT 52 | printf("%lld ", sum_cols[i]); 53 | } 54 | printf("\n"); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/src/D_two_dim_array_sum.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define DIM_1_SIZE 3 5 | #define DIM_2_SIZE 5 6 | 7 | int main() { 8 | 9 | uint32_t arr[DIM_1_SIZE][DIM_2_SIZE] = { 10 | {1, 2, 3, 4, 5}, 11 | {2, 3, 4, 5, 6}, 12 | {3, 4, 5, 6, 7}, 13 | }; 14 | // expected output on this data: 15 | // rows sum: 15, 20, 25 16 | // cols sum: 6, 9, 12, 15, 18 17 | 18 | // trivial alg 19 | // iterate each col and count sum, then iterate each row and count sum (or first row and then col) 20 | // opearations count: 2(DIM_1_SIZE*DIM_2_SIZE) 21 | // also col read is bad for perf 22 | 23 | uint32_t sum_rows[DIM_1_SIZE] = {0}; 24 | uint32_t sum_cols[DIM_2_SIZE] = {0}; 25 | 26 | // one-pass alg 27 | for(int i = 0; i < DIM_1_SIZE; i++) { 28 | for(int j = 0; j < DIM_2_SIZE; j++) { 29 | sum_rows[i] += arr[i][j]; 30 | sum_cols[j] += arr[i][j]; 31 | } 32 | } 33 | // if data readed from stdin - no need to fill 2D array at all, can add straight to sum 34 | 35 | printf("rows sum:\n"); 36 | 37 | for(int i = 0; i < DIM_1_SIZE; i++) { 38 | printf("%d ", sum_rows[i]); 39 | } 40 | printf("\n"); 41 | 42 | printf("cols sum:\n"); 43 | 44 | for(int i = 0; i < DIM_2_SIZE; i++) { 45 | printf("%d ", sum_cols[i]); 46 | } 47 | printf("\n"); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/src/addresses_arrays.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ARR_SIZE 10 4 | 5 | int main() { 6 | // Initialize an array 7 | int intArray[ARR_SIZE] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; 8 | 9 | // Print an address of every array element 10 | for (int i = 0; i < ARR_SIZE; i++) { 11 | printf("int array element shift = [%d] - value stored = %d - address = %p\n", i, intArray[i], &intArray[i]); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/src/delete_element_alg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ARR_SIZE 10 4 | 5 | // Function to print an array - it accepts pointer to the array's memory and 6 | // array's size 7 | void printArray(int *arr, int len) { 8 | for (int i = 0; i < len; i++) { 9 | printf("%d ", arr[i]); 10 | } 11 | printf("\n"); 12 | } 13 | 14 | int main() { 15 | // Initialize an array and variables 16 | int array[ARR_SIZE] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 17 | int deleteIndex = 4; 18 | int arrayActualLen = ARR_SIZE; 19 | 20 | // Print the initial array 21 | printf("Initial array:\n"); 22 | printArray(array, ARR_SIZE); 23 | 24 | // Delete element - move affected elements one position left 25 | for (int i = deleteIndex + 1; i < ARR_SIZE; i++) { 26 | array[i - 1] = array[i]; 27 | } 28 | 29 | // Change the array's actual length 30 | arrayActualLen--; 31 | 32 | // Print the resulting array 33 | printf("New array size = %d \n", arrayActualLen); 34 | printf("Array after deleting value at index %d \n", deleteIndex); 35 | printArray(array, arrayActualLen); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/src/find_element_index_alg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ARR_SIZE 10 4 | 5 | // Function to print an array - it accepts pointer to the array's memory and 6 | // array's size 7 | void printArray(int *arr, int len) { 8 | for (int i = 0; i < len; i++) { 9 | printf("%d ", arr[i]); 10 | } 11 | printf("\n"); 12 | } 13 | 14 | int main() { 15 | 16 | // Initialize an array and variables 17 | int array[ARR_SIZE] = {0, 11, 2, 33, 24, 5, 16, 37, 85, 99}; 18 | // Target to find 19 | char elementToFind = 16; 20 | // Variable for resulting index, initialize it to some bad value to check if 21 | // it is changed finally 22 | int indexFound = -1; 23 | 24 | // Print the initial array 25 | printf("Initial array:\n"); 26 | printArray(array, ARR_SIZE); 27 | 28 | // For loop to find the target value 29 | for (int i = 0; i < ARR_SIZE; i++) { 30 | // If target is found - save index and leave 31 | if (array[i] == elementToFind) { 32 | indexFound = i; 33 | break; 34 | } 35 | } 36 | 37 | // If this variable is not changed - element is missing 38 | if (indexFound != -1) { 39 | printf("Element %d is found at index %d \n", elementToFind, indexFound); 40 | } else { 41 | printf("Element %d is not found\n", elementToFind); 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/src/get_element_by_index_perf.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define ARR_SIZE 500000 7 | #define NUM_ITERATIONS_PER_EXPERIMENT 100 8 | 9 | void getElement(int *array, int position) { 10 | // Start clock 11 | clock_t t = clock(); 12 | // Make NUM_ITERATIONS_PER_EXPERIMENT runs to avoid some OS related delays 13 | for (int i = 0; i < NUM_ITERATIONS_PER_EXPERIMENT; i++) { 14 | // Variable where we read the data from the array 15 | int elementValue = 0; 16 | // Read element at the position 17 | // Actually this variable it is not used 18 | // we need it only to read the value and compute total time 19 | elementValue = array[position]; 20 | } 21 | // Finish clock, compute total time spent in seconds 22 | t = clock() - t; 23 | double timeSpent = ((double)t) / CLOCKS_PER_SEC; 24 | printf("Experiment: Read value at index %d. Time of %d runs = %f seconds \n", position, NUM_ITERATIONS_PER_EXPERIMENT, timeSpent); 25 | } 26 | 27 | int main() { 28 | // Variables declaration 29 | int array[ARR_SIZE]; 30 | 31 | // Initialize random seed 32 | srand(999); 33 | 34 | // Fill an array with initial uniformly distributed random values (last 35 | // position is "free") 36 | for (int i = 0; i < ARR_SIZE - 1; i++) { 37 | array[i] = rand(); 38 | } 39 | 40 | // Make 3 reads - 0, middle and last positions 41 | getElement(array, 0); 42 | getElement(array, ARR_SIZE / 2); 43 | getElement(array, ARR_SIZE - 1); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/src/insert_delete_global.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SIZE 350 4 | int n; 5 | 6 | // Solution from Alex Larkov KNT9 7 | 8 | void print(int arr[SIZE]) 9 | { 10 | for (int i = 0; i < n; ++i) 11 | { 12 | printf("%d ", arr[i]); 13 | } 14 | printf("\n"); 15 | } 16 | 17 | void insert(int arr[SIZE], int index, int val) 18 | { 19 | for (int i = n - 1; i >= index; --i) 20 | { 21 | arr[i + 1] = arr[i]; 22 | } 23 | ++n; 24 | arr[index] = val; 25 | } 26 | 27 | void delete(int arr[SIZE], int index) 28 | { 29 | for (int i = index; i < n - 1; ++i) 30 | { 31 | arr[i] = arr[i + 1]; 32 | } 33 | --n; 34 | } 35 | 36 | int main() 37 | { 38 | int arr[SIZE] = {0}; 39 | scanf("%d", &n); 40 | 41 | for (int i = 0; i < n; ++i) 42 | { 43 | scanf("%d", &arr[i]); 44 | } 45 | 46 | int m; 47 | scanf("%d", &m); 48 | 49 | for (int i = 0; i < m; ++i) 50 | { 51 | int t; 52 | scanf("%d", &t); 53 | if (t == 0) 54 | { 55 | int index, val; 56 | scanf("%d%d", &index, &val); 57 | --index; 58 | insert(arr, index, val); 59 | } else 60 | { 61 | int index; 62 | scanf("%d", &index); 63 | --index; 64 | delete(arr, index); 65 | } 66 | print(arr); 67 | } 68 | return 0; 69 | }; -------------------------------------------------------------------------------- /1_arrays_complexity_testing/practice/src/insert_element_alg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ARR_SIZE 11 4 | 5 | // Function to print an array - it accepts pointer to the array's memory and 6 | // array's size 7 | void printArray(int *arr, int len) { 8 | for (int i = 0; i < len; i++) { 9 | printf("%d ", arr[i]); 10 | } 11 | printf("\n"); 12 | } 13 | 14 | int main() { 15 | // Initialize an array and variables - we assume the array has 1 free position 16 | // at the end 17 | int array[ARR_SIZE] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1}; 18 | int insertIndex = 4; 19 | int insertValue = 42; 20 | 21 | // Print the initial array 22 | printf("Initial array:\n"); 23 | printArray(array, ARR_SIZE); 24 | 25 | // Insert element - move affected elements one position right 26 | for (int i = ARR_SIZE - 1; i > insertIndex; i--) { 27 | array[i] = array[i - 1]; 28 | } 29 | // Insert a new value 30 | array[insertIndex] = insertValue; 31 | 32 | // Print the resulting array 33 | printf("Array after inserting value %d at index %d \n", insertValue, insertIndex); 34 | printArray(array, ARR_SIZE); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /2_sorting_simple/lection/images/bubble_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/images/bubble_sort.png -------------------------------------------------------------------------------- /2_sorting_simple/lection/images/bucket_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/images/bucket_sort.png -------------------------------------------------------------------------------- /2_sorting_simple/lection/images/bucket_sort_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/images/bucket_sort_2.png -------------------------------------------------------------------------------- /2_sorting_simple/lection/images/bucket_sort_pseudo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/images/bucket_sort_pseudo.png -------------------------------------------------------------------------------- /2_sorting_simple/lection/images/counting_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/images/counting_sort.png -------------------------------------------------------------------------------- /2_sorting_simple/lection/images/insertion_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/images/insertion_sort.png -------------------------------------------------------------------------------- /2_sorting_simple/lection/images/radix_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/images/radix_sort.png -------------------------------------------------------------------------------- /2_sorting_simple/lection/images/radix_sort_step1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/images/radix_sort_step1.png -------------------------------------------------------------------------------- /2_sorting_simple/lection/images/radix_sort_step2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/images/radix_sort_step2.png -------------------------------------------------------------------------------- /2_sorting_simple/lection/images/radix_sort_step3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/images/radix_sort_step3.png -------------------------------------------------------------------------------- /2_sorting_simple/lection/images/selection_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/images/selection_sort.png -------------------------------------------------------------------------------- /2_sorting_simple/lection/slides/2_sorting_simple.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/slides/2_sorting_simple.pdf -------------------------------------------------------------------------------- /2_sorting_simple/lection/slides/HSE-theme/01_Logo_HSE_full_eng_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/slides/HSE-theme/01_Logo_HSE_full_eng_CMYK.pdf -------------------------------------------------------------------------------- /2_sorting_simple/lection/slides/HSE-theme/01_Logo_HSE_full_rus_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/slides/HSE-theme/01_Logo_HSE_full_rus_CMYK.pdf -------------------------------------------------------------------------------- /2_sorting_simple/lection/slides/HSE-theme/01_Znak_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/lection/slides/HSE-theme/01_Znak_CMYK.pdf -------------------------------------------------------------------------------- /2_sorting_simple/practice/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project("practice") 3 | 4 | set(SRC_PREFIX src) 5 | set(INSTAL_DIR bin) 6 | 7 | add_executable(bubble_sort ${SRC_PREFIX}/bubble_sort.c) 8 | add_executable(bucket_sort ${SRC_PREFIX}/bucket_sort.c) 9 | add_executable(counting_sort ${SRC_PREFIX}/counting_sort.c) 10 | add_executable(insertion_sort ${SRC_PREFIX}/insertion_sort.c) 11 | add_executable(radix_sort ${SRC_PREFIX}/radix_sort.c) 12 | add_executable(selection_sort ${SRC_PREFIX}/selection_sort.c) 13 | 14 | INSTALL( 15 | TARGETS 16 | bubble_sort 17 | bucket_sort 18 | counting_sort 19 | insertion_sort 20 | radix_sort 21 | selection_sort 22 | DESTINATION 23 | ${CMAKE_CURRENT_SOURCE_DIR}/${INSTAL_DIR} 24 | ) 25 | 26 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rdf build 4 | cmake . -Bbuild 5 | cd build 6 | make -j8 7 | make install 8 | cd .. 9 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/0.md: -------------------------------------------------------------------------------- 1 | _Практика 2. Сортировки, часть 1. Рекурсия._ 2 | 3 | # Cекция 0 - Selection Sort. 4 | 5 | ## Цели секции: 6 | 7 | 1. Изучить алгоритм Selection Sort 8 | 9 | ## Характеристики алгоритма 10 | 11 | **Time Complexity**: `O(n^2)` ,as there are two nested loops: 12 | * One loop to select an element of Array one by one = `O(n)` 13 | * Another loop to compare that element with every other Array element = `O(n)` 14 | * Therefore overall complexity = O(n) * O(n) = O(n*n) = `O(n^2)` 15 | 16 | 17 | **Auxiliary Space**: `O(1)` as the only extra memory used is for temporary variables. 18 | 19 | ## Реализация алгоритма 20 | 21 | Исходный код - [selection_sort.c](../src/selection_sort.c) 22 | 23 | ### Исходный код программы: 24 | ![](images/selection_sort_code.png) 25 | 26 | ## Ссылки 27 | 28 | https://www.geeksforgeeks.org/selection-sort-algorithm-2/ 29 | 30 | [plan](../practice.md) | [>](1.md) 31 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/1.md: -------------------------------------------------------------------------------- 1 | _Практика 2. Сортировки, часть 1. Рекурсия._ 2 | 3 | # Cекция 1 - Insertion Sort. 4 | 5 | ## Цели секции: 6 | 7 | 1. Изучить алгоритм Insertion Sort 8 | 9 | ## Характеристики алгоритма 10 | 11 | ### Time Complexity of Insertion Sort 12 | * **Best case**: `O(n)`, If the array is already sorted, where n is the number of elements in the array. 13 | * **Average case**: `O(n^2)`, If the array is randomly ordered 14 | * **Worst case**: `O(n^2)`, If the array is in reverse order 15 | ### Space Complexity of Insertion Sort 16 | **Auxiliary Space**: `O(1)`, Insertion sort requires O(1) additional space, making it a space-efficient sorting algorithm. 17 | 18 | ## Реализация алгоритма 19 | 20 | Исходный код - [insertion_sort.c](../src/insertion_sort.c) 21 | 22 | ### Исходный код программы: 23 | ![](images/insertion_sort_code.png) 24 | 25 | ## Ссылки 26 | 27 | https://www.geeksforgeeks.org/insertion-sort-algorithm/ 28 | 29 | [<](0.md) | [plan](../practice.md) | [>](2.md) 30 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/2.md: -------------------------------------------------------------------------------- 1 | _Практика 2. Сортировки, часть 1. Рекурсия._ 2 | 3 | # Cекция 2 - Bubble Sort. 4 | 5 | ## Цели секции: 6 | 7 | 1. Изучить алгоритм Bubble Sort 8 | 9 | ## Характеристики алгоритма 10 | 11 | **Time Complexity**: `O(n^2)` 12 | 13 | **Auxiliary Space**: `O(1)` 14 | 15 | ## Реализация алгоритма 16 | 17 | Исходный код - [bubble_sort.c](../src/bubble_sort.c) 18 | 19 | ### Исходный код программы: 20 | ![](images/bubble_sort_code.png) 21 | 22 | ## Ссылки 23 | 24 | https://www.geeksforgeeks.org/bubble-sort-algorithm/ 25 | 26 | [<](1.md) | [plan](../practice.md) | [>](3.md) 27 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/3.md: -------------------------------------------------------------------------------- 1 | _Практика 2. Сортировки, часть 1. Рекурсия._ 2 | 3 | # Cекция 3 - Counting Sort. 4 | 5 | ## Цели секции: 6 | 7 | 1. Изучить алгоритм Counting Sort 8 | 9 | ## Характеристики алгоритма 10 | 11 | **Time Complexity**: `O(N+M)`, where N and M are the size of `inputArray[]` and `countArray[]` respectively. 12 | 13 | **Auxiliary Space**: `O(N+M)`, where N and M are the space taken by `outputArray[]` and `countArray[]` respectively. 14 | 15 | ## Реализация алгоритма 16 | 17 | Исходный код - [counting_sort.c](../src/counting_sort.c) 18 | 19 | ### Исходный код программы: 20 | ![](images/counting_sort_code.png) 21 | 22 | ## Ссылки 23 | 24 | https://www.geeksforgeeks.org/counting-sort/ 25 | 26 | [<](2.md) | [plan](../practice.md) | [>](4.md) 27 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/4.md: -------------------------------------------------------------------------------- 1 | _Практика 2. Сортировки, часть 1. Рекурсия._ 2 | 3 | # Cекция 4 - Bucket Sort. 4 | 5 | ## Цели секции: 6 | 7 | 1. Изучить алгоритм Bucket Sort 8 | 9 | ## Характеристики алгоритма 10 | 11 | **Worst Case Time Complexity**: `O(n^2)` 12 | 13 | 14 | **Best Case Time Complexity**: `O(n + k)` 15 | 16 | **Auxiliary Space**: `O(n+k)` 17 | 18 | ## Реализация алгоритма 19 | 20 | Исходный код - [bucket_sort.c](../src/bucket_sort.c) 21 | 22 | ### Исходный код программы: 23 | ![](images/bucket_sort_code.png) 24 | 25 | ### Зависимость скорости работы от bucket count 26 | 27 | ``` 28 | test time 1 bucket 29 | range 0-1000, 10 iterations, executed in 0.232848 seconds 30 | 31 | test time 2 bucket 32 | range 0-1000, 10 iterations, executed in 0.125513 seconds 33 | 34 | test time 4 bucket 35 | range 0-1000, 10 iterations, executed in 0.064828 seconds 36 | ``` 37 | 38 | ## Ссылки 39 | 40 | https://www.geeksforgeeks.org/bucket-sort-2/ 41 | 42 | [<](3.md) | [plan](../practice.md) | [>](5.md) 43 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/5.md: -------------------------------------------------------------------------------- 1 | _Практика 2. Сортировки, часть 1. Рекурсия._ 2 | 3 | # Cекция 5 - Radix Sort. 4 | 5 | ## Цели секции: 6 | 7 | 1. Изучить алгоритм Radix Sort 8 | 9 | ## Характеристики алгоритма 10 | 11 | **Time Complexity**: `O(d * (n + b))`, where `d` is the number of digits, `n` is the number of elements, and `b` is the base of the number system being used. 12 | 13 | **Auxiliary Space**: `O(n + b)`, where `n` is the number of elements and `b` is the base of the number system. 14 | 15 | ## Реализация алгоритма 16 | 17 | Исходный код - [radix_sort.c](../src/radix_sort.c) 18 | 19 | ### Исходный код программы: 20 | ![](images/radix_sort_code.png) 21 | 22 | ## Ссылки 23 | 24 | https://www.geeksforgeeks.org/radix-sort/ 25 | 26 | [<](4.md) | [plan](../practice.md) | [>](6.md) 27 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/6.md: -------------------------------------------------------------------------------- 1 | _Практика 2. Сортировки, часть 1. Рекурсия._ 2 | 3 | # Cекция 6 - Рекурсия. 4 | 5 | ## Цели секции: 6 | 7 | 1. Изучить принципы работы рекурсивных функций 8 | 9 | ## Простой пример 10 | 11 | Исходный код - [recursive_factorial.c](../src/recursive_factorial.c) 12 | 13 | ### Исходный код программы: 14 | ![](images/recursive_factorial_code.png) 15 | 16 | ## Стек вызова 17 | 18 | Исходный код - [recursive_callstack.c](../src/recursive_callstack.c) 19 | 20 | ### Исходный код программы: 21 | ![](images/recursive_callstack_code.png) 22 | 23 | ### Стек вызова функций: 24 | ![](images/recursion.jpg) 25 | 26 | ## Ссылки 27 | 28 | * https://www.geeksforgeeks.org/introduction-to-recursion-2/ 29 | * https://habr.com/ru/articles/337030/ 30 | 31 | 32 | [<](5.md) | [plan](../practice.md) 33 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/images/bubble_sort_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/practice/md/images/bubble_sort_code.png -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/images/bucket_sort_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/practice/md/images/bucket_sort_code.png -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/images/counting_sort_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/practice/md/images/counting_sort_code.png -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/images/insertion_sort_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/practice/md/images/insertion_sort_code.png -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/images/radix_sort_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/practice/md/images/radix_sort_code.png -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/images/recursion.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/practice/md/images/recursion.jpg -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/images/recursive_callstack_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/practice/md/images/recursive_callstack_code.png -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/images/recursive_factorial_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/practice/md/images/recursive_factorial_code.png -------------------------------------------------------------------------------- /2_sorting_simple/practice/md/images/selection_sort_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/2_sorting_simple/practice/md/images/selection_sort_code.png -------------------------------------------------------------------------------- /2_sorting_simple/practice/practice.md: -------------------------------------------------------------------------------- 1 | # Практика 2. Сортировки, часть 1. Рекурсия. 2 | 3 | ## План практики 4 | 5 | ### Секция 0 - [Selection Sort.](md/0.md) 6 | ### Секция 1 - [Insertion Sort.](md/1.md) 7 | ### Секция 2 - [Bubble Sort.](md/2.md) 8 | ### Секция 3 - [Counting Sort.](md/3.md) 9 | ### Секция 4 - [Bucket Sort.](md/4.md) 10 | ### Секция 5 - [Radix Sort.](md/5.md) 11 | ### Секция 6 - [Рекурсия.](md/6.md) 12 | 13 | [к оглавлению](../../TOC.md) 14 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/src/bubble_sort.c: -------------------------------------------------------------------------------- 1 | // Optimized implementation of Bubble sort 2 | #include 3 | #include 4 | 5 | void swap(int* xp, int* yp){ 6 | int temp = *xp; 7 | *xp = *yp; 8 | *yp = temp; 9 | } 10 | 11 | // An optimized version of Bubble Sort 12 | void bubbleSort(int arr[], int n){ 13 | int i, j; 14 | bool swapped; 15 | for (i = 0; i < n - 1; i++) { 16 | swapped = false; 17 | for (j = 0; j < n - i - 1; j++) { 18 | if (arr[j] > arr[j + 1]) { 19 | swap(&arr[j], &arr[j + 1]); 20 | swapped = true; 21 | } 22 | } 23 | 24 | // If no two elements were swapped by inner loop, 25 | // then break 26 | if (swapped == false) 27 | break; 28 | } 29 | } 30 | 31 | // Function to print an array 32 | void printArray(int arr[], int size){ 33 | int i; 34 | for (i = 0; i < size; i++) 35 | printf("%d ", arr[i]); 36 | } 37 | 38 | int main(){ 39 | int arr[] = { 64, 34, 25, 12, 22, 11, 90 }; 40 | int n = sizeof(arr) / sizeof(arr[0]); 41 | bubbleSort(arr, n); 42 | printf("Sorted array: \n"); 43 | printArray(arr, n); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/src/counting_sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void countingSort(int* arr, int n) { 5 | 6 | int maxEl = arr[0]; 7 | 8 | for (int i = 1; i < n; ++i) { 9 | if (arr[i] > maxEl) { 10 | maxEl = arr[i]; 11 | } 12 | } 13 | 14 | int* countArr = (int*)calloc((maxEl + 1), sizeof(arr[0])); 15 | int* output = (int*)calloc(n, sizeof(arr[0])); 16 | 17 | for(int i = 0; i < n; ++i) { 18 | ++countArr[arr[i]]; 19 | } 20 | 21 | int j = 0; 22 | 23 | for (int i = 0; i < maxEl + 1; ++i) { 24 | while (countArr[i] != 0) { 25 | output[j] = i; 26 | countArr[i]--; 27 | j++; 28 | } 29 | } 30 | 31 | for (int i = 0; i < 10; ++i) { 32 | arr[i] = output[i]; 33 | } 34 | 35 | free(output); 36 | free(countArr); 37 | } 38 | 39 | void printArray(int arr[], int n) 40 | { 41 | for (int i = 0; i < n; ++i) 42 | printf("%d ", arr[i]); 43 | printf("\n"); 44 | } 45 | 46 | int main(void) 47 | { 48 | int* a = (int*)calloc(10, sizeof(int)); 49 | for (int i = 9; i >= 0; i--) { 50 | a[10-i] = i; 51 | } 52 | 53 | countingSort(a, 10); 54 | 55 | printArray(a, sizeof(a) / sizeof(a[0])); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/src/insertion_sort.c: -------------------------------------------------------------------------------- 1 | // C program for implementation of Insertion Sort 2 | #include 3 | 4 | /* Function to sort array using insertion sort */ 5 | void insertionSort(int arr[], int n) 6 | { 7 | for (int i = 1; i < n; ++i) { 8 | int key = arr[i]; 9 | int j = i - 1; 10 | 11 | /* Move elements of arr[0..i-1], that are 12 | greater than key, to one position ahead 13 | of their current position */ 14 | while (j >= 0 && arr[j] > key) { 15 | arr[j + 1] = arr[j]; 16 | j = j - 1; 17 | } 18 | arr[j + 1] = key; 19 | } 20 | } 21 | 22 | /* A utility function to print array of size n */ 23 | void printArray(int arr[], int n) 24 | { 25 | for (int i = 0; i < n; ++i) 26 | printf("%d ", arr[i]); 27 | printf("\n"); 28 | } 29 | 30 | // Driver method 31 | int main() 32 | { 33 | int arr[] = { 12, 11, 13, 5, 6 }; 34 | int n = sizeof(arr) / sizeof(arr[0]); 35 | 36 | insertionSort(arr, n); 37 | printArray(arr, n); 38 | 39 | return 0; 40 | } 41 | 42 | /* This code is contributed by Hritik Shah. */ 43 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/src/recursive_callstack.c: -------------------------------------------------------------------------------- 1 | // A C program to demonstrate working of recursion 2 | #include 3 | 4 | void printFun(int test) 5 | { 6 | if (test < 1) 7 | return; 8 | else { 9 | printf("%d ", test); 10 | printFun(test - 1); 11 | printf("%d ", test); 12 | return; 13 | } 14 | } 15 | 16 | // Driver Code 17 | int main() 18 | { 19 | int test = 3; 20 | printFun(test); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/src/recursive_factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fact(int n) { 4 | 5 | // BASE CONDITION 6 | if (n == 0 || n == 1) 7 | return 1; 8 | 9 | return n * fact(n - 1); 10 | } 11 | 12 | int main() { 13 | printf("Factorial of 5 : %d\n", fact(5)); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /2_sorting_simple/practice/src/selection_sort.c: -------------------------------------------------------------------------------- 1 | // C program for implementation of selection sort 2 | #include 3 | 4 | void selectionSort(int arr[], int n) { 5 | for (int i = 0; i < n - 1; i++) { 6 | 7 | // Assume the current position holds 8 | // the minimum element 9 | int min_idx = i; 10 | 11 | // Iterate through the unsorted portion 12 | // to find the actual minimum 13 | for (int j = i + 1; j < n; j++) { 14 | if (arr[j] < arr[min_idx]) { 15 | 16 | // Update min_idx if a smaller element is found 17 | min_idx = j; 18 | } 19 | } 20 | 21 | // Move minimum element to its 22 | // correct position 23 | int temp = arr[i]; 24 | arr[i] = arr[min_idx]; 25 | arr[min_idx] = temp; 26 | } 27 | } 28 | 29 | void printArray(int arr[], int n) { 30 | for (int i = 0; i < n; i++) { 31 | printf("%d ", arr[i]); 32 | } 33 | printf("\n"); 34 | } 35 | 36 | int main() { 37 | int arr[] = {64, 25, 12, 22, 11}; 38 | int n = sizeof(arr) / sizeof(arr[0]); 39 | 40 | printf("Original array: "); 41 | printArray(arr, n); 42 | 43 | selectionSort(arr, n); 44 | 45 | printf("Sorted array: "); 46 | printArray(arr, n); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/bubble_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/bubble_sort.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/bucket_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/bucket_sort.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/bucket_sort_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/bucket_sort_2.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/bucket_sort_pseudo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/bucket_sort_pseudo.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/compare_based_proof.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/compare_based_proof.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/compare_based_tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/compare_based_tree.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/compare_based_tree_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/compare_based_tree_2.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/counting_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/counting_sort.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/insertion_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/insertion_sort.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/merge_accesses.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/merge_accesses.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/merge_already_sorted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/merge_already_sorted.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/merge_compares_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/merge_compares_1.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/merge_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/merge_example.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/merge_extra_space.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/merge_extra_space.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/merge_insertion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/merge_insertion.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/merge_insertion_full.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/merge_insertion_full.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/merge_iterative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/merge_iterative.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/merge_merge_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/merge_merge_1.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/merge_merge_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/merge_merge_2.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/merge_recursive_main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/merge_recursive_main.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/qs_common.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/qs_common.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/qs_complexity_cases.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/qs_complexity_cases.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/qs_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/qs_example.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/qs_example.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/qs_example.tif -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/qs_hoare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/qs_hoare.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/qs_lomuto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/qs_lomuto.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/qs_lomuto_pseudo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/qs_lomuto_pseudo.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/qs_main_pseudo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/qs_main_pseudo.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/qs_pseudo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/qs_pseudo.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/qselect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/qselect.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/radix_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/radix_sort.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/radix_sort_step1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/radix_sort_step1.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/radix_sort_step2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/radix_sort_step2.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/radix_sort_step3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/radix_sort_step3.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/selection_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/selection_sort.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/stability_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/stability_example.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/stability_insertion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/stability_insertion.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/stability_merge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/stability_merge.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/stability_qs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/stability_qs.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/stability_selection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/stability_selection.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/summary_all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/summary_all.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/images/summary_sedgewick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/images/summary_sedgewick.png -------------------------------------------------------------------------------- /3_sorting_recursion/lection/slides/3_sorting_recursion.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/slides/3_sorting_recursion.pdf -------------------------------------------------------------------------------- /3_sorting_recursion/lection/slides/HSE-theme/01_Logo_HSE_full_eng_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/slides/HSE-theme/01_Logo_HSE_full_eng_CMYK.pdf -------------------------------------------------------------------------------- /3_sorting_recursion/lection/slides/HSE-theme/01_Logo_HSE_full_rus_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/slides/HSE-theme/01_Logo_HSE_full_rus_CMYK.pdf -------------------------------------------------------------------------------- /3_sorting_recursion/lection/slides/HSE-theme/01_Znak_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/lection/slides/HSE-theme/01_Znak_CMYK.pdf -------------------------------------------------------------------------------- /3_sorting_recursion/practice/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project("practice") 3 | 4 | set(SRC_PREFIX src) 5 | set(INSTAL_DIR bin) 6 | 7 | add_executable(merge_sort ${SRC_PREFIX}/merge_sort.c) 8 | add_executable(nth_element ${SRC_PREFIX}/nth_element.c) 9 | add_executable(qsort_hoar ${SRC_PREFIX}/qsort_hoar.c) 10 | add_executable(qsort_lomuto ${SRC_PREFIX}/qsort_lomuto.c) 11 | add_executable(req_1_to_n ${SRC_PREFIX}/req_1_to_n.c) 12 | add_executable(req_a_to_b ${SRC_PREFIX}/req_a_to_b.c) 13 | add_executable(req_check_pwr_2 ${SRC_PREFIX}/req_check_pwr_2.c) 14 | add_executable(req_num_ones ${SRC_PREFIX}/req_num_ones.c) 15 | add_executable(req_rotate_digits ${SRC_PREFIX}/req_rotate_digits.c) 16 | add_executable(req_sum_digits ${SRC_PREFIX}/req_sum_digits.c) 17 | add_executable(req_sum_digits ${SRC_PREFIX}/tim_sort.c) 18 | 19 | INSTALL( 20 | TARGETS 21 | merge_sort 22 | nth_element 23 | qsort_hoar 24 | qsort_lomuto 25 | req_1_to_n 26 | req_a_to_b 27 | req_check_pwr_2 28 | req_num_ones 29 | req_rotate_digits 30 | req_sum_digits 31 | tim_sort 32 | DESTINATION 33 | ${CMAKE_CURRENT_SOURCE_DIR}/${INSTAL_DIR} 34 | ) 35 | 36 | -------------------------------------------------------------------------------- /3_sorting_recursion/practice/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rdf build 4 | cmake . -Bbuild 5 | cd build 6 | make -j8 7 | make install 8 | cd .. 9 | -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/1.md: -------------------------------------------------------------------------------- 1 | _Практика 3. Сортировки, часть 2. Рекурсия._ 2 | 3 | # Cекция 1 - Merge Sort. 4 | 5 | ## Цели секции: 6 | 7 | 1. Изучить алгоритм Merge Sort 8 | 9 | ## Характеристики алгоритма 10 | 11 | ### Time Complexity of Merge Sort 12 | * **Best case**: `O(n log n)`, When the array is already sorted or nearly sorted. 13 | * **Average case**: `O(n log n)`, When the array is randomly ordered. 14 | * **Worst case**: `O(n log n)`, When the array is sorted in reverse order. 15 | ### Space Complexity of Merge Sort 16 | **Auxiliary Space**: `O(n)`, Additional space is required for the temporary array used during merging. 17 | 18 | ## Реализация алгоритма 19 | 20 | Исходный код - [merge_sort.c](../src/merge_sort.c) 21 | 22 | ### Исходный код программы: 23 | ![](images/merge_sort_code.png) 24 | 25 | ## Ссылки 26 | 27 | https://www.geeksforgeeks.org/merge-sort/ 28 | 29 | [<](0.md) | [plan](../practice.md) | [>](2.md) 30 | -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/2.md: -------------------------------------------------------------------------------- 1 | _Практика 3. Сортировки, часть 2. Рекурсия._ 2 | 3 | # Cекция 2 - Quick Sort. 4 | 5 | ## Цели секции: 6 | 7 | 1. Изучить алгоритм Quick Sort 8 | 2. Изучить Lomuto partition 9 | 2. Изучить Hoar partition 10 | 11 | ## Характеристики алгоритма 12 | 13 | Характеристики алгоритма зависят от выбранного разделения. 14 | 15 | ## Реализация алгоритма 16 | ### Исходный код программы: 17 | 18 | ![](images/qsort_generic_code.png) 19 | 20 | ## Lomuto partition 21 | 22 | ### Характеристики алгоритма 23 | * **Time Complexity**: `O(n)` 24 | * **Auxiliary Space**: `O(1)` 25 | 26 | ### Реализация алгоритма 27 | 28 | Исходный код - [qsort_lomuto.c](../src/qsort_lomuto.c) 29 | 30 | ### Исходный код программы: 31 | ![](images/qsort_lomuto_code.png) 32 | 33 | ## Hoar partition 34 | 35 | ### Характеристики алгоритма 36 | * **Time Complexity**: `O(n)` 37 | * **Auxiliary Space**: `O(1)` 38 | 39 | ### Реализация алгоритма 40 | 41 | Исходный код - [qsort_hoar.c](../src/qsort_hoar.c) 42 | 43 | ### Исходный код программы: 44 | ![](images/qsort_hoar_code.png) 45 | 46 | ## Ссылки 47 | 48 | * https://www.geeksforgeeks.org/quick-sort-algorithm/ 49 | * https://www.geeksforgeeks.org/lomuto-partition-algorithm/ 50 | * https://www.geeksforgeeks.org/hoare-s-partition-algorithm/ 51 | 52 | [<](1.md) | [plan](../practice.md) | [>](3.md) 53 | -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/4.md: -------------------------------------------------------------------------------- 1 | _Практика 3. Сортировки, часть 2. Рекурсия._ 2 | 3 | # Cекция 4 - Nth element. 4 | 5 | ## Цели секции: 6 | 7 | 1. Изучить алгоритм Nth element 8 | 9 | ## Характеристики алгоритма 10 | 11 | Данный алгоритм может быть реализован различными путями. В рамках данной практики рассматривается реализация на основе `qsort`. Существуют реализации на основе `introselect` ("introspective selection"), но они сложны для понимания. 12 | 13 | * **Time Complexity**: `O(n)` 14 | * **Auxiliary Space**: `O(1)` 15 | 16 | Ассимтотическая сложность алгоритма совпадает с `qsort`, но на практике данный алгоритм будет работать быстрее, чем `qsort`. 17 | 18 | ## Реализация алгоритма 19 | 20 | Исходный код - [nth_element.c](../src/nth_element.c) 21 | 22 | ### Исходный код программы: 23 | ![](images/nth_element_code.png) 24 | 25 | ### Результат выполнения программы: 26 | ![](images/nth_element_out.png) 27 | 28 | ## Ссылки 29 | 30 | * https://www.geeksforgeeks.org/stdnth_element-in-cpp/ 31 | * https://en.wikipedia.org/wiki/Introselect 32 | 33 | [<](3.md) | [plan](../practice.md) 34 | -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/images/merge_sort_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/practice/md/images/merge_sort_code.png -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/images/nth_element_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/practice/md/images/nth_element_code.png -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/images/nth_element_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/practice/md/images/nth_element_out.png -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/images/qsort_generic_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/practice/md/images/qsort_generic_code.png -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/images/qsort_hoar_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/practice/md/images/qsort_hoar_code.png -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/images/qsort_lomuto_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/practice/md/images/qsort_lomuto_code.png -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/images/req_1_to_n_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/practice/md/images/req_1_to_n_code.png -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/images/req_a_to_b_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/practice/md/images/req_a_to_b_code.png -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/images/req_check_pwr_2_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/practice/md/images/req_check_pwr_2_code.png -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/images/req_num_ones_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/practice/md/images/req_num_ones_code.png -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/images/req_rotate_digits_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/practice/md/images/req_rotate_digits_code.png -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/images/req_sum_digits_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/practice/md/images/req_sum_digits_code.png -------------------------------------------------------------------------------- /3_sorting_recursion/practice/md/images/timsort_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/3_sorting_recursion/practice/md/images/timsort_code.png -------------------------------------------------------------------------------- /3_sorting_recursion/practice/practice.md: -------------------------------------------------------------------------------- 1 | # Сортировки, часть 2. Рекурсия. 2 | 3 | ## План практики 4 | 5 | ### Секция 0 - [Простые задачи с использованием рекурсии.](md/0.md) 6 | ### Секция 1 - [Merge Sort.](md/1.md) 7 | ### Секция 2 - [Quick Sort.](md/2.md) 8 | ### Секция 3 - [Tim Sort.](md/3.md) 9 | ### Секция 4 - [Nth element.](md/4.md) 10 | 11 | [к оглавлению](../../TOC.md) 12 | -------------------------------------------------------------------------------- /3_sorting_recursion/practice/src/req_1_to_n.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void print_1_to_n(int n) { 4 | if (n == 0) { 5 | return; 6 | } 7 | 8 | print_1_to_n(n - 1); 9 | 10 | printf("%d ", n); 11 | } 12 | 13 | int main() { 14 | print_1_to_n(10); 15 | printf("\n"); 16 | } 17 | -------------------------------------------------------------------------------- /3_sorting_recursion/practice/src/req_a_to_b.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void print_a_to_b(int a, int b) { 4 | if (a == b) { 5 | 6 | printf("%d ", a); 7 | 8 | return; 9 | } 10 | 11 | if (a > b) 12 | { 13 | print_a_to_b(a - 1, b); 14 | 15 | printf("%d ", a); 16 | } else { 17 | 18 | print_a_to_b(a + 1, b); 19 | 20 | printf("%d ", a); 21 | } 22 | } 23 | 24 | int main() { 25 | print_a_to_b(10, 2); 26 | printf("\n"); 27 | print_a_to_b(2, 8); 28 | printf("\n"); 29 | } 30 | -------------------------------------------------------------------------------- /3_sorting_recursion/practice/src/req_check_pwr_2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int req_check_pwr_2(float n) { 4 | if (n == 1) { 5 | 6 | return 1; 7 | } 8 | 9 | if (n > 1 && n < 2) { 10 | return 0; 11 | } 12 | 13 | return req_check_pwr_2(n / 2); 14 | } 15 | 16 | int main() { 17 | printf("is %f a power of 2 = %d\n", 31.0, req_check_pwr_2(31)); 18 | printf("is %f a power of 2 = %d\n", 32.0, req_check_pwr_2(32)); 19 | } 20 | -------------------------------------------------------------------------------- /3_sorting_recursion/practice/src/req_num_ones.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int req_num_ones(int* arr, int len, int index) { 4 | if(len == index) { 5 | return 0; 6 | } 7 | 8 | if(arr[index] == 1) { 9 | return 1 + req_num_ones(arr, len, index + 1); 10 | } else { 11 | return 0 + req_num_ones(arr, len, index + 1); 12 | } 13 | } 14 | 15 | int main() { 16 | int arr[] = {1, 2, 3, 1, 1, 5, 6, 12}; 17 | 18 | printf("%d\n", req_num_ones(arr, sizeof(arr)/sizeof(arr[1]), 0)); 19 | } 20 | -------------------------------------------------------------------------------- /3_sorting_recursion/practice/src/req_rotate_digits.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int req_rotate_digits(int num, int rotated) { 4 | if(num == 0) { 5 | return rotated; 6 | } 7 | 8 | return (req_rotate_digits(num / 10, rotated * 10 + num % 10)); 9 | } 10 | 11 | int main() { 12 | 13 | printf("%d\n", req_rotate_digits(123, 0)); 14 | } 15 | -------------------------------------------------------------------------------- /3_sorting_recursion/practice/src/req_sum_digits.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int req_sim_digits(int num) { 4 | if(num == 0) { 5 | return 0; 6 | } 7 | 8 | return num % 10 + (req_sim_digits(num / 10)); 9 | } 10 | 11 | int main() { 12 | 13 | printf("%d\n", req_sim_digits(123)); 14 | } 15 | -------------------------------------------------------------------------------- /4_search/lection/images/bs_iterative_c_impl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/bs_iterative_c_impl.png -------------------------------------------------------------------------------- /4_search/lection/images/bs_pseudo_iter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/bs_pseudo_iter.png -------------------------------------------------------------------------------- /4_search/lection/images/bs_rec_tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/bs_rec_tree.png -------------------------------------------------------------------------------- /4_search/lection/images/bs_recursive_c_impl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/bs_recursive_c_impl.png -------------------------------------------------------------------------------- /4_search/lection/images/doubling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/doubling.png -------------------------------------------------------------------------------- /4_search/lection/images/doubling_complexity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/doubling_complexity.png -------------------------------------------------------------------------------- /4_search/lection/images/doubling_pseudo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/doubling_pseudo.png -------------------------------------------------------------------------------- /4_search/lection/images/interpolation_formula.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/interpolation_formula.png -------------------------------------------------------------------------------- /4_search/lection/images/interpolation_pseudo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/interpolation_pseudo.png -------------------------------------------------------------------------------- /4_search/lection/images/jump_search.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/jump_search.jpg -------------------------------------------------------------------------------- /4_search/lection/images/linear_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/linear_search.png -------------------------------------------------------------------------------- /4_search/lection/images/monsters_meme.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/monsters_meme.jpg -------------------------------------------------------------------------------- /4_search/lection/images/ternary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/ternary.png -------------------------------------------------------------------------------- /4_search/lection/images/ternary_iterative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/ternary_iterative.png -------------------------------------------------------------------------------- /4_search/lection/images/ternary_recursive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/images/ternary_recursive.png -------------------------------------------------------------------------------- /4_search/lection/slides/4_search.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/slides/4_search.pdf -------------------------------------------------------------------------------- /4_search/lection/slides/HSE-theme/01_Logo_HSE_full_eng_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/slides/HSE-theme/01_Logo_HSE_full_eng_CMYK.pdf -------------------------------------------------------------------------------- /4_search/lection/slides/HSE-theme/01_Logo_HSE_full_rus_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/slides/HSE-theme/01_Logo_HSE_full_rus_CMYK.pdf -------------------------------------------------------------------------------- /4_search/lection/slides/HSE-theme/01_Znak_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/lection/slides/HSE-theme/01_Znak_CMYK.pdf -------------------------------------------------------------------------------- /4_search/practice/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project("practice") 3 | 4 | set(SRC_PREFIX src) 5 | set(INSTAL_DIR bin) 6 | 7 | add_executable(benchmark ${SRC_PREFIX}/benchmark.c) 8 | add_executable(binary_search ${SRC_PREFIX}/binary_search.c) 9 | add_executable(exponential_search ${SRC_PREFIX}/exponential_search.c) 10 | add_executable(interpolation_search ${SRC_PREFIX}/interpolation_search.c) 11 | add_executable(jump_search ${SRC_PREFIX}/jump_search.c) 12 | add_executable(linear_search ${SRC_PREFIX}/linear_search.c) 13 | add_executable(ternary_search ${SRC_PREFIX}/ternary_search.c) 14 | add_executable(ternary_search_for_unimodal_func ${SRC_PREFIX}/ternary_search_for_unimodal_func.c) 15 | 16 | target_link_libraries(benchmark m) 17 | target_link_libraries(jump_search m) 18 | 19 | INSTALL( 20 | TARGETS 21 | benchmark 22 | binary_search 23 | exponential_search 24 | interpolation_search 25 | jump_search 26 | linear_search 27 | ternary_search 28 | ternary_search_for_unimodal_func 29 | DESTINATION 30 | ${CMAKE_CURRENT_SOURCE_DIR}/${INSTAL_DIR} 31 | ) 32 | 33 | -------------------------------------------------------------------------------- /4_search/practice/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rdf build 4 | cmake . -Bbuild 5 | cd build 6 | make -j8 7 | make install 8 | cd .. 9 | -------------------------------------------------------------------------------- /4_search/practice/md/0.md: -------------------------------------------------------------------------------- 1 | _Практика 4. Поиск элемента в массиве._ 2 | 3 | # Cекция 0 - Linear search. Jump search. 4 | 5 | ## Linear search 6 | 7 | Исходный код - [linear_search.c](../src/linear_search.c) 8 | 9 | ### Исходный код программы: 10 | ![](images/linear_search_code.png) 11 | 12 | ## Jump search 13 | 14 | Исходный код - [jump_search.c](../src/jump_search.c) 15 | 16 | ### Исходный код программы: 17 | ![](images/jump_search_code.png) 18 | 19 | [plan](../practice.md) | [>](1.md) 20 | -------------------------------------------------------------------------------- /4_search/practice/md/1.md: -------------------------------------------------------------------------------- 1 | _Практика 4. Поиск элемента в массиве._ 2 | 3 | # Cекция 1 - Binary search. Ternary search. 4 | 5 | ## Binary search 6 | 7 | Исходный код - [binary_search.c](../src/binary_search.c) 8 | 9 | ### Исходный код программы: 10 | ![](images/binary_search_code.png) 11 | 12 | ## Ternary search 13 | 14 | Исходный код - [ternary_search.c](../src/ternary_search.c) 15 | 16 | ### Исходный код программы: 17 | ![](images/ternary_search_code.png) 18 | 19 | [<](0.md) | [plan](../practice.md) | [>](2.md) 20 | -------------------------------------------------------------------------------- /4_search/practice/md/2.md: -------------------------------------------------------------------------------- 1 | _Практика 4. Поиск элемента в массиве._ 2 | 3 | # Cекция 2 - Exponential search. 4 | 5 | ## Exponential search 6 | 7 | Исходный код - [exponential_search.c](../src/exponential_search.c) 8 | 9 | ### Исходный код программы: 10 | ![](images/exponential_search_code.png) 11 | 12 | [<](1.md) | [plan](../practice.md) | [>](3.md) 13 | -------------------------------------------------------------------------------- /4_search/practice/md/3.md: -------------------------------------------------------------------------------- 1 | _Практика 4. Поиск элемента в массиве._ 2 | 3 | # Cекция 3 - Interpolation search. 4 | 5 | ## Interpolation search 6 | 7 | Исходный код - [interpolation_search.c](../src/interpolation_search.c) 8 | 9 | ### Исходный код программы: 10 | ![](images/interpolation_search_code.png) 11 | 12 | [<](2.md) | [plan](../practice.md) | [>](4.md) 13 | -------------------------------------------------------------------------------- /4_search/practice/md/5.md: -------------------------------------------------------------------------------- 1 | _Практика 4. Поиск элемента в массиве._ 2 | 3 | # Задача 0 - Формулировка задачи. 4 | 5 | Команда программистов пишет код. Для упрощения работы каждому изменению в коде присваивается порядкойвый номер, позволяющий однозначно идентифицировать это изменение. Будем называть такой порядковый номер ревизией. 6 | 7 | Имеется несколько ревизий кода, последовательно пронумерованных от `0` до `n`. В ревизии кода под номером `k` была допущена ошибка, такая, что любая ревизия из `[k .. n]` работает неправильно. Для любой ревизии кода можно однозначно сказать работает она правильно, или нет. Необходимо найти ревизию `k`, выполнив наименьшее количество проверок. 8 | 9 | ## Пример 10 | 11 | ### Номера ревизий кода: 12 | ``` 13 | 0 1 2 3 4 5 6 14 | ``` 15 | 16 | ### Результаты проверок 17 | 18 | ``` 19 | 0 1 2 3 4 5 6 20 | OK OK OK FAIL FAIL FAIL FAIL 21 | ``` 22 | 23 | ### Ответ 24 | `k` = 3, так как все ревизии в `[0 .. 2]` работают, токгда как все ревизии в `[3 .. 6]` не работают. 25 | 26 | [<](4.md) | [plan](../practice.md) | [>](6.md) 27 | -------------------------------------------------------------------------------- /4_search/practice/md/6.md: -------------------------------------------------------------------------------- 1 | _Практика 4. Поиск элемента в массиве._ 2 | 3 | # Задача 0 - Решение. 4 | 5 | Для решения этой задачи удобнее всего использовать алгоритм бинарного поиска по ответу. 6 | 7 | Стоит отметить, что условие задачи моделирует реальные ситуации, которые могут встречаться при разработке программного обеспечения. Существуют т.н. системы контроля версий, позволяющие присваивать ревизии изменениям в коде. Одна из самых популярных систем контроля версий - `git`. В этой системе контроля версий поиск ревизии кода с ошибкой может быть осуществлён с помощью команды `bisect`. 8 | 9 | [<](5.md) | [plan](../practice.md) | [>](7.md) 10 | -------------------------------------------------------------------------------- /4_search/practice/md/7.md: -------------------------------------------------------------------------------- 1 | _Практика 4. Поиск элемента в массиве._ 2 | 3 | # Задача 1 - Формулировка задачи. 4 | 5 | Дан массив `arr` длинной `len`, в котором есть элемент с индексом `k`, такой, что: 6 | * для любого `i` в `[0 .. k]` `arr[i] < arr[i + 1]` 7 | * для любого `j` в `[k .. len - 1]` `arr[j] > arr[j + 1]` 8 | 9 | Найти `k`. 10 | 11 | ## Пример 12 | 13 | ### Фрагмент массива около индекса с максимальным элементом 14 | 15 | ``` 16 | index: ... 679 680 681 682 683 ... 17 | value: ... 721 722 723 360 359 ... 18 | ``` 19 | 20 | ### Ответ 21 | 22 | `k` = 681 23 | 24 | [<](6.md) | [plan](../practice.md) | [>](8.md) 25 | -------------------------------------------------------------------------------- /4_search/practice/md/8.md: -------------------------------------------------------------------------------- 1 | _Практика 4. Поиск элемента в массиве._ 2 | 3 | # Задача 1 - Решение. 4 | 5 | Формулировка данной задачи является упрощением задачи о поиске экстремума унимодальной функции одной переменной. Данную задачу можно решить с помощью тернатрного поиска. 6 | 7 | Исходный код - [ternary_search_for_unimodal_func.c](../src/ternary_search_for_unimodal_func.c) 8 | 9 | ### Исходный код программы: 10 | ![](images/ternary_search_for_unimodal_func_code.png) 11 | 12 | [<](7.md) | [plan](../practice.md) 13 | -------------------------------------------------------------------------------- /4_search/practice/md/images/binary_search_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/practice/md/images/binary_search_code.png -------------------------------------------------------------------------------- /4_search/practice/md/images/exponential_search_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/practice/md/images/exponential_search_code.png -------------------------------------------------------------------------------- /4_search/practice/md/images/interpolation_search_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/practice/md/images/interpolation_search_code.png -------------------------------------------------------------------------------- /4_search/practice/md/images/jump_search_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/practice/md/images/jump_search_code.png -------------------------------------------------------------------------------- /4_search/practice/md/images/linear_search_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/practice/md/images/linear_search_code.png -------------------------------------------------------------------------------- /4_search/practice/md/images/ternary_search_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/practice/md/images/ternary_search_code.png -------------------------------------------------------------------------------- /4_search/practice/md/images/ternary_search_for_unimodal_func_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/4_search/practice/md/images/ternary_search_for_unimodal_func_code.png -------------------------------------------------------------------------------- /4_search/practice/practice.md: -------------------------------------------------------------------------------- 1 | # Практика 4. Поиск элемента в массиве. 2 | 3 | ## План практики 4 | 5 | ### Секция 0 - [Linear search. Jump search.](md/0.md) 6 | ### Секция 1 - [Binary search. Ternary search.](md/1.md) 7 | ### Секция 2 - [Exponential search.](md/2.md) 8 | ### Секция 3 - [Interpolation search.](md/3.md) 9 | ### Секция 4 - [Сравнение производительности алгоритмов.](md/4.md) 10 | ### Задача 0 - [Формулировка задачи.](md/5.md) 11 | ### Задача 0 - [Решение.](md/6.md) 12 | ### Задача 1 - [Формулировка задачи.](md/7.md) 13 | ### Задача 1 - [Решение.](md/8.md) 14 | 15 | [к оглавлению](../../TOC.md) 16 | -------------------------------------------------------------------------------- /4_search/practice/src/binary_search.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ARR_SIZE 1000 4 | 5 | int binary_search(int* array, int size, int item_to_find) { 6 | int l = 0; 7 | int r = size - 1; 8 | while (l <= r) { 9 | int m = l + (r - l) / 2; 10 | // Check if x is present at mid 11 | if (array[m] == item_to_find) { 12 | return m; 13 | } 14 | // If x greater, ignore left half 15 | if (array[m] < item_to_find) { 16 | l = m + 1; 17 | } 18 | // If x is smaller, ignore right half 19 | else { 20 | r = m - 1; 21 | } 22 | } 23 | 24 | // If we reach here, then element was not present 25 | return -1; 26 | } 27 | 28 | int main() { 29 | int arr[ARR_SIZE]; 30 | 31 | for (size_t i = 0; i < ARR_SIZE; i++) 32 | { 33 | arr[i] = i; 34 | } 35 | 36 | int element = 831; 37 | int index = binary_search(arr, ARR_SIZE, element); 38 | 39 | printf("Found element %d at index %d\n", element, index); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /4_search/practice/src/interpolation_search.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ARR_SIZE 1000 4 | 5 | int interpolation_search(int* arr, int n, int x) 6 | { 7 | // Find indexes of two corners 8 | int low = 0, high = (n - 1); 9 | // Since array is sorted, an element present 10 | // in array must be in range defined by corner 11 | while (low <= high && x >= arr[low] && x <= arr[high]) 12 | { 13 | if (low == high) { 14 | if (arr[low] == x) { 15 | return low; 16 | } else { 17 | return -1; 18 | } 19 | } 20 | // Probing the position with keeping 21 | // uniform distribution in mind. 22 | int pos = low + (((double)(high - low) / 23 | (arr[high] - arr[low])) * (x - arr[low])); 24 | 25 | // Condition of target found 26 | if (arr[pos] == x) 27 | return pos; 28 | // If x is larger, x is in upper part 29 | if (arr[pos] < x) { 30 | low = pos + 1; 31 | } 32 | // If x is smaller, x is in the lower part 33 | else { 34 | high = pos - 1; 35 | } 36 | } 37 | return -1; 38 | } 39 | 40 | int main() { 41 | int arr[ARR_SIZE]; 42 | 43 | for (size_t i = 0; i < ARR_SIZE; i++) 44 | { 45 | arr[i] = i; 46 | } 47 | 48 | int element = 831; 49 | int index = interpolation_search(arr, ARR_SIZE, element); 50 | 51 | printf("Found element %d at index %d\n", element, index); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /4_search/practice/src/jump_search.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define ARR_SIZE 1000 5 | 6 | int jump_search(int* a, int n, int item) { 7 | int i = 0; 8 | int m = sqrt(n); //initializing block size= √(n) 9 | 10 | while(a[m] <= item && m < n) { 11 | // the control will continue to jump the blocks 12 | i = m; // shift the block 13 | m += sqrt(n); 14 | if(m > n - 1) // if m exceeds the array size 15 | return -1; 16 | } 17 | 18 | for(int x = i; x 2 | 3 | #define ARR_SIZE 1000 4 | 5 | int linear_search(int* array, int n, int x) { 6 | 7 | for (int i = 0; i < n; i++) 8 | if (array[i] == x) { 9 | return i; 10 | } 11 | return -1; 12 | } 13 | 14 | int main() { 15 | int arr[ARR_SIZE]; 16 | 17 | for (size_t i = 0; i < ARR_SIZE; i++) 18 | { 19 | arr[i] = i; 20 | } 21 | 22 | int element = 831; 23 | int index = linear_search(arr, ARR_SIZE, element); 24 | 25 | printf("Found element %d at index %d\n", element, index); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/ll_circular_variant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/ll_circular_variant.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/ll_doubly_complexity_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/ll_doubly_complexity_table.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/ll_doubly_variant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/ll_doubly_variant.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/ll_node_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/ll_node_code.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/ll_node_create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/ll_node_create.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/ll_pros_cons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/ll_pros_cons.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/ll_single.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/ll_single.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/ll_single_variant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/ll_single_variant.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/ll_singly_complexity_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/ll_singly_complexity_table.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/ll_traverse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/ll_traverse.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/queue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/queue.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/queue_array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/queue_array.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/queue_array_create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/queue_array_create.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/queue_array_enqueue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/queue_array_enqueue.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/queue_complexity_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/queue_complexity_table.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/queue_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/queue_example.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/queue_ll.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/queue_ll.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/stack.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/stack_arrays.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/stack_arrays.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/stack_complexity_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/stack_complexity_table.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/stack_empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/stack_empty.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/stack_full.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/stack_full.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/stack_ll.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/stack_ll.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/stack_ll_picture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/stack_ll_picture.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/stack_peek.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/stack_peek.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/stack_pop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/stack_pop.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/stack_push.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/stack_push.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/images/stack_usage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/images/stack_usage.png -------------------------------------------------------------------------------- /5_simple_data_structures/lection/slides/5_simple_data_structures.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/slides/5_simple_data_structures.pdf -------------------------------------------------------------------------------- /5_simple_data_structures/lection/slides/HSE-theme/01_Logo_HSE_full_eng_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/slides/HSE-theme/01_Logo_HSE_full_eng_CMYK.pdf -------------------------------------------------------------------------------- /5_simple_data_structures/lection/slides/HSE-theme/01_Logo_HSE_full_rus_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/slides/HSE-theme/01_Logo_HSE_full_rus_CMYK.pdf -------------------------------------------------------------------------------- /5_simple_data_structures/lection/slides/HSE-theme/01_Znak_CMYK.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/lection/slides/HSE-theme/01_Znak_CMYK.pdf -------------------------------------------------------------------------------- /5_simple_data_structures/practice/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project("practice") 3 | 4 | set(SRC_PREFIX src) 5 | set(INSTAL_DIR bin) 6 | 7 | add_executable(array_queue ${SRC_PREFIX}/array_queue.c) 8 | add_executable(array_stack ${SRC_PREFIX}/array_stack.c) 9 | add_executable(linked_list ${SRC_PREFIX}/linked_list.c) 10 | add_executable(list_queue ${SRC_PREFIX}/list_queue.c) 11 | add_executable(list_stack ${SRC_PREFIX}/list_stack.c) 12 | 13 | INSTALL( 14 | TARGETS 15 | array_queue 16 | array_stack 17 | linked_list 18 | list_queue 19 | list_stack 20 | DESTINATION 21 | ${CMAKE_CURRENT_SOURCE_DIR}/${INSTAL_DIR} 22 | ) 23 | -------------------------------------------------------------------------------- /5_simple_data_structures/practice/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rdf build 4 | cmake . -Bbuild 5 | cd build 6 | make -j8 7 | make install 8 | cd .. 9 | -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/0.md: -------------------------------------------------------------------------------- 1 | _Практика 5. Простые структуры данных._ 2 | 3 | # Секция 0 - Linked list. 4 | 5 | Исходный код - [linked_list.c](../src/linked_list.c) 6 | 7 | ### Структура данных: 8 | ![](images/linked_list_data_structures_code.png) 9 | 10 | ### Создание и удаление списка: 11 | ![](images/linked_list_create_delete_code.png) 12 | 13 | ### Добавление элемента в начало и конец списка: 14 | ![](images/linked_list_add_code.png) 15 | 16 | ### Поиск элемента в списке: 17 | ![](images/linked_list_search_code.png) 18 | 19 | ### Удаление элемента: 20 | ![](images/linked_list_delete_element_code.png) 21 | 22 | ### Добавление элемента после произвольного элемента в списке: 23 | ![](images/linked_list_add_after_before_code.png) 24 | 25 | [plan](../practice.md) | [>](1.md) 26 | -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/1.md: -------------------------------------------------------------------------------- 1 | _Практика 5. Простые структуры данных._ 2 | 3 | # Секция 1 - Stack. 4 | 5 | Исходный код - [stack.c](../src/list_stack.c) 6 | 7 | ### Исходный код программы: 8 | ![](images/stack_code.png) 9 | 10 | [<](0.md) | [plan](../practice.md) | [>](2.md) 11 | -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/2.md: -------------------------------------------------------------------------------- 1 | _Практика 5. Простые структуры данных._ 2 | 3 | # Секция 2 - Queue. 4 | 5 | Исходный код - [queue.c](../src/list_queue.c) 6 | 7 | ### Исходный код программы: 8 | ![](images/queue_code.png) 9 | 10 | [<](1.md) | [plan](../practice.md) | [>](3.md) 11 | -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/3.md: -------------------------------------------------------------------------------- 1 | _Практика 5. Простые структуры данных._ 2 | 3 | # Задача 0 - Формулировка задачи. 4 | 5 | Проверить парвильность расстановки скобок в строке. 6 | 7 | *пример правильных строк* 8 | ``` 9 | ()()()[][]{()} 10 | ((())){{}}[{}] 11 | ``` 12 | 13 | *пример неправильных строк* 14 | ``` 15 | {[)} 16 | }{)( 17 | ``` 18 | 19 | [<](2.md) | [plan](../practice.md) | [>](4.md) 20 | -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/4.md: -------------------------------------------------------------------------------- 1 | _Практика 5. Простые структуры данных._ 2 | 3 | # Задача 0 - Решение. 4 | 5 | Для решения этой задачи можно использовать стек. 6 | 7 | Алгоритм решения задачи: 8 | * идём по строке, записываем в стек открывающие скобки 9 | * при встрече в строке закрывающей скобки - достаём из стека скобку, проверяем совпадает ли закрывающая скобка с открывающей 10 | * при несовпадении - есть ошибка в последовательности скобок 11 | * при совпадении - продолжаем идти по строке 12 | 13 | [<](3.md) | [plan](../practice.md) | [>](5.md) 14 | -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/5.md: -------------------------------------------------------------------------------- 1 | _Практика 5. Простые структуры данных._ 2 | 3 | # Задача 1 - Формулировка задачи. 4 | 5 | Вычислить результат математического выражения. Математическое выражение дано в виде строки. 6 | 7 | **Допустимые символы**: основные бинарные операторы +, -, *, /; скобки (), цифры 0-9. 8 | 9 | [<](4.md) | [plan](../practice.md) | [>](6.md) 10 | -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/images/linked_list_add_after_before_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/practice/md/images/linked_list_add_after_before_code.png -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/images/linked_list_add_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/practice/md/images/linked_list_add_code.png -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/images/linked_list_create_delete_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/practice/md/images/linked_list_create_delete_code.png -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/images/linked_list_data_structures_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/practice/md/images/linked_list_data_structures_code.png -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/images/linked_list_delete_element_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/practice/md/images/linked_list_delete_element_code.png -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/images/linked_list_search_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/practice/md/images/linked_list_search_code.png -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/images/queue_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/practice/md/images/queue_code.png -------------------------------------------------------------------------------- /5_simple_data_structures/practice/md/images/stack_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/5_simple_data_structures/practice/md/images/stack_code.png -------------------------------------------------------------------------------- /5_simple_data_structures/practice/practice.md: -------------------------------------------------------------------------------- 1 | # Практика 5. Простые структуры данных. 2 | 3 | ## План практики 4 | 5 | ### Секция 0 - [Linked list.](md/0.md) 6 | ### Секция 1 - [Stack.](md/1.md) 7 | ### Секция 2 - [Queue.](md/2.md) 8 | ### Задача 0 - [Формулировка задачи.](md/3.md) 9 | ### Задача 0 - [Решение.](md/4.md) 10 | ### Задача 1 - [Формулировка задачи.](md/5.md) 11 | ### Задача 1 - [Решение.](md/6.md) 12 | 13 | [к оглавлению](../../TOC.md) 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # About 2 | Repository for Algorithms and Data Structures course (HSE Nizhny Novgorod). 3 | 4 | # Course content 5 | 6 | [Table of content](TOC.md) 7 | 8 | # How to run practice code examples 9 | 10 | All sources are placed in `src` directory in practice folder - for example in `0_intro/src`. 11 | 12 | ## Simple way 13 | 14 | Use online gcc compiler - https://www.onlinegdb.com/online_c_compiler. Just copy and paste source code and press run. 15 | 16 | ## Hard way 17 | 18 | All code for practice developed on WSL with following environment: 19 | ``` 20 | Ubuntu 20.04.4 LTS 21 | gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 22 | cmake version 3.16.3 23 | ``` 24 | 25 | You can install WSL on your Windows pc (or just install gcc and cmake if you use Linux or Mac) and run script `build.sh` in practice folder - for example in `0_intro/practice`. After this all example binaries will be placed into `bin` folder and you can run it. 26 | 27 | ### WSL and tools installation instructions 28 | 29 | Google it! Or use simple way. 30 | 31 | # Acknowledgements 32 | 33 | Special thanks goes to: 34 | 35 | Maksim Zakharov @FLTLN https://github.com/FLTLN 36 | 37 | Yuriy Magus @theMagusDev https://github.com/theMagusDev 38 | 39 | Vadim @vadyukkha https://github.com/vadyukkha 40 | 41 | # Links 42 | ## Notes from Yuriy Magus 43 | https://yuriymagus.notion.site/HSE-Algorithms-and-data-structures-dcb628e674874c3aa0e6e01f593c25b9 44 | 45 | ## Algorithms visualization tools 46 | * [Simple](https://visualgo.net/en) 47 | * [Complicated but more detailed](https://algorithm-visualizer.org/) -------------------------------------------------------------------------------- /TOC.md: -------------------------------------------------------------------------------- 1 | ## Неделя 0 2 | ### Заметки - [Алгоритмы, задачи, вычислительные машины.](0_intro/lection/0_0_plan.md) 3 | 4 | ### Слайды- [Алгоритмы, задачи, вычислительные машины.](0_intro/lection/slides/0_introduction.pdf) 5 | 6 | ### Практика - [Трансляция, переменные, типы данных, битовые операции.](0_intro/practice/practice.md) 7 | 8 | ## Неделя 1 9 | ### Заметки - [Алгоритмы, задачи, вычислительные машины.](1_arrays_complexity_testing/lection/1_0_plan.md) 10 | 11 | ### Слайды- [Алгоритмы, задачи, вычислительные машины.](1_arrays_complexity_testing/lection/slides/1_arrays_complexity_testing.pdf) 12 | 13 | ### Практика - [Тестирование. Работа с массивами.](1_arrays_complexity_testing/practice/practice.md) 14 | 15 | ## Неделя 2 16 | 17 | ### Практика - [Сортировки, часть 1. Рекурсия.](2_sorting_simple/practice/practice.md) 18 | 19 | ## Неделя 3 20 | 21 | ### Практика - [Сортировки, часть 2. Рекурсия.](3_sorting_recursion/practice/practice.md) 22 | 23 | ## Неделя 4 24 | 25 | ### Практика - [Поиск элемента в массиве.](4_search/practice/practice.md) 26 | 27 | ## Неделя 5 28 | 29 | ### Практика - [Простые структуры данных.](5_simple_data_structures/practice/practice.md) -------------------------------------------------------------------------------- /config/carbon_source_config.json: -------------------------------------------------------------------------------- 1 | {"paddingVertical":"0px","paddingHorizontal":"0px","backgroundImage":null,"backgroundImageSelection":null,"backgroundMode":"color","backgroundColor":"rgba(255,255,255,1)","dropShadow":true,"dropShadowOffsetY":"18px","dropShadowBlurRadius":"68px","theme":"one-light","windowTheme":"boxy","language":"auto","fontFamily":"Source Code Pro","fontSize":"18px","lineHeight":"143%","windowControls":true,"widthAdjustment":false,"lineNumbers":true,"firstLineNumber":1,"exportSize":"2x","watermark":false,"squaredImage":false,"hiddenCharacters":false,"name":"","width":800,"highlights":null} -------------------------------------------------------------------------------- /config/presets/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rdf build 4 | cmake . -Bbuild 5 | cd build 6 | make -j8 7 | make install 8 | cd .. 9 | -------------------------------------------------------------------------------- /generate_build_scripts.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import os 3 | import shutil 4 | 5 | parser = argparse.ArgumentParser() 6 | 7 | 8 | parser.add_argument("dir") 9 | args = parser.parse_args() 10 | 11 | dir_path = os.path.dirname(os.path.realpath(__file__)) 12 | 13 | work_dir = os.path.join(dir_path, args.dir) 14 | src_dir = os.path.join(work_dir, "src") 15 | 16 | srcs = os.listdir(src_dir) 17 | 18 | 19 | with open(os.path.join(work_dir, "CMakeLists.txt"), "w") as file: 20 | 21 | file.write("cmake_minimum_required(VERSION 3.16)\n") 22 | file.write('project("practice")\n') 23 | file.write("\n") 24 | file.write("set(SRC_PREFIX src)\n") 25 | file.write("set(INSTAL_DIR bin)\n") 26 | file.write("\n") 27 | 28 | for src in srcs: 29 | file.write("add_executable(" + src.split(".")[0] + " " + "${SRC_PREFIX}"+"/{src}".format(src = src) + ")\n") 30 | 31 | file.write("\n") 32 | file.write("INSTALL(\n") 33 | file.write(" TARGETS\n") 34 | 35 | for src in srcs: 36 | file.write(" " + src.split(".")[0] + "\n") 37 | 38 | file.write(" DESTINATION\n") 39 | file.write(" ${CMAKE_CURRENT_SOURCE_DIR}/${INSTAL_DIR}\n") 40 | file.write(")\n") 41 | file.write("\n") 42 | 43 | shutil.copyfile(os.path.join(dir_path, "config/presets/build.sh"), os.path.join(work_dir, "build.sh")) -------------------------------------------------------------------------------- /generate_practice_md.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import os 3 | 4 | # сейчас работает только как генератор навигации 5 | # коглда решу проблему с энкодингом - обучу генерить оглавление 6 | 7 | parser = argparse.ArgumentParser() 8 | 9 | 10 | parser.add_argument("dir") 11 | parser.add_argument('--add_nav', action=argparse.BooleanOptionalAction, default=False) 12 | 13 | args = parser.parse_args() 14 | 15 | dir_path = os.path.dirname(os.path.realpath(__file__)) 16 | 17 | work_dir = os.path.join(dir_path, args.dir) 18 | md_dir = os.path.join(work_dir, "md") 19 | 20 | mds = os.listdir(md_dir) 21 | 22 | mds = list(filter(lambda x: "md" in x, mds)) 23 | 24 | mds.sort(key = lambda x: int(x.split(".")[0])) 25 | 26 | print(mds) 27 | 28 | print(args.add_nav) 29 | 30 | for md in mds: 31 | print(md) 32 | 33 | if args.add_nav: 34 | index = int(md.split(".")[0]) 35 | 36 | nav_line = "" 37 | 38 | prev_md = "{}.md".format(index - 1) 39 | next_md = "{}.md".format(index + 1) 40 | 41 | if prev_md in mds: 42 | nav_line = nav_line + "[<]({})".format(prev_md) + " | " 43 | 44 | nav_line = nav_line + "[plan](../practice.md)" 45 | 46 | if next_md in mds: 47 | nav_line = nav_line + " | [>]({})".format(next_md) 48 | 49 | with open(os.path.join(md_dir, md), "a") as file: 50 | file.write("\n") 51 | file.write(nav_line) 52 | file.write("\n") 53 | -------------------------------------------------------------------------------- /links.md: -------------------------------------------------------------------------------- 1 | Princeton introduction to CS course: 2 | https://introcs.cs.princeton.edu/java/lectures/ -------------------------------------------------------------------------------- /old/lections/0_intro+arrays.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/old/lections/0_intro+arrays.pptx -------------------------------------------------------------------------------- /old/lections/1_types_arrays_complexity.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/old/lections/1_types_arrays_complexity.pptx -------------------------------------------------------------------------------- /old/lections/2_sorts.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/old/lections/2_sorts.pptx -------------------------------------------------------------------------------- /old/lections/3.5_cryptography_101.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/old/lections/3.5_cryptography_101.pptx -------------------------------------------------------------------------------- /old/lections/3_number_theory.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/old/lections/3_number_theory.pptx -------------------------------------------------------------------------------- /old/lections/4_data_structures_1.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/old/lections/4_data_structures_1.pptx -------------------------------------------------------------------------------- /old/lections/5_data_structures_2.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/old/lections/5_data_structures_2.pptx -------------------------------------------------------------------------------- /old/practice/10_graphs/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help 2 | 3 | all: adjacency_list adjacency_matrix edges_list # Build all targets 4 | 5 | help: # Show help for each of the Makefile recipes. 6 | @printf "\n" 7 | @grep -E '^[a-z].*:.*' Makefile | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done 8 | @printf "\n" 9 | 10 | adjacency_list: adjacency_list.c # Build adjacency list based graph 11 | gcc adjacency_list.c -o adjacency_list 12 | 13 | adjacency_matrix: adjacency_matrix.c # Build adjacency matrix based graph 14 | gcc adjacency_matrix.c -o adjacency_matrix 15 | 16 | edges_list: edges_list.c # Build edges list based graph 17 | gcc edges_list.c -o edges_list 18 | 19 | clean: # Delete all builded files 20 | rm -f adjacency_list adjacency_matrix edges_list 21 | -------------------------------------------------------------------------------- /old/practice/11_graph_path/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help 2 | 3 | all: dijkstra # Build all targets 4 | 5 | help: # Show help for each of the Makefile recipes. 6 | @printf "\n" 7 | @grep -E '^[a-z].*:.*' Makefile | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done 8 | @printf "\n" 9 | 10 | dijkstra: graph.c dijkstra.c # Build Dijkstra algorithm 11 | gcc graph.c dijkstra.c -o dijkstra 12 | 13 | bellman_ford: graph.c bellman_ford.c # Build Bellman–Ford algorithm 14 | gcc graph.c bellman_ford.c -o bellman_ford 15 | 16 | floyd_warshall: graph.c floyd_warshall.c # Build Floyd–Warshall algorithm 17 | gcc graph.c floyd_warshall.c -o floyd_warshall 18 | 19 | clean: # Delete all builded files 20 | rm -f dijkstra 21 | -------------------------------------------------------------------------------- /old/practice/11_graph_path/bellman_ford: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/old/practice/11_graph_path/bellman_ford -------------------------------------------------------------------------------- /old/practice/11_graph_path/dijkstra: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/old/practice/11_graph_path/dijkstra -------------------------------------------------------------------------------- /old/practice/11_graph_path/floyd_warshall: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/il-bychkov/algorithms_course/f3a54dd919ce287e2ae5268c04af1813335f6a15/old/practice/11_graph_path/floyd_warshall -------------------------------------------------------------------------------- /old/practice/11_graph_path/graph.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPH_H 2 | #define GRAPH_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | typedef enum graph_order { 11 | ordered, 12 | unordered 13 | } graph_order_r; 14 | 15 | typedef struct graph { 16 | int8_t* matrix; 17 | size_t n_vertices; 18 | graph_order_r order; 19 | } graph_t; 20 | 21 | void new_graph(graph_t* graph, size_t n_vertices, graph_order_r order); 22 | void delete_graph(graph_t* graph); 23 | 24 | int add_edge(graph_t* graph, size_t from, size_t to, int8_t weight); 25 | bool is_ajacend(graph_t* graph, size_t from, size_t to); 26 | int8_t get_distance(graph_t* graph, size_t from, size_t to); 27 | void print_graph(graph_t* graph); 28 | 29 | typedef struct path_set { 30 | size_t* previous; 31 | int8_t* distanse; 32 | size_t n_vertices; 33 | size_t path_start; 34 | } path_set_t; 35 | 36 | void new_path_set(path_set_t* path_set, size_t n_vertices); 37 | void delete_path_set(path_set_t* path_set); 38 | void print_path_set(path_set_t* path_set); 39 | 40 | #endif // GRAPH_H 41 | -------------------------------------------------------------------------------- /old/practice/12_graph_MST/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help 2 | 3 | all: kruskal prima # Build all targets 4 | 5 | help: # Show help for each of the Makefile recipes. 6 | @printf "\n" 7 | @grep -E '^[a-z].*:.*' Makefile | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done 8 | @printf "\n" 9 | 10 | kruskal: kruskal.cpp 11 | g++ -std=c++20 kruskal.cpp -o kruskal 12 | 13 | prima: prima.cpp 14 | g++ -std=c++20 prima.cpp -o prima 15 | 16 | clean: # Delete all builded files 17 | rm -f kruskal prima 18 | -------------------------------------------------------------------------------- /old/practice/12_two_pointers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (CMAKE_CXX_STANDARD 11) 2 | 3 | add_executable( 4 | sum_of_two 5 | sum_of_two.cc 6 | ) 7 | 8 | add_executable( 9 | most_close 10 | most_close.cc 11 | ) 12 | 13 | add_executable( 14 | min_k_sum 15 | min_k_sum.cc 16 | ) -------------------------------------------------------------------------------- /old/practice/12_two_pointers/Readme.md: -------------------------------------------------------------------------------- 1 | Для билда: 2 | ``` 3 | mkdir build && cd build 4 | cmake .. 5 | make 6 | ``` -------------------------------------------------------------------------------- /old/practice/12_two_pointers/min_k_sum.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int GetMinKSum(const std::vector& a, int sum_threshold) { 6 | size_t i = 0; // pointer to 'sum sequence' start 7 | size_t j = 0; // pointer to 'sum sequence' end 8 | 9 | int sum = 0; 10 | int min_seq_len = INT_MAX; 11 | for (i = 0; i < a.size(); ++i) { 12 | // we continue the summarization from same spot, no return to back 13 | while (j < a.size() && sum <= sum_threshold) { 14 | sum += a[j]; 15 | ++j; 16 | } 17 | // task condition 18 | if (sum > sum_threshold) { 19 | int seq_len = j - i; 20 | // save min sequence length 21 | if (seq_len < min_seq_len) { 22 | std::cout << "Saving new seq: sum=" << sum << "|seq_len=" << seq_len << "|i=" << i << "|j=" << j << "\n"; 23 | min_seq_len = seq_len; 24 | } 25 | } else { 26 | // we exited the 'while' upper loop because of the end of array; no more steps needed 27 | break; 28 | } 29 | // remove first element of 'sum sequence' as we move sequence start pointer further 30 | sum -= a[i]; 31 | } 32 | 33 | return min_seq_len; 34 | } 35 | 36 | 37 | int main() { 38 | std::vector a {1, 2, 3, 4, 5}; 39 | int target = 4; 40 | auto res = GetMinKSum(a, target); 41 | std::cout << "Min seq.len for sum > [" << target << "] = " << res << "\n"; 42 | } -------------------------------------------------------------------------------- /old/practice/12_two_pointers/sum_of_two.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | std::pair SumOfTwo(const std::vector& a, int target) { 6 | size_t i = 0; // left pointer 7 | size_t j = a.size() - 1; // right pointer 8 | 9 | // till the left and right pointers meeting 10 | while (i < j) 11 | { 12 | // condition of task 13 | int current_sum = a[i] + a[j]; 14 | if (current_sum == target) { 15 | return {i, j}; 16 | } else if (current_sum < target) { 17 | // increase left pointer to increase sum (numbers are bigger on right side) 18 | ++i; 19 | } else { 20 | // decrease rigth pointer to decrease sum (numbers are smaller on left side) 21 | --j; 22 | } 23 | } 24 | 25 | // no condition 26 | return {-1, -1}; 27 | } 28 | 29 | 30 | int main() { 31 | std::vector numbers {1, 2, 4, 8, 16}; 32 | 33 | int target1 = 10; 34 | auto res1 = SumOfTwo(numbers, target1); 35 | std::cout << "Target = " << target1 << ": " << res1.first << " " << res1.second << '\n'; 36 | 37 | int target2 = 9; 38 | auto res2 = SumOfTwo(numbers, target2); 39 | std::cout << "Target = " << target2 << ": " << res2.first << " " << res2.second << '\n'; 40 | 41 | int target3 = 13; 42 | auto res3 = SumOfTwo(numbers, target3); 43 | std::cout << "Target = " << target3 << ": " << res3.first << " " << res3.second << '\n'; 44 | } -------------------------------------------------------------------------------- /old/practice/13_substr/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help 2 | 3 | all: substr # Build all targets 4 | 5 | help: # Show help for each of the Makefile recipes. 6 | @printf "\n" 7 | @grep -E '^[a-z].*:.*' Makefile | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done 8 | @printf "\n" 9 | 10 | substr: naive.c rabin_karp.c kmp.c main.c # Build all 11 | gcc naive.c rabin_karp.c kmp.c main.c -o substr 12 | 13 | clean: # Delete all builded files 14 | rm -f substr 15 | -------------------------------------------------------------------------------- /old/practice/13_substr/kmp.c: -------------------------------------------------------------------------------- 1 | #include "substr.h" 2 | 3 | size_t substr_kmp(char* str, size_t str_len, char* substr, size_t substr_len) { 4 | 5 | size_t* pi = malloc(substr_len * sizeof(size_t)); 6 | pi[0] = 0; 7 | 8 | size_t l; 9 | 10 | for (l = 1; l < substr_len - 1; l++) { 11 | size_t j = pi[l-1]; 12 | while ((j > 0) && (substr[l] != substr[j])) { 13 | j = pi[j-1]; 14 | } 15 | 16 | if (substr[l] == substr[j]) { 17 | ++j; 18 | } 19 | 20 | pi[l] = j; 21 | } 22 | 23 | size_t j = 0; 24 | 25 | for (size_t i = 0; i < str_len; i++) { 26 | while ((j > 0) && (str[i] != substr[j])) { 27 | j = pi[j-1]; 28 | } 29 | 30 | if (str[i] == substr[j]) { 31 | j++; 32 | } 33 | 34 | if (j==l) { 35 | free(pi); 36 | return i - l + 1; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /old/practice/13_substr/main.c: -------------------------------------------------------------------------------- 1 | #include "substr.h" 2 | 3 | void print_part(char* str, size_t start, size_t len) { 4 | for (size_t i = start; i < start + len; i++) { 5 | printf("%c", str[i]); 6 | } 7 | printf("\n"); 8 | } 9 | 10 | int main() { 11 | 12 | char str[] = "aaaaa sssssssubstring string sub aaaaaa"; 13 | char substr[] = "substring"; 14 | 15 | size_t index_naive = substr_naive(str, sizeof(str)/sizeof(str[0]), substr, sizeof(substr)/sizeof(substr[0])); 16 | size_t index_rabin_karp = substr_rabin_karp(str, sizeof(str)/sizeof(str[0]), substr, sizeof(substr)/sizeof(substr[0])); 17 | size_t index_kmp = substr_kmp(str, sizeof(str)/sizeof(str[0]), substr, sizeof(substr)/sizeof(substr[0])); 18 | 19 | printf("naive:\n"); 20 | print_part(str, index_naive, sizeof(substr)/sizeof(substr[0])); 21 | printf("Rabin-Karp:\n"); 22 | print_part(str, index_rabin_karp, sizeof(substr)/sizeof(substr[0])); 23 | printf("Knuth-Morris-Pratt:\n"); 24 | print_part(str, index_kmp, sizeof(substr)/sizeof(substr[0])); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /old/practice/13_substr/naive.c: -------------------------------------------------------------------------------- 1 | #include "substr.h" 2 | 3 | size_t substr_naive(char* str, size_t str_len, char* substr, size_t substr_len) { 4 | 5 | if (substr_len > str_len || !str || !substr) { 6 | return str_len+1; 7 | } 8 | 9 | 10 | for (size_t i = 0; i < str_len - substr_len; i++) { 11 | 12 | size_t substr_index = 0; 13 | 14 | while (str[i + substr_index] == substr[substr_index]) { 15 | substr_index++; 16 | } 17 | 18 | if(substr_index + 1 == substr_len) { 19 | return i; 20 | } 21 | } 22 | 23 | return str_len+1; 24 | } 25 | -------------------------------------------------------------------------------- /old/practice/13_substr/rabin_karp.c: -------------------------------------------------------------------------------- 1 | #include "substr.h" 2 | 3 | size_t substr_rabin_karp(char* str, size_t str_len, char* substr, size_t substr_len) { 4 | 5 | if (substr_len > str_len || !str || !substr) { 6 | return str_len+1; 7 | } 8 | 9 | size_t hash_substr = 0; 10 | 11 | for (size_t i = 0; i < substr_len - 1; i++) { 12 | hash_substr += (size_t)substr[i]; 13 | } 14 | 15 | for (size_t i = 0; i < str_len - substr_len; i++) { 16 | 17 | size_t hash_str = 0; 18 | 19 | for (size_t j = 0; j < substr_len - 1; j++) { 20 | hash_str += (size_t)str[j + i]; 21 | } 22 | 23 | if (hash_substr == hash_str) { 24 | bool is_match = true; 25 | 26 | for (size_t j = 0; j < substr_len - 1; j++) { 27 | is_match = str[j + i] == substr[j]; 28 | } 29 | 30 | if (is_match) { 31 | return i; 32 | } 33 | 34 | } 35 | 36 | } 37 | 38 | return str_len+1; 39 | } 40 | -------------------------------------------------------------------------------- /old/practice/13_substr/substr.h: -------------------------------------------------------------------------------- 1 | #ifndef SUBSTR_H 2 | #define SUBSTR_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | size_t substr_naive(char* str, size_t str_len, char* substr, size_t substr_len); 11 | size_t substr_rabin_karp(char* str, size_t str_len, char* substr, size_t substr_len); 12 | size_t substr_kmp(char* str, size_t str_len, char* substr, size_t substr_len); 13 | 14 | #endif // SUBSTR_H 15 | -------------------------------------------------------------------------------- /old/practice/15_dynamic/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help 2 | 3 | all: knapsack_unbounded knapsack_0_1 lcm # Build all targets 4 | 5 | help: # Show help for each of the Makefile recipes. 6 | @printf "\n" 7 | @grep -E '^[a-z].*:.*' Makefile | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done 8 | @printf "\n" 9 | 10 | knapsack_unbounded: knapsack_unbounded.c # Build knapsack_unbounded 11 | gcc knapsack_unbounded.c -o knapsack_unbounded 12 | 13 | knapsack_0_1: knapsack_0_1.c # Build knapsack_0_1 14 | gcc knapsack_0_1.c -o knapsack_0_1 15 | 16 | lcm: lcm.c # Build lcm 17 | gcc lcm.c -o lcm 18 | 19 | clean: # Delete all builded files 20 | rm -f knapsack_unbounded knapsack_0_1 lcm 21 | -------------------------------------------------------------------------------- /old/practice/15_dynamic/knapsack.h: -------------------------------------------------------------------------------- 1 | #ifndef KNAPSACK_H 2 | #define KNAPSACK_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | typedef struct item { 11 | uint32_t w; // weight 12 | uint32_t v; // value 13 | } item_t; 14 | 15 | #define max(a,b) (((a) > (b)) ? (a) : (b)) 16 | 17 | #endif // KNAPSACK_H 18 | -------------------------------------------------------------------------------- /old/practice/15_dynamic/knapsack_0_1.c: -------------------------------------------------------------------------------- 1 | #include "knapsack.h" 2 | 3 | // based on https://algocode.ru/page/c-8-knapsack/ 4 | 5 | void knapsack_unbounded(item_t* items, size_t n, size_t W) { 6 | 7 | size_t* m = malloc(sizeof(size_t) * (n + 1) * (W + 1)); 8 | 9 | for (size_t j = 0; j < W + 1; j++) { 10 | m[j] = 0; 11 | } 12 | 13 | for (size_t i = 1; i < n + 1; i++) { 14 | for (size_t j = 0; j < W + 1; j++) { 15 | m[i * W + j] = m[(i - 1) * W + j]; 16 | 17 | if (items[i].w <= j ) { 18 | m[i * W + j] = max(m[i * W + j], m[(i - 1) * W + j - items[i].w] + items[i].v); 19 | } 20 | } 21 | } 22 | 23 | for (size_t i = 0; i < n; i++) { 24 | for (size_t j = 0; j < W; j++) { 25 | printf("%4ld ", m[i * W + j]); 26 | } 27 | printf("\n"); 28 | } 29 | 30 | free(m); 31 | 32 | } 33 | 34 | int main() { 35 | 36 | item_t items[] = { 37 | {2, 2}, 38 | {2, 3}, 39 | {4, 10}, 40 | {3, 5}, 41 | }; 42 | 43 | knapsack_unbounded(items, sizeof(items) / sizeof(item_t), 10); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /old/practice/15_dynamic/knapsack_unbounded.c: -------------------------------------------------------------------------------- 1 | #include "knapsack.h" 2 | 3 | // based on https://algocode.ru/page/c-8-knapsack/ 4 | 5 | void knapsack_unbounded(item_t* items, size_t n, size_t W) { 6 | 7 | size_t* m = malloc(sizeof(size_t) * (n + 1) * (W + 1)); 8 | 9 | for (size_t j = 0; j < W + 1; j++) { 10 | m[j] = 0; 11 | 12 | if (items[0].w <= j ) { 13 | m[j] = max(m[j], m[j - items[0].w] + items[0].v); 14 | } 15 | } 16 | 17 | for (size_t i = 1; i < n + 1; i++) { 18 | for (size_t j = 0; j < W + 1; j++) { 19 | m[i * W + j] = m[(i - 1) * W + j]; 20 | 21 | if (items[i].w <= j ) { 22 | m[i * W + j] = max(m[i * W + j], m[i * W + j - items[i].w] + items[i].v); 23 | } 24 | } 25 | } 26 | 27 | for (size_t i = 0; i < n; i++) { 28 | for (size_t j = 0; j < W; j++) { 29 | printf("%4ld ", m[i * W + j]); 30 | } 31 | printf("\n"); 32 | } 33 | 34 | free(m); 35 | 36 | } 37 | 38 | int main() { 39 | 40 | item_t items[] = { 41 | {2, 2}, 42 | {2, 3}, 43 | {4, 10}, 44 | {4, 5}, 45 | }; 46 | 47 | knapsack_unbounded(items, sizeof(items) / sizeof(item_t), 12); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /old/practice/2_sorting/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help 2 | 3 | all: utility_demo counting_sort bucket_sort qsort # Build all targets 4 | 5 | help: # Show help for each of the Makefile recipes. 6 | @printf "\n" 7 | @grep -E '^[a-z].*:.*' Makefile | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done 8 | @printf "\n" 9 | 10 | utility_demo: sorting.c utility_demo.c # Build avaliable utilities demo 11 | gcc sorting.c utility_demo.c -o utility_demo 12 | 13 | counting_sort: sorting.c counting_sort.c # Build counting sort implementation 14 | gcc sorting.c counting_sort.c -o counting_sort 15 | 16 | bucket_sort: sorting.c bucket_sort.c # Build bucket sort implementation 17 | gcc sorting.c bucket_sort.c -o bucket_sort 18 | 19 | qsort: 20 | gcc qsort_hoar.c -o qsort_hoar 21 | gcc qsort_lomuto.c -o qsort_lomuto 22 | 23 | clean: # Delete all builded files 24 | rm -f utility_demo counting_sort bucket_sort 25 | -------------------------------------------------------------------------------- /old/practice/2_sorting/sorting.h: -------------------------------------------------------------------------------- 1 | #ifndef SORTING_UTILS_H 2 | #define SORTING_UTILS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define DEFAULT_ARR_SIZE 10 10 | #define DEFAULT_LARGE_ARR_SIZE 1000 11 | 12 | // fill array randomly 13 | void array_fill_rand(uint32_t* array, size_t array_size); 14 | // fill array randomly with elements within range 15 | void array_fill_rand_range(uint32_t* array, size_t array_size, uint32_t range_start, uint32_t range_end); 16 | // sort array with qsort from stdlib, smallest to largest 17 | // use it to validate own sorting algs implementations 18 | void array_sort_std_inc(uint32_t* array, size_t array_size); 19 | // sort array with qsort from stdlib, largest to smallest 20 | // use it to validate own sorting algs implementations 21 | void array_sort_std_dec(uint32_t* array, size_t array_size); 22 | // coppy all items from src to dst 23 | void array_copy(uint32_t* dst, uint32_t* src, size_t array_size); 24 | // compare two arrays 25 | // returns -1 if arrays are equal 26 | // returns diff element index if arrays are not equal 27 | int array_compare(uint32_t* a, uint32_t* b, size_t array_size); 28 | // print array 29 | // note is limited to 128 characters 30 | void array_print(uint32_t* array, size_t array_size, char* note); 31 | // compare two arrays and reports if it equal or not 32 | // use it to validate own sorting algs implementations 33 | void array_test(uint32_t* ref, uint32_t* test, size_t array_size); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /old/practice/2_sorting/utility_demo.c: -------------------------------------------------------------------------------- 1 | #include "sorting.h" 2 | 3 | #define ARR_SIZE 10 4 | 5 | int main() { 6 | 7 | uint32_t array[ARR_SIZE]; 8 | uint32_t array_sorted_ref[ARR_SIZE]; 9 | 10 | array_fill_rand_range(array, ARR_SIZE, 0, 10); 11 | 12 | array_print(array, ARR_SIZE, "initial unsorted array state\n"); 13 | 14 | array_copy(array_sorted_ref, array, ARR_SIZE); 15 | 16 | array_sort_std_inc(array_sorted_ref, ARR_SIZE); 17 | array_print(array_sorted_ref, ARR_SIZE, "\nreference sorted smallest to largest array state\n"); 18 | 19 | array_sort_std_dec(array, ARR_SIZE); 20 | array_print(array, ARR_SIZE, "\ninitial sorted largest to smallest array state\n"); 21 | 22 | array_test(array_sorted_ref, array, ARR_SIZE); 23 | 24 | array_sort_std_inc(array, ARR_SIZE); 25 | array_print(array, ARR_SIZE, "\ninitial sorted smallest to largest array state\n"); 26 | 27 | array_test(array_sorted_ref, array, ARR_SIZE); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /old/practice/3_search/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help 2 | 3 | all: utility_demo # Build all targets 4 | 5 | help: # Show help for each of the Makefile recipes. 6 | @printf "\n" 7 | @grep -E '^[a-z].*:.*' Makefile | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done 8 | @printf "\n" 9 | 10 | utility_demo: ../2_sorting/sorting.c ../2_sorting/utility_demo.c # Build avaliable utilities demo 11 | gcc ../2_sorting/sorting.c ../2_sorting/utility_demo.c -o utility_demo 12 | 13 | linear_search: ../2_sorting/sorting.c linear_search.c 14 | gcc ../2_sorting/sorting.c linear_search.c -o linear_search 15 | 16 | binary_search: ../2_sorting/sorting.c binary_search.c 17 | gcc ../2_sorting/sorting.c binary_search.c -o binary_search 18 | 19 | exponential_search_with_recursive_binary_search: ../2_sorting/sorting.c exponential_search_w_rec_binary.c 20 | gcc ../2_sorting/sorting.c exponential_search_w_rec_binary.c -o exponential_search_with_recursive_binary_search 21 | 22 | exponential_search_with_iterative_binary_search: ../2_sorting/sorting.c exponential_search_w_itr_binary.c 23 | gcc ../2_sorting/sorting.c exponential_search_w_itr_binary.c -o exponential_search_with_iterative_binary_search 24 | 25 | interpolation_search: ../2_sorting/sorting.c interpolation_search.c 26 | gcc ../2_sorting/sorting.c interpolation_search.c -o interpolation_search 27 | 28 | clean: # Delete all builded files 29 | rm -f utility_demo 30 | -------------------------------------------------------------------------------- /old/practice/5_bitmanip/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help 2 | 3 | all: bitmanip # Build all targets 4 | 5 | help: # Show help for each of the Makefile recipes. 6 | @printf "\n" 7 | @grep -E '^[a-z].*:.*' Makefile | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done 8 | @printf "\n" 9 | 10 | bitmanip: bitmanip.c # Build bit manupulation list 11 | gcc bitmanip.c -o bitmanip 12 | 13 | clean: # Delete all builded files 14 | rm -f bitmanip 15 | -------------------------------------------------------------------------------- /old/practice/7_hash_table/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help 2 | 3 | all: hash_table_map # Build all targets 4 | 5 | help: # Show help for each of the Makefile recipes. 6 | @printf "\n" 7 | @grep -E '^[a-z].*:.*' Makefile | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done 8 | @printf "\n" 9 | 10 | hash_table_map: main.c # Build map based on hash table 11 | gcc main.c -o hash_table_map 12 | 13 | clean: # Delete all builded files 14 | rm -f hash_table_map 15 | -------------------------------------------------------------------------------- /old/practice/9_disjoint_set_union/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help 2 | 3 | all: dsu # Build all targets 4 | 5 | help: # Show help for each of the Makefile recipes. 6 | @printf "\n" 7 | @grep -E '^[a-z].*:.*' Makefile | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done 8 | @printf "\n" 9 | 10 | dsu: dsu.c # Build array based queue 11 | gcc dsu.c -o dsu 12 | 13 | clean: # Delete all builded files 14 | rm -f dsu 15 | -------------------------------------------------------------------------------- /old/practice/cpp/hash_map/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help 2 | 3 | all: hash_map # Build all targets 4 | 5 | help: # Show help for each of the Makefile recipes. 6 | @printf "\n" 7 | @grep -E '^[a-z].*:.*' Makefile | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done 8 | @printf "\n" 9 | 10 | hash_map: hash_map_with_diff_key_value_types.cpp 11 | g++ -std=c++20 hash_map_with_diff_key_value_types.cpp -o hash_map 12 | 13 | clean: # Delete all builded files 14 | rm -f hash_map 15 | -------------------------------------------------------------------------------- /old/practice/cpp/hash_map/README_EN.md: -------------------------------------------------------------------------------- 1 | ### Node class 2 | The `Node` class implements key-value pairs along with a boolean flag indicating whether the node is currently in use or not. It provides functionality for updating values, checking for node emptiness, and overloading the print output statement. 3 | 4 | ### HashMap class 5 | The `HashMap` class implements a hash table data structure using an array of pointers to `Node` objects. It supports insert (`put`), delete (`del`), search (`get`), resize and re-hash operations. In addition, operators for indexing (`[]`), equality comparison (`==` and `!=`), and the output operator (`<<`) are overloaded. 6 | 7 | ### Hashing Functions 8 | The `HashMap` class uses two hash functions to generate indexes based on string and integer keys. These hash functions involve the double hashing method for efficient collision resolution. 9 | 10 | ### Collision Resolution 11 | Collisions are resolved using the double hashing methods. If a collision occurs during insertion or search, the algorithm searches for an alternative index by applying a second hash function. 12 | 13 | ### Resizing and Re-hashing 14 | The hash table automatically resizes itself and performs re-hashing when it becomes too full or contains too many deleted items. This helps maintain an acceptable load factor and ensures efficient performance. 15 | 16 | ### Test class 17 | The `Test` class provides several tests to demonstrate the functionality of the `HashMap` class. The tests cover scenarios such as basic operations, string comparison, operator overloading, and handling invalid keys. 18 | -------------------------------------------------------------------------------- /old/practice/cpp/hash_map/README_RU.md: -------------------------------------------------------------------------------- 1 | ### Класс Node 2 | Класс `Node` создает пары ключ-значение вместе с состоянием, который показывает использование узла в данный момент. Он предоставляет функционал для обновления значений, проверки на пустоту узла, а также перегрузку оператора вывода для печати. 3 | 4 | ### Класс HashMap 5 | Класс `HashMap` реализует структуру данных хэш-таблицы, используя массив указателей на объекты `Node`. Он поддерживает операции вставки (`put`), удаления (`del`), поиска (`get`), изменения размера и перехэширования. Кроме того, перегружены операторы для индексации (`[]`), сравнения на равенство (`==` и `!=`), и оператор вывода (`<<`). 6 | 7 | ### Функции Хэширования 8 | Класс `HashMap` использует две хэш-функции для генерации индексов на основе строковых и целочисленных ключей. Эти хэш-функции применяют метод двойного хэширования для эффективного разрешения коллизий. 9 | 10 | ### Разрешение Коллизий 11 | Коллизии разрешаются с помощью техники двойного хэширования. Если при вставке или поиске происходит коллизия, алгоритм ищет альтернативный индекс. 12 | 13 | ### Изменение Размера и Перехэширование 14 | Хэш-таблица автоматически изменяет свой размер и выполняет перехэширование, когда становится слишком заполненной или содержит слишком много удаленных элементов. Это помогает поддерживать приемлемый коэффициент загрузки и обеспечивает эффективную производительность. 15 | 16 | ### Класс Тестирования 17 | Класс `Test` предоставляет несколько тестов для демонстрации функциональности класса `HashMap`. Тесты охватывают такие сценарии, как основные операции, сравнение строк, перегрузку операторов и обработку некорректных ключей. 18 | -------------------------------------------------------------------------------- /old/practice/cpp/topological_sort/MakeLists.txt: -------------------------------------------------------------------------------- 1 | .PHONY: help 2 | 3 | all: kahn dfs_topsort # Build all targets 4 | 5 | help: # Show help for each of the Makefile recipes. 6 | @printf "\n" 7 | @grep -E '^[a-z].*:.*' Makefile | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done 8 | @printf "\n" 9 | 10 | kahn: kahn.cpp # Build kahn 11 | g++ -std=c++20 kahn.cpp -o kahn 12 | 13 | dfs_topsort: dfs_topsort.cpp # Build dfs_topsort 14 | g++ -std=c++20 dfs_topsort.cpp -o dfs_topsort 15 | 16 | clean: # Delete all builded files 17 | rm -f kahn dfs_topsort -------------------------------------------------------------------------------- /old/practice/cpp/topological_sort/README_EN.md: -------------------------------------------------------------------------------- 1 | ## Topological sorting algorithms 2 | 3 | ### Kahn's Algorithm 4 | 5 | ### Description. 6 | Kahn's algorithm uses a queue to process vertices with zero incoming degree. 7 | 8 | ### Example of work 9 | 10 | Input: 11 | ``` 12 | 8 13 | 0 0 0 0 0 0 0 0 14 | 0 0 0 0 1 0 1 0 15 | 0 0 0 0 0 0 0 1 16 | 0 0 0 0 1 0 0 1 17 | 0 0 0 0 0 0 0 0 18 | 0 0 0 0 0 0 0 0 19 | 0 0 0 0 0 0 0 0 20 | 1 0 0 0 0 1 1 0 21 | ``` 22 | 23 | Output: 24 | ``` 25 | Graph 26 | 0 - None 27 | 1 - 4 6 28 | 2 - 7 29 | 3 - 4 7 30 | 4 - None 31 | 5 - None 32 | 6 - None 33 | 7 - 0 5 6 34 | Khan`s topological sort result: 35 | 1 2 3 4 7 0 5 6 36 | ``` 37 | 38 | ### Topological sorting algorithm using DFS 39 | 40 | ### Description 41 | 42 | DFS traverses the graph and adds vertices to the stack in traversal order, then retrieves vertices from the stack in reverse order. 43 | 44 | ### Example of work 45 | 46 | Input: 47 | ``` 48 | 8 49 | 0 0 0 0 0 0 0 0 50 | 0 0 0 0 1 0 1 0 51 | 0 0 0 0 0 0 0 1 52 | 0 0 0 0 1 0 0 1 53 | 0 0 0 0 0 0 0 0 54 | 0 0 0 0 0 0 0 0 55 | 0 0 0 0 0 0 0 0 56 | 1 0 0 0 0 1 1 0 57 | ``` 58 | 59 | Output: 60 | 61 | ``` 62 | Graph 63 | 0 - None 64 | 1 - 4 6 65 | 2 - 7 66 | 3 - 4 7 67 | 4 - None 68 | 5 - None 69 | 6 - None 70 | 7 - 0 5 6 71 | DFS topsort result: 72 | 3 2 7 5 1 6 4 0 73 | ``` 74 | -------------------------------------------------------------------------------- /old/practice/cpp/topological_sort/README_RU.md: -------------------------------------------------------------------------------- 1 | # Алгоритмы топологической сортировки 2 | 3 | ## Алгоритм Кана 4 | 5 | ### Описание 6 | Алгоритм Кана использует очередь для обработки вершин с нулевой входящей степенью. 7 | 8 | ### Пример работы 9 | 10 | Input: 11 | ``` 12 | 8 13 | 0 0 0 0 0 0 0 0 14 | 0 0 0 0 1 0 1 0 15 | 0 0 0 0 0 0 0 1 16 | 0 0 0 0 1 0 0 1 17 | 0 0 0 0 0 0 0 0 18 | 0 0 0 0 0 0 0 0 19 | 0 0 0 0 0 0 0 0 20 | 1 0 0 0 0 1 1 0 21 | ``` 22 | 23 | Output: 24 | ``` 25 | Graph 26 | 0 - None 27 | 1 - 4 6 28 | 2 - 7 29 | 3 - 4 7 30 | 4 - None 31 | 5 - None 32 | 6 - None 33 | 7 - 0 5 6 34 | Khan`s topological sort result: 35 | 1 2 3 4 7 0 5 6 36 | ``` 37 | 38 | ## Алгоритм топологической сортировки при помощи DFS 39 | 40 | ### Описание 41 | 42 | DFS проходит по графу и добавляет вершины в стек в порядке обхода, затем извлекает из стека вершины в обратном порядке. 43 | 44 | ### Пример работы 45 | 46 | Input: 47 | ``` 48 | 8 49 | 0 0 0 0 0 0 0 0 50 | 0 0 0 0 1 0 1 0 51 | 0 0 0 0 0 0 0 1 52 | 0 0 0 0 1 0 0 1 53 | 0 0 0 0 0 0 0 0 54 | 0 0 0 0 0 0 0 0 55 | 0 0 0 0 0 0 0 0 56 | 1 0 0 0 0 1 1 0 57 | ``` 58 | 59 | Output: 60 | 61 | ``` 62 | Graph 63 | 0 - None 64 | 1 - 4 6 65 | 2 - 7 66 | 3 - 4 7 67 | 4 - None 68 | 5 - None 69 | 6 - None 70 | 7 - 0 5 6 71 | DFS topsort result: 72 | 3 2 7 5 1 6 4 0 73 | ``` 74 | -------------------------------------------------------------------------------- /old/snippets/time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void measure_time_of_operation() { 7 | clock_t t; 8 | t = clock(); // hi-res clock counter 9 | printf("MEASURE MY TIME!\n"); 10 | t = clock() - t; 11 | double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds 12 | 13 | printf("executed in %f seconds \n", time_taken); 14 | } 15 | 16 | int main() { 17 | 18 | measure_time_of_operation(); 19 | 20 | return 0; 21 | } --------------------------------------------------------------------------------