实例介绍
Pythonic Data Structures and Algorithms
在Python 3中以最简和清晰的示例实现数据结构和算法。
使用unittest
运行所有测试,请输入以下命令:
$ python3 -m unittest discover tests
对于运行特定的一些测试,您可以这样做(例如:sort):
$ python3 -m unittest tests.test_sort
使用pytest
运行所有测试,请输入以下命令:
$ python3 -m pytest tests
安装
如果您想在代码中使用algorithms API,非常简单:
$ pip3 install algorithms
您可以通过创建一个Python文件进行测试:(例如:使用sort中的merge_sort)
from algorithms.sort import merge_sort
if __name__ == "__main__":
my_list = [1, 8, 3, 5, 6]
my_list = merge_sort(my_list)
print(my_list)
卸载
如果您想卸载algorithms,非常简单:
$ pip3 uninstall -y algorithms
实现列表
数组
delete_nth
flatten
garage
josephus_problem
limit
longest_non_repeat
max_ones_index
merge_intervals
missing_ranges
plus_one
remove_duplicates
rotate
summarize_ranges
three_sum
【实例截图】
文件清单
└── algorithms-cad4754bc71742c2d6fcbd3b92ae74834d359844
├── algorithms
│ ├── arrays
│ │ ├── delete_nth.py
│ │ ├── flatten.py
│ │ ├── garage.py
│ │ ├── __init__.py
│ │ ├── josephus.py
│ │ ├── limit.py
│ │ ├── longest_non_repeat.py
│ │ ├── max_ones_index.py
│ │ ├── merge_intervals.py
│ │ ├── missing_ranges.py
│ │ ├── move_zeros.py
│ │ ├── n_sum.py
│ │ ├── plus_one.py
│ │ ├── remove_duplicates.py
│ │ ├── rotate.py
│ │ ├── summarize_ranges.py
│ │ ├── three_sum.py
│ │ ├── top_1.py
│ │ ├── trimmean.py
│ │ └── two_sum.py
│ ├── automata
│ │ ├── dfa.py
│ │ └── __init__.py
│ ├── backtrack
│ │ ├── add_operators.py
│ │ ├── anagram.py
│ │ ├── array_sum_combinations.py
│ │ ├── combination_sum.py
│ │ ├── factor_combinations.py
│ │ ├── find_words.py
│ │ ├── generate_abbreviations.py
│ │ ├── generate_parenthesis.py
│ │ ├── __init__.py
│ │ ├── letter_combination.py
│ │ ├── palindrome_partitioning.py
│ │ ├── pattern_match.py
│ │ ├── permute.py
│ │ ├── permute_unique.py
│ │ ├── subsets.py
│ │ └── subsets_unique.py
│ ├── bfs
│ │ ├── count_islands.py
│ │ ├── __init__.py
│ │ ├── maze_search.py
│ │ ├── shortest_distance_from_all_buildings.py
│ │ └── word_ladder.py
│ ├── bit
│ │ ├── add_bitwise_operator.py
│ │ ├── binary_gap.py
│ │ ├── bit_operation.py
│ │ ├── bytes_int_conversion.py
│ │ ├── count_flips_to_convert.py
│ │ ├── count_ones.py
│ │ ├── find_difference.py
│ │ ├── find_missing_number.py
│ │ ├── flip_bit_longest_sequence.py
│ │ ├── has_alternative_bit.py
│ │ ├── __init__.py
│ │ ├── insert_bit.py
│ │ ├── power_of_two.py
│ │ ├── remove_bit.py
│ │ ├── reverse_bits.py
│ │ ├── single_number2.py
│ │ ├── single_number3.py
│ │ ├── single_number.py
│ │ ├── subsets.py
│ │ └── swap_pair.py
│ ├── compression
│ │ ├── elias.py
│ │ ├── huffman_coding.py
│ │ ├── __init__.py
│ │ └── rle_compression.py
│ ├── dfs
│ │ ├── all_factors.py
│ │ ├── count_islands.py
│ │ ├── __init__.py
│ │ ├── maze_search.py
│ │ ├── pacific_atlantic.py
│ │ ├── sudoku_solver.py
│ │ └── walls_and_gates.py
│ ├── distribution
│ │ ├── histogram.py
│ │ └── __init__.py
│ ├── dp
│ │ ├── buy_sell_stock.py
│ │ ├── climbing_stairs.py
│ │ ├── coin_change.py
│ │ ├── combination_sum.py
│ │ ├── edit_distance.py
│ │ ├── egg_drop.py
│ │ ├── fib.py
│ │ ├── hosoya_triangle.py
│ │ ├── house_robber.py
│ │ ├── __init__.py
│ │ ├── int_divide.py
│ │ ├── job_scheduling.py
│ │ ├── k_factor.py
│ │ ├── knapsack.py
│ │ ├── longest_common_subsequence.py
│ │ ├── longest_increasing.py
│ │ ├── matrix_chain_order.py
│ │ ├── max_product_subarray.py
│ │ ├── max_subarray.py
│ │ ├── min_cost_path.py
│ │ ├── num_decodings.py
│ │ ├── planting_trees.py
│ │ ├── regex_matching.py
│ │ ├── rod_cut.py
│ │ └── word_break.py
│ ├── graph
│ │ ├── all_pairs_shortest_path.py
│ │ ├── bellman_ford.py
│ │ ├── check_bipartite.py
│ │ ├── check_digraph_strongly_connected.py
│ │ ├── clone_graph.py
│ │ ├── count_connected_number_of_component.py
│ │ ├── cycle_detection.py
│ │ ├── dijkstra.py
│ │ ├── find_all_cliques.py
│ │ ├── find_path.py
│ │ ├── graph.py
│ │ ├── __init__.py
│ │ ├── markov_chain.py
│ │ ├── maximum_flow_bfs.py
│ │ ├── maximum_flow_dfs.py
│ │ ├── maximum_flow.py
│ │ ├── minimum_spanning_tree.py
│ │ ├── path_between_two_vertices_in_digraph.py
│ │ ├── prims_minimum_spanning.py
│ │ ├── satisfiability.py
│ │ ├── strongly_connected_components_kosaraju.py
│ │ ├── tarjan.py
│ │ ├── transitive_closure_dfs.py
│ │ └── traversal.py
│ ├── greedy
│ │ ├── __init__.py
│ │ └── max_contiguous_subsequence_sum.py
│ ├── heap
│ │ ├── binary_heap.py
│ │ ├── __init__.py
│ │ ├── k_closest_points.py
│ │ ├── merge_sorted_k_lists.py
│ │ ├── skyline.py
│ │ └── sliding_window_max.py
│ ├── __init__.py
│ ├── linkedlist
│ │ ├── add_two_numbers.py
│ │ ├── copy_random_pointer.py
│ │ ├── delete_node.py
│ │ ├── first_cyclic_node.py
│ │ ├── __init__.py
│ │ ├── intersection.py
│ │ ├── is_cyclic.py
│ │ ├── is_palindrome.py
│ │ ├── is_sorted.py
│ │ ├── kth_to_last.py
│ │ ├── linkedlist.py
│ │ ├── merge_two_list.py
│ │ ├── partition.py
│ │ ├── remove_duplicates.py
│ │ ├── remove_range.py
│ │ ├── reverse.py
│ │ ├── rotate_list.py
│ │ └── swap_in_pairs.py
│ ├── map
│ │ ├── hashtable.py
│ │ ├── __init__.py
│ │ ├── is_anagram.py
│ │ ├── is_isomorphic.py
│ │ ├── longest_common_subsequence.py
│ │ ├── longest_palindromic_subsequence.py
│ │ ├── randomized_set.py
│ │ ├── separate_chaining_hashtable.py
│ │ ├── valid_sudoku.py
│ │ └── word_pattern.py
│ ├── maths
│ │ ├── base_conversion.py
│ │ ├── chinese_remainder_theorem.py
│ │ ├── combination.py
│ │ ├── cosine_similarity.py
│ │ ├── decimal_to_binary_ip.py
│ │ ├── diffie_hellman_key_exchange.py
│ │ ├── euler_totient.py
│ │ ├── extended_gcd.py
│ │ ├── factorial.py
│ │ ├── fft.py
│ │ ├── find_order_simple.py
│ │ ├── find_primitive_root_simple.py
│ │ ├── gcd.py
│ │ ├── generate_strobogrammtic.py
│ │ ├── hailstone.py
│ │ ├── __init__.py
│ │ ├── is_strobogrammatic.py
│ │ ├── krishnamurthy_number.py
│ │ ├── magic_number.py
│ │ ├── modular_exponential.py
│ │ ├── modular_inverse.py
│ │ ├── next_bigger.py
│ │ ├── next_perfect_square.py
│ │ ├── nth_digit.py
│ │ ├── num_digits.py
│ │ ├── num_perfect_squares.py
│ │ ├── polynomial.py
│ │ ├── power.py
│ │ ├── prime_check.py
│ │ ├── primes_sieve_of_eratosthenes.py
│ │ ├── pythagoras.py
│ │ ├── rabin_miller.py
│ │ ├── recursive_binomial_coefficient.py
│ │ ├── rsa.py
│ │ ├── sqrt_precision_factor.py
│ │ ├── summing_digits.py
│ │ └── symmetry_group_cycle_index.py
│ ├── matrix
│ │ ├── bomb_enemy.py
│ │ ├── cholesky_matrix_decomposition.py
│ │ ├── copy_transform.py
│ │ ├── count_paths.py
│ │ ├── crout_matrix_decomposition.py
│ │ ├── __init__.py
│ │ ├── matrix_exponentiation.py
│ │ ├── matrix_inversion.py
│ │ ├── multiply.py
│ │ ├── rotate_image.py
│ │ ├── search_in_sorted_matrix.py
│ │ ├── sort_matrix_diagonally.py
│ │ ├── sparse_dot_vector.py
│ │ ├── sparse_mul.py
│ │ ├── spiral_traversal.py
│ │ ├── sudoku_validator.py
│ │ └── sum_sub_squares.py
│ ├── ml
│ │ └── nearest_neighbor.py
│ ├── queues
│ │ ├── __init__.py
│ │ ├── max_sliding_window.py
│ │ ├── moving_average.py
│ │ ├── priority_queue.py
│ │ ├── queue.py
│ │ ├── reconstruct_queue.py
│ │ └── zigzagiterator.py
│ ├── search
│ │ ├── binary_search.py
│ │ ├── find_min_rotate.py
│ │ ├── first_occurrence.py
│ │ ├── __init__.py
│ │ ├── interpolation_search.py
│ │ ├── jump_search.py
│ │ ├── last_occurrence.py
│ │ ├── linear_search.py
│ │ ├── next_greatest_letter.py
│ │ ├── search_insert.py
│ │ ├── search_range.py
│ │ ├── search_rotate.py
│ │ ├── ternary_search.py
│ │ └── two_sum.py
│ ├── set
│ │ ├── find_keyboard_row.py
│ │ ├── __init__.py
│ │ ├── randomized_set.py
│ │ └── set_covering.py
│ ├── sort
│ │ ├── bitonic_sort.py
│ │ ├── bogo_sort.py
│ │ ├── bubble_sort.py
│ │ ├── bucket_sort.py
│ │ ├── cocktail_shaker_sort.py
│ │ ├── comb_sort.py
│ │ ├── counting_sort.py
│ │ ├── cycle_sort.py
│ │ ├── exchange_sort.py
│ │ ├── gnome_sort.py
│ │ ├── heap_sort.py
│ │ ├── __init__.py
│ │ ├── insertion_sort.py
│ │ ├── meeting_rooms.py
│ │ ├── merge_sort.py
│ │ ├── pancake_sort.py
│ │ ├── pigeonhole_sort.py
│ │ ├── quick_sort.py
│ │ ├── radix_sort.py
│ │ ├── selection_sort.py
│ │ ├── shell_sort.py
│ │ ├── sort_colors.py
│ │ ├── stooge_sort.py
│ │ ├── top_sort.py
│ │ └── wiggle_sort.py
│ ├── stack
│ │ ├── __init__.py
│ │ ├── is_consecutive.py
│ │ ├── is_sorted.py
│ │ ├── longest_abs_path.py
│ │ ├── ordered_stack.py
│ │ ├── remove_min.py
│ │ ├── simplify_path.py
│ │ ├── stack.py
│ │ ├── stutter.py
│ │ ├── switch_pairs.py
│ │ └── valid_parenthesis.py
│ ├── streaming
│ │ ├── __init__.py
│ │ ├── misra_gries.py
│ │ └── one_sparse_recovery.py
│ ├── strings
│ │ ├── add_binary.py
│ │ ├── atbash_cipher.py
│ │ ├── breaking_bad.py
│ │ ├── caesar_cipher.py
│ │ ├── check_pangram.py
│ │ ├── contain_string.py
│ │ ├── count_binary_substring.py
│ │ ├── decode_string.py
│ │ ├── delete_reoccurring.py
│ │ ├── domain_extractor.py
│ │ ├── encode_decode.py
│ │ ├── first_unique_char.py
│ │ ├── fizzbuzz.py
│ │ ├── group_anagrams.py
│ │ ├── __init__.py
│ │ ├── int_to_roman.py
│ │ ├── is_palindrome.py
│ │ ├── is_rotated.py
│ │ ├── judge_circle.py
│ │ ├── knuth_morris_pratt.py
│ │ ├── license_number.py
│ │ ├── longest_common_prefix.py
│ │ ├── longest_palindromic_substring.py
│ │ ├── make_sentence.py
│ │ ├── merge_string_checker.py
│ │ ├── min_distance.py
│ │ ├── multiply_strings.py
│ │ ├── one_edit_distance.py
│ │ ├── panagram.py
│ │ ├── rabin_karp.py
│ │ ├── repeat_string.py
│ │ ├── repeat_substring.py
│ │ ├── reverse_string.py
│ │ ├── reverse_vowel.py
│ │ ├── reverse_words.py
│ │ ├── roman_to_int.py
│ │ ├── rotate.py
│ │ ├── strip_url_params.py
│ │ ├── strong_password.py
│ │ ├── text_justification.py
│ │ ├── unique_morse.py
│ │ ├── validate_coordinates.py
│ │ └── word_squares.py
│ ├── tree
│ │ ├── avl
│ │ │ ├── avl.py
│ │ │ └── __init__.py
│ │ ├── binary_tree_paths.py
│ │ ├── bin_tree_to_list.py
│ │ ├── bst
│ │ │ ├── array_to_bst.py
│ │ │ ├── bst_closest_value.py
│ │ │ ├── BSTIterator.py
│ │ │ ├── bst.py
│ │ │ ├── count_left_node.py
│ │ │ ├── delete_node.py
│ │ │ ├── depth_sum.py
│ │ │ ├── height.py
│ │ │ ├── is_bst.py
│ │ │ ├── kth_smallest.py
│ │ │ ├── lowest_common_ancestor.py
│ │ │ ├── num_empty.py
│ │ │ ├── predecessor.py
│ │ │ ├── serialize_deserialize.py
│ │ │ ├── successor.py
│ │ │ └── unique_bst.py
│ │ ├── b_tree.py
│ │ ├── construct_tree_postorder_preorder.py
│ │ ├── deepest_left.py
│ │ ├── fenwick_tree
│ │ │ └── fenwick_tree.py
│ │ ├── __init__.py
│ │ ├── invert_tree.py
│ │ ├── is_balanced.py
│ │ ├── is_subtree.py
│ │ ├── is_symmetric.py
│ │ ├── longest_consecutive.py
│ │ ├── lowest_common_ancestor.py
│ │ ├── max_height.py
│ │ ├── max_path_sum.py
│ │ ├── min_height.py
│ │ ├── path_sum2.py
│ │ ├── path_sum.py
│ │ ├── pretty_print.py
│ │ ├── red_black_tree
│ │ │ └── red_black_tree.py
│ │ ├── same_tree.py
│ │ ├── segment_tree
│ │ │ ├── iterative_segment_tree.py
│ │ │ └── segment_tree.py
│ │ ├── traversal
│ │ │ ├── __init__.py
│ │ │ ├── inorder.py
│ │ │ ├── level_order.py
│ │ │ ├── postorder.py
│ │ │ ├── preorder.py
│ │ │ └── zigzag.py
│ │ ├── tree.py
│ │ └── trie
│ │ ├── add_and_search.py
│ │ └── trie.py
│ ├── unionfind
│ │ └── count_islands.py
│ └── unix
│ ├── __init__.py
│ └── path
│ ├── full_path.py
│ ├── join_with_slash.py
│ ├── simplify_path.py
│ └── split.py
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── docs
│ ├── make.bat
│ ├── Makefile
│ ├── requirements.txt
│ └── source
│ ├── arrays.rst
│ ├── backtrack.rst
│ ├── bfs.rst
│ ├── bit.rst
│ ├── conf.py
│ ├── dfs.rst
│ ├── dp.rst
│ ├── examples.rst
│ ├── graph.rst
│ ├── heap.rst
│ ├── index.rst
│ ├── linkedlist.rst
│ ├── map.rst
│ ├── maths.rst
│ ├── matrix.rst
│ ├── queues.rst
│ ├── search.rst
│ ├── set.rst
│ ├── sort.rst
│ ├── stack.rst
│ ├── _static
│ │ ├── algorithms_logo.png
│ │ └── logo
│ │ ├── 128pxblack.png
│ │ ├── 128pxblack.svg
│ │ ├── 128pxblue.png
│ │ ├── 128pxblue.svg
│ │ ├── 128pxorange.png
│ │ ├── 128pxorange.svg
│ │ ├── 256pxblack.png
│ │ ├── 256pxblack.svg
│ │ ├── 256pxblue.png
│ │ ├── 256pxblue.svg
│ │ ├── 256pxorange.png
│ │ ├── 256pxorange.svg
│ │ ├── 512pxblack.png
│ │ ├── 512pxblack.svg
│ │ ├── 512pxblue.png
│ │ ├── 512pxblue.svg
│ │ ├── 512pxorange.png
│ │ ├── 512pxorange.svg
│ │ ├── add
│ │ ├── logotype1black.png
│ │ ├── logotype1black.svg
│ │ ├── logotype1blue.png
│ │ ├── logotype1blue.svg
│ │ ├── logotype1orange.png
│ │ ├── logotype1orange.svg
│ │ ├── logotype2black.png
│ │ ├── logotype2black.svg
│ │ ├── logotype2blue.png
│ │ ├── logotype2blue.svg
│ │ ├── logotype2orange.png
│ │ └── logotype2orange.svg
│ ├── strings.rst
│ └── tree.rst
├── LICENSE
├── MANIFEST.in
├── README.md
├── requirements.txt
├── setup.py
├── test_requirements.txt
├── tests
│ ├── test_array.py
│ ├── test_automata.py
│ ├── test_backtrack.py
│ ├── test_bfs.py
│ ├── test_bit.py
│ ├── test_compression.py
│ ├── test_dfs.py
│ ├── test_dp.py
│ ├── test_graph.py
│ ├── test_greedy.py
│ ├── test_heap.py
│ ├── test_histogram.py
│ ├── test_iterative_segment_tree.py
│ ├── test_linkedlist.py
│ ├── test_map.py
│ ├── test_maths.py
│ ├── test_matrix.py
│ ├── test_ml.py
│ ├── test_monomial.py
│ ├── test_polynomial.py
│ ├── test_queues.py
│ ├── test_search.py
│ ├── test_set.py
│ ├── test_sort.py
│ ├── test_stack.py
│ ├── test_streaming.py
│ ├── test_strings.py
│ ├── test_tree.py
│ └── test_unix.py
└── tox.ini
42 directories, 475 files
标签:
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论