├── .github ├── DCP_SCORECARD.md ├── DevIncept Assessment │ ├── Week 1 │ │ └── DCP - PyAlgo-Tree - Week 1.xlsx │ └── Week 2 │ │ └── DCP - PyAlgo-Tree - Week2.xlsx ├── FUNDING.yml ├── README │ ├── readme1_template.md │ └── readme2_template.md ├── _config.yml ├── auto_assign.yml ├── config.yml ├── issue_template │ ├── bug_report.md │ └── feature_request.md ├── labels.json ├── opensource_programs.md ├── pullrequest_template.md └── workflows │ ├── issue-label.yml │ └── reviewer_auto_assigner.yml ├── Algebra ├── Algebra Operation │ ├── Images │ │ ├── IMG_20211003_002224.jpg │ │ ├── IMG_20211003_002329.jpg │ │ ├── IMG_20211003_002355.jpg │ │ ├── IMG_20211003_002420.jpg │ │ ├── IMG_20211003_002437.jpg │ │ ├── IMG_20211003_002512.jpg │ │ ├── IMG_20211003_002530.jpg │ │ └── IMG_20211003_002554.jpg │ ├── README.md │ └── algebra.py └── README.md ├── Arithmetic └── README.md ├── Arrays ├── Array Operations │ ├── Images │ │ ├── Output1_part1.png │ │ ├── Output1_part2.png │ │ ├── Output1_part3.png │ │ ├── Output1_part4.png │ │ ├── Output1_part5.png │ │ ├── Output1_part6.png │ │ └── Output1_part7.png │ ├── README.md │ ├── array_operations.py │ └── requirements.txt ├── Divisor Sum │ ├── Images │ │ └── ss.png │ ├── README.md │ └── divisor_sum.py ├── README.md └── Trapping Rainwater │ ├── Images │ └── outputimg5.jpg │ ├── README.md │ └── trapping_rainwater.py ├── Artificial Intelligence ├── 8 Puzzle Problem using A star Algorithm │ ├── 8_puzzle_problem_using_A_star_algorithm.py │ ├── Images │ │ └── ss.png │ └── README.md ├── 8 Puzzle Problem using BFS │ ├── 8_puzzle_problem_using_BFS.py │ ├── Images │ │ ├── ss1.png │ │ ├── ss2.png │ │ ├── ss3.png │ │ └── ss4.png │ └── README.md └── README.md ├── Backtracking ├── Cryptarithmetic Problem │ ├── Images │ │ └── ss.png │ ├── README.md │ └── cryptarithmetic_problem.py ├── Graph Coloring Problem │ ├── Images │ │ └── ss.png │ ├── README.md │ └── graph_coloring_problem.py ├── Hamiltonian Cycle │ ├── Images │ │ └── ss.png │ ├── README.md │ └── hamiltonian_cycle.py ├── Knight's Tour │ ├── Images │ │ └── ss.png │ ├── README.md │ └── knight's_tour.py ├── N Queens │ ├── Images │ │ └── ss.png │ ├── README.md │ └── n_queens.py ├── README.md ├── Rat in a Maze │ ├── Images │ │ ├── rat1.PNG │ │ ├── rat2.PNG │ │ └── rat3.PNG │ ├── README.md │ └── rat_in_a_maze.py ├── Subset Sum │ ├── Images │ │ └── ss.png │ ├── README.md │ └── subset_sum.py ├── Sudoku Solver │ ├── Images │ │ ├── output.png │ │ ├── output_error.png │ │ └── sample.png │ ├── README.md │ └── sudoku.py ├── Tic Tac Toe Game │ ├── Images │ │ ├── ss1.png │ │ └── ss2.png │ ├── README.md │ └── tic_tac_toe_game.py └── Water Jug Problem │ ├── Images │ ├── ss1.png │ ├── ss2.png │ ├── ss3.png │ └── ss4.png │ ├── README.md │ └── water_jug_problem.py ├── Bit Manipulation ├── Count Set Bits in an integer │ ├── Images │ │ ├── cover_pic.png │ │ ├── io_1.png │ │ └── io_2.png │ ├── README.md │ ├── brian_kernighans_algo.py │ └── brute_approach.py └── README.md ├── Blockchain └── README.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING_GUIDELINES.md ├── Ciphers ├── Affine Cipher │ ├── Affine_Cipher.py │ ├── Images │ │ ├── Affine Cipher_Output-2.jpeg │ │ ├── Affine Cipher_Output-3.jpeg │ │ ├── Affine Cipher_Output-4.jpeg │ │ └── Affine Cipher_Output.jpeg │ ├── README.md │ └── requirements.txt ├── Caesar Cipher │ ├── Caeser_Cipher.py │ ├── Images │ │ ├── Output_1.png │ │ ├── Output_2.png │ │ └── Output_3.png │ └── README.md ├── README.md └── Vigenère Cipher │ ├── Images │ ├── Decryption Mode.png │ ├── Encryption Mode.png │ └── Vignere Table.png │ ├── README.md │ └── Vignere_Cipher.py ├── Compressions └── README.md ├── Computer Vision ├── Face Detection │ ├── README.md │ ├── face_detection.py │ ├── images │ │ ├── Flow_FaceDetection_OpenCV.jpg │ │ ├── harry.png │ │ └── snape.png │ └── requirements.txt ├── Face Recognition │ ├── Dataset │ │ ├── recognition_list.csv │ │ └── train_images │ │ │ ├── Bill Gates.jpg │ │ │ ├── Elon Musk.jpg │ │ │ └── Narendra Modi.jpg │ ├── Images │ │ ├── Output │ │ │ ├── Name_list.png │ │ │ ├── Name_list1.png │ │ │ ├── outout3.png │ │ │ ├── output1.png │ │ │ └── output2.png │ │ └── block Diagram.png │ └── Model │ │ ├── README.md │ │ ├── face_recognition.py │ │ └── requirements.txt ├── Human Detection and Counting │ ├── Images │ │ ├── 1.jpg │ │ ├── 2.jpg │ │ ├── 3.jpg │ │ ├── 4.jpg │ │ ├── 5.jpg │ │ ├── 6.jpg │ │ ├── 7.jpg │ │ ├── 8.jpg │ │ ├── 9.jpg │ │ ├── front1.png │ │ ├── front2.png │ │ ├── icon.ico │ │ ├── icon.jpg │ │ ├── image1.jpg │ │ └── image2.png │ ├── README.md │ ├── frozen_inference_graph.pb │ ├── human_detection_and_counting.py │ ├── persondetection.py │ └── requirements.txt └── README.md ├── Conversions └── README.md ├── Cryptography ├── Brute Forcing Caesar Cipher │ ├── Images │ │ └── brute_force_output.png │ ├── README.md │ └── brute_forcing_caesar_cipher.py ├── Caesar Cipher │ ├── Images │ │ ├── DecryptedString.png │ │ ├── EncryptedStringOutput.png │ │ └── README.md │ ├── README.md │ └── caesar_cipher.py ├── Diffie_Hellmann │ ├── Images │ │ ├── diffie1.PNG │ │ ├── diffie2.PNG │ │ └── diffie3.PNG │ ├── README.md │ ├── diffie_hellman.py │ └── requirements.txt ├── README.md ├── RSA_ElGamal_cryptography │ ├── Images │ │ ├── elgamal.PNG │ │ ├── elgamal1.PNG │ │ ├── rsa.PNG │ │ └── rsa1.PNG │ ├── README.md │ ├── requirements.txt │ └── rsa_elgamal.py ├── Reverse Cipher │ ├── Images │ │ └── reverse_cipher.png │ ├── README.md │ └── reverse_cipher.py └── Transposition Cipher │ ├── Images │ └── Output1.PNG │ ├── README.md │ └── transposition_cipher.py ├── Data Structures └── README.md ├── Deep Learning └── README.md ├── Digital Image Processing ├── Face Detection │ ├── README.md │ ├── face_detection.py │ ├── images │ │ ├── harry.png │ │ └── snape.png │ └── requirements.txt └── README.md ├── Dynamic Programming ├── 0 1 Knapsack │ ├── 01_knapsack.py │ ├── Images │ │ ├── io_1.png │ │ ├── io_2.png │ │ ├── knapsack_cover_pic.jpg │ │ └── tree_dig.jpg │ └── README.md ├── Bell Numbers │ ├── Images │ │ ├── bell1.png │ │ ├── bell2.png │ │ └── bell3.png │ ├── README.md │ └── bell_numbers.py ├── Friends Pairing Problem │ ├── Images │ │ ├── friend1.PNG │ │ ├── friend2.PNG │ │ └── friend3.PNG │ ├── README.md │ └── friends_pairing_problem.py ├── Gold Mine Problem │ ├── Images │ │ ├── gold1.PNG │ │ └── gold2.PNG │ ├── README.md │ └── gold_mine_problem.py ├── Longest Common Subsequence │ ├── Images │ │ ├── TEST_1.png │ │ └── TEST_2.png │ ├── README.md │ └── longest_common_subsequence.py ├── Nth Catalan Numbers │ ├── Images │ │ ├── catalan-1.png │ │ ├── catalan-2.png │ │ └── catalan-3.png │ ├── README.md │ └── nth_catalan_numbers.py ├── Subset Sum Problem │ ├── Images │ │ ├── subset1.png │ │ ├── subset2.png │ │ ├── subset3.png │ │ └── subset4.png │ ├── README.md │ └── subset_sum_problem.py └── Ugly Numbers │ ├── Images │ ├── ugly1.PNG │ ├── ugly2.PNG │ ├── ugly3.PNG │ └── ugly4.PNG │ ├── README.md │ └── ugly_numbers.py ├── Electronics └── README.md ├── Fractals └── README.md ├── Geometry ├── Complex To Polar Coordinates │ ├── Images │ │ ├── README.md │ │ ├── complexpolaroutput.png │ │ └── complexpolaroutput1.png │ ├── README.md │ └── complex_to_polar.py ├── Find Angle MBC │ ├── Find_Angle_MBC.py │ ├── Images │ │ ├── mbc1.png │ │ ├── mbc2.png │ │ ├── mbc3.png │ │ ├── mbc4.png │ │ ├── mbc5.png │ │ └── mbc6.png │ └── README.md └── README.md ├── Graphs ├── Breadth First Search │ ├── Images │ │ ├── input.jpg │ │ └── output.jpg │ ├── README.md │ └── bfs.py ├── DFS │ ├── Images │ │ ├── dfs.jpg │ │ └── output.jpg │ ├── README.md │ └── dfs.py └── README.md ├── Greedy ├── Activity Selection Problem │ ├── Images │ │ ├── asp-1.png │ │ └── asp-2.png │ ├── README.md │ └── activity_selection_problem.py ├── Huffman Coding │ ├── Images │ │ ├── hc-1.png │ │ └── hc-2.png │ ├── README.md │ └── huffman_coding.py ├── Job Sequencing Problem │ ├── Images │ │ ├── jsp-1.png │ │ └── jsp-2.png │ ├── README.md │ └── job_sequencing_problem.py └── README.md ├── Hashes └── README.md ├── Knapsack ├── 0-1 Knapsack │ ├── Brute Force Method │ │ ├── 0-1_knapsack_brute_force.py │ │ └── README.md │ ├── Dynamic Method │ │ ├── 0-1_knapsack_dynamic.py │ │ └── README.md │ ├── Images │ │ ├── knapsack1.PNG │ │ ├── knapsack2.PNG │ │ └── knapsack3.jpg │ └── README.md ├── Fractional Knapsack │ ├── Images │ │ └── frac1.PNG │ ├── README.md │ └── fractional_knapsack.py └── README.md ├── LICENSE ├── Lists ├── Circular Linked List │ ├── Images │ │ ├── Output1.PNG │ │ └── Output2.PNG │ ├── README.md │ └── circular_linked_list.py ├── Doubly Linked List │ ├── Images │ │ ├── screenshot_1.png │ │ └── screenshot_2.png │ ├── README.md │ └── doubly_linked_list.py ├── README.md └── Singly Linked List │ ├── Images │ └── Screenshot_1.png │ ├── README.md │ └── singly_linked_list.py ├── Machine Learning ├── Campus Placement Analysis & Prediction │ ├── Dataset │ │ └── Placement_Data_Full_Class.csv │ ├── Images │ │ ├── cp1.jpg │ │ ├── cp2.jpg │ │ ├── cp3.jpg │ │ └── cp4.jpg │ └── Model │ │ ├── README.md │ │ └── campus_placement_analysis&prediction.py ├── Heart Failure Prediction │ ├── Heart_Failure_Prediction.ipynb │ ├── Image │ │ ├── Decision Tree Classifier.png │ │ ├── Gradient Boosting.png │ │ ├── KNN.png │ │ ├── Logistic Regression.png │ │ ├── Random Forest Classifier.png │ │ └── SVM.png │ ├── README.md │ ├── Requirements.txt │ └── heart.csv ├── K-Means Clustering using Iris │ ├── K-Means_Clustering_using_Iris.ipynb │ ├── README.md │ └── requirements.txt ├── Mobile Price Range Classification │ ├── Dataset │ │ └── train.csv │ ├── Images │ │ ├── lr1.jpg │ │ ├── lr2.jpg │ │ └── lr3.jpg │ └── Model │ │ ├── README.md │ │ └── mobile_price_range_classification.py ├── Movie Classification │ ├── Dataset │ │ └── Movie_classification.csv │ ├── Images │ │ ├── knn1.jpg │ │ ├── knn2.jpg │ │ ├── knn3.jpg │ │ ├── knn4.jpg │ │ ├── knn5.jpg │ │ └── knn6.jpg │ └── Model │ │ ├── README.md │ │ └── movie_classification.py ├── Predicting House Prices │ ├── Images │ │ ├── lin1.png │ │ ├── lin2.png │ │ ├── lin3.png │ │ ├── lin4.png │ │ ├── lin5.png │ │ └── lin6.png │ ├── Predicting_House_Prices.py │ ├── README.md │ └── requirements.txt └── README.md ├── Maths ├── Average Calculator │ ├── Images │ │ └── ss.png │ ├── README.md │ └── average_calculator.py ├── Binary Numbers │ ├── Images │ │ └── ss.png │ ├── README.md │ └── binary_numbers.py ├── Bitwise AND │ ├── Images │ │ └── ss.png │ ├── README.md │ └── bitwise_AND.py └── README.md ├── Matrices └── README.md ├── Miscellaneous └── README.md ├── Networking └── README.md ├── Optimization └── README.md ├── Path Finding └── README.md ├── Quantum └── README.md ├── Queues ├── Linked Queue │ ├── Images │ │ ├── Screenshot_1.png │ │ └── Screenshot_2.png │ ├── README.md │ └── linked_queue.py ├── Priority Queue │ ├── Images │ │ ├── hey │ │ └── priority.jpg │ ├── README.md │ └── priority.py └── README.md ├── README.md ├── Recursion ├── All indices │ ├── All_indices.py │ ├── Images │ │ └── Output-img.jpg │ └── README.md ├── Fibonacci │ ├── Images │ │ └── output.png │ ├── README.md │ └── fib.py ├── First Index │ ├── Images │ │ └── output1.jpg │ ├── README.md │ └── first_index_of_array.py ├── Last Index │ ├── Images │ │ └── output2.jpg │ ├── README.md │ └── last_index.py ├── Max Path Maze │ ├── Images │ │ └── terminal_output.png │ ├── README.md │ └── max_path_maze.py ├── Palindrome Check │ ├── Images │ │ ├── Palindrome_Check_1.PNG │ │ ├── Palindrome_Check_2.PNG │ │ ├── Palindrome_Check_3.PNG │ │ └── Palindrome_Check_4.PNG │ ├── README.md │ └── palindrome_check.py └── README.md ├── Scheduling └── Round Robin Scheduling │ ├── Images │ ├── Round_Robin_Scheduling_output1.jpeg │ ├── Round_Robin_Scheduling_output2.jpeg │ └── Round_Robin_Scheduling_output3.jpeg │ ├── README.md │ └── round_robin_scheduling.py ├── Searching ├── Binary Search │ ├── Images │ │ └── output.jpg │ ├── README.md │ └── binary_search.py ├── Depth First Search │ ├── Images │ │ ├── ss1.png │ │ └── ss2.png │ ├── README.md │ └── depth_first_search.py ├── Linear Search │ ├── Images │ │ └── output.jpg │ ├── README.md │ └── linear_search.py └── README.md ├── Sets └── README.md ├── Sorting ├── Bubble Sort │ ├── Images │ │ └── output.jpg │ ├── README.md │ └── bubble_sort.py ├── Heap Sort │ ├── Images │ │ └── heap_sort.png │ ├── README.md │ └── heap_sort.py ├── Insertion Sort │ ├── Images │ │ ├── input.png │ │ └── sort_output1.png │ ├── README.md │ └── insertion_sort.py ├── Merge Sort │ ├── Images │ │ └── output.png │ ├── README.md │ └── merge_sort.py ├── Quick Sort │ ├── Images │ │ ├── output1.png │ │ └── output2.png │ ├── README.md │ └── quick_sort.py ├── README.md ├── Radix Sort │ ├── Images │ │ ├── radix-sort-1.png │ │ └── radix-sort-2.png │ ├── README.md │ └── radix_sort.py ├── Selection Sort │ ├── Images │ │ └── output.jpg │ ├── README.md │ └── selection_sort.py └── Shell Sort │ ├── Images │ ├── Output1.png │ ├── Output2.png │ └── shell_sort.png │ ├── README.md │ └── shell_sort.py ├── Stacks ├── Infix to Postfix Conversion │ ├── Images │ │ ├── infix_to_postfix_conversion1.PNG │ │ ├── infix_to_postfix_conversion2.PNG │ │ └── infix_to_postfix_conversion3.PNG │ ├── README.md │ └── infix_to_postfix_conversion.py └── README.md ├── Streaming └── README.md ├── Strings ├── Bad String │ ├── Images │ │ └── ss.png │ ├── README.md │ └── bad_string.py ├── Capitalizing │ ├── Images │ │ └── ss.png │ ├── README.md │ └── capitalizing.py ├── Determining DNA Health │ ├── Determining_DNA_Health.py │ ├── Images │ │ ├── dna1.png │ │ ├── dna2.png │ │ ├── dna3.png │ │ ├── dna4.png │ │ └── dna5.png │ └── README.md └── README.md ├── Tests └── README.md ├── Traversals ├── Inorder Preorder Postorder │ ├── Images │ │ └── output.png │ ├── README.md │ └── inorder_preorder_postorder.py └── README.md ├── Trees ├── BST Level Order Traversal │ ├── BST_level_order_traversal.py │ ├── Images │ │ └── ss.png │ └── README.md ├── Binary Search Tree │ ├── BST.py │ ├── Images │ │ ├── output1.png │ │ ├── output2.png │ │ ├── output3.png │ │ ├── output4.png │ │ └── output5.png │ └── README.md ├── Binary Tree To DLL │ ├── Images │ │ ├── binary_tree_to_dll_output1.PNG │ │ ├── binary_tree_to_dll_output2.PNG │ │ └── binary_tree_to_dll_output3.PNG │ ├── README.md │ └── binary_tree_to_dll.py ├── Expression Tree Evaluation │ ├── Images │ │ ├── expression_tree_evaluation_output.PNG │ │ └── expression_tree_evaluation_output2.PNG │ ├── README.md │ └── expression_tree_evaluation.py ├── Height of a BST │ ├── Images │ │ └── ss.png │ ├── README.md │ └── height_of_BST.py ├── Lowest Common Ancestor Binary Search Tree │ ├── Images │ │ ├── lowest_common_ancestor_binary_search_tree_output1.PNG │ │ ├── lowest_common_ancestor_binary_search_tree_output2.PNG │ │ └── lowest_common_ancestor_binary_search_tree_output3.PNG │ ├── README.md │ └── lowest_common_ancestor_binary_search_tree.py ├── Lowest Common Ancestor Binary Tree │ ├── Images │ │ ├── README.md │ │ ├── lowest_common_ancestor_binary_tree_output1.PNG │ │ ├── lowest_common_ancestor_binary_tree_output2.PNG │ │ ├── lowest_common_ancestor_binary_tree_output3.PNG │ │ └── lowest_common_ancestor_binary_tree_output4.PNG │ ├── README.md │ └── lowest_common_ancestor_binary_tree.py ├── README.md ├── Segment Tree Creation │ ├── Images │ │ ├── creation_output1.PNG │ │ ├── creation_output2.PNG │ │ └── creation_output3.PNG │ ├── README.md │ └── segment_tree_creation.py ├── Segment Tree Range Sum Query │ ├── Images │ │ ├── range_sum_query_output1.PNG │ │ └── range_sum_query_output2.PNG │ ├── README.md │ └── segment_tree_sum_range_query.py └── Segment Tree Update Query │ ├── Images │ ├── update_query_output1.PNG │ └── update_query_output2.PNG │ ├── README.md │ └── segment_tree_update_query.py ├── Unix └── README.md └── _config.yml /.github/DevIncept Assessment/Week 1/DCP - PyAlgo-Tree - Week 1.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/.github/DevIncept Assessment/Week 1/DCP - PyAlgo-Tree - Week 1.xlsx -------------------------------------------------------------------------------- /.github/DevIncept Assessment/Week 2/DCP - PyAlgo-Tree - Week2.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/.github/DevIncept Assessment/Week 2/DCP - PyAlgo-Tree - Week2.xlsx -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [prathimacode-hub] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: [ 14 | "https://www.buymeacoffee.com/prathimakadari", 15 | ] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 16 | -------------------------------------------------------------------------------- /.github/README/readme1_template.md: -------------------------------------------------------------------------------- 1 | # Package/Script Name 2 | 3 | ## Aim 4 | 5 | The main aim of the script you want to achieve. 6 | 7 | 8 | ## Purpose 9 | 10 | What's the purpose of this script 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - Give a short introduction about the script 16 | - If package, list of functionalities/scripts it can perform 17 | - If standalone script, short description of script explaining what it achieves. 18 | - List out the libraries imported. 19 | 20 | 21 | ## Workflow of the Project 22 | 23 | Add the workflow of the script point by point to get good understanding of the program 24 | 25 | 26 | ## Detailed explanation of script, if needed 27 | 28 | If code is not explainable using comments, use this sections to explain your script 29 | 30 | 31 | ## Setup instructions 32 | 33 | Explain how to setup and run your package/script in user's system 34 | 35 | 36 | ## Compilation Steps 37 | 38 | Briefly show the compilation steps of the script 39 | 40 | 41 | ## Sample Test Cases 42 | 43 | Provide 2-3 sample test cases of the project 44 | 45 | 46 | ## Output 47 | 48 | Display images/gifs/videos of output/result of your script so that users can visualize it 49 | 50 | 51 | ## Author(s) 52 | 53 | Name(s) of author(s) 54 | 55 | 56 | ## Disclaimers, if any 57 | 58 | Use this section to mention if any particular disclaimer is required 59 | -------------------------------------------------------------------------------- /.github/README/readme2_template.md: -------------------------------------------------------------------------------- 1 | **PROJECT TITLE** 2 | 3 | The project title should be "Name of the Algorithm" 4 | 5 | **INTRODUCTION** 6 | 7 | What's the project you had taken to explain this algorithm 8 | 9 | **DATASET** 10 | 11 | Add a link to dataset and from where it's taken to explain this algorithm. 12 | 13 | **PURPOSE** 14 | 15 | What's the purpose of this algorithm 16 | 17 | **BRIEF EXPLANATION** 18 | 19 | Explain briefly about the algorithm 20 | 21 | **WORKING OF ALGORITHM** 22 | 23 | Write down the step by step procedure of how algorithm works using points. 24 | 25 | **USAGE** 26 | 27 | Why have you choosed this algorithm should be stated 28 | 29 | **USE CASES** 30 | 31 | Explain few examples where this can work and provide good efficiency 32 | 33 | **LIBRARIES USED** 34 | 35 | Add all the libraries you had used to explain this algorithm 36 | 37 | **CONCLUSION** 38 | 39 | What's the conclusion on this algorithm 40 | 41 | **YOUR NAME** 42 | 43 | Add your full along with social media handles if applicable 44 | 45 | -------------------------------------------------------------------------------- /.github/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman 2 | -------------------------------------------------------------------------------- /.github/auto_assign.yml: -------------------------------------------------------------------------------- 1 | # Set to true to add reviewers to pull requests 2 | addReviewers: true 3 | # Set to true to add assignees to pull requests 4 | addAssignees: false 5 | # A list of reviewers to be added to pull requests (GitHub user name) 6 | reviewers: 7 | - prathimacode-hub 8 | -------------------------------------------------------------------------------- /.github/config.yml: -------------------------------------------------------------------------------- 1 | # Configuration for welcome - https://github.com/behaviorbot/welcome 2 | 3 | # Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome 4 | # Comment to be posted to on first time issues 5 | 6 | newIssueWelcomeComment: > 7 | Hello there! 👋🏻 Welcome to the PyAlgo-Tree! 🚀⚡️ 8 | 9 | Thank you and congrats 🎉 for opening your very first issue in this project. 10 | Please adhere to our [Code of Conduct](https://github.com/prathimacode-hub/PyAlgo-Tree/blob/main/CODE_OF_CONDUCT.md). 👍🏻 11 | You may submit a PR if you like, make sure to follow our [Pull Request Template](https://github.com/prathimacode-hub/PyAlgo-Tree/blob/main/.github/pullrequest_template.md). 12 | 13 | Feel free to get in touch with me through social media handles. Hope to see you there!😄 14 | 15 | # Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome 16 | # Comment to be posted to on PRs from first time contributors in your repository 17 | 18 | newPRWelcomeComment: > 19 | Hello there! 👋 Welcome to the project! 💖 20 | 21 | Thank you and congrats 🎉 for opening your first pull request. 22 | Please adhere to our [Code of Conduct](https://github.com/prathimacode-hub/PyAlgo-Tree/blob/main/CODE_OF_CONDUCT.md). 🙌🏻 We will get back to you as soon as we can. 😄 23 | 24 | Feel free to get in touch with me through social media handles. Hope to see you there!😄 25 | 26 | # Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge 27 | # Comment to be posted to on pull requests merged by a first time user 28 | 29 | firstPRMergeComment: > 30 | Congrats on merging your first Pull Request! 🎉 All the best for your amazing open source journey ahead. 🚀⚡️ 31 | -------------------------------------------------------------------------------- /.github/issue_template/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | Title: Project Title 3 | About: Create a report to help us improve. 4 | Name: YourName 5 | Label: Bug Report 6 | Assignee: '' 7 | 8 | --- 9 | 10 | Define You: 11 | 12 | - [ ] Hacktoberfest2022 Participant 13 | - [ ] Contributor 14 | 15 | 16 | 17 | 18 | **Describe the Bug** 19 | 20 | 21 | 22 | **Steps to Reproduce** 23 | 24 | Steps to reproduce the behavior: 25 | 26 | 1. 27 | 2. 28 | 3. 29 | 4. 30 | 31 | **Expected Behavior** 32 | 33 | 34 | 35 | **Actual Behavior** 36 | 37 | 38 | 39 | **Screenshots** 40 | 41 | 42 | 43 | **Additional Details** 44 | 45 | 46 | -------------------------------------------------------------------------------- /.github/issue_template/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | Title: Project Title 3 | About: Suggest an idea for this project 4 | Name: YourName 5 | Label: Feature Request 6 | Assignee: '' 7 | 8 | --- 9 | 10 | Define You: 11 | 12 | - [ ] Hacktoberfest2022 Participant 13 | - [ ] Contributor 14 | 15 | 16 | 17 | 18 | **Is your feature request related to a problem? Please describe.** 19 | 20 | 21 | 22 | **Describe the solution you'd like...** 23 | 24 | 25 | 26 | **Describe alternatives you've considered?** 27 | 28 | 29 | 30 | **Approach to be followed (optional):** 31 | 32 | 33 | 34 | **Additional context** 35 | 36 | 37 | -------------------------------------------------------------------------------- /.github/labels.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "good first issue", 4 | "description": "This issue is good for first timers", 5 | "color": "a9e3ff" 6 | }, 7 | { 8 | "name": "🆘 help wanted", 9 | "description": "This issue needs help ! Please help if possible !", 10 | "color": "ff00ff" 11 | }, 12 | { 13 | "name": "🟧 Level3 ", 14 | "description": "This issue will be considered as level 3 issue for DCP21.Points will be 40.", 15 | "color": "ff9f1c" 16 | }, 17 | { 18 | "name": "🟨 Level2 ", 19 | "description": "This issue will be considered as level 2 issue for DCP21.Points will be 20", 20 | "color": "ffcc00" 21 | }, 22 | { 23 | "name": "🟩 Level1 ", 24 | "description": "This issue will be considered as level 1 issue for DCP21.Points will be 10", 25 | "color": "cfda2c" 26 | }, 27 | { 28 | "name": "🟪 Level0 ", 29 | "description": "This issue will be considered as level 0 issue for DCP21.Points will be 5", 30 | "color": "aa00de" 31 | }, 32 | { 33 | "name": " DCP21 ", 34 | "description": "This issue will be considered for DCP21", 35 | "color": "d93f0b" 36 | }, 37 | { 38 | "name": " 🤩 Up for Grab ", 39 | "description": "This issue will is not assigned ! Grab It !", 40 | "color": "bf00ff" 41 | } 42 | ] 43 | -------------------------------------------------------------------------------- /.github/opensource_programs.md: -------------------------------------------------------------------------------- 1 | # Open Source Events 2 | 3 | List of Open Source Events in which this project participated. 4 | 5 | - DevIncept Contribution Program (DevIncept Codes) 6 | 7 | For developers By developers!!!🚀 8 | DevIncept is a community coming from different backgrounds with common zeal and enthusiasm for learning, sharing and writing. Skills here varies from a beginner to pro. 9 | 10 | It's a 30days Contribution Open Source Program to bring students into the world of open source development. There is no restriction in technology, framework or language, and as well everyone from beginner to expert is welcomed to join this program. This is all about open source. 11 | 12 | 13 | 14 | - Hacktoberfest 2022 15 | 16 | HACKTOBERFEST IS FOR EVERYONE. WHETHER IT’S YOUR FIRST TIME—OR YOUR NINTH—IT’S ALMOST TIME TO HACK OUT FOUR PRISTINE PULL/MERGE REQUESTS AND COMPLETE YOUR MISSION FOR OPEN SOURCE. IT ISN’T ALL ABOUT CODE. ANYONE WHO WRITES, DESIGNS, TESTS, MENTORS, OR ORGANIZES OFFERS MUCH NEEDED SUPPORT FOR OPEN-SOURCE PROJECTS ALL OVER THE WORLD. 17 | 18 | 19 | -------------------------------------------------------------------------------- /.github/pullrequest_template.md: -------------------------------------------------------------------------------- 1 | ## Related Issue 2 | 3 | - Info about the related issue 4 | 5 | - [ ] Hacktoberfest2022 Participant 6 | - [ ] Contributor 7 | 8 | Closes: #issue number that will be closed through this PR 9 | 10 | ### Describe the changes you've made 11 | 12 | Give a clear description what modifications you have made 13 | 14 | ## Type of change 15 | 16 | What sort of change have you made: 17 | 21 | - [ ] Bug fix (non-breaking change which fixes an issue) 22 | - [ ] New feature (non-breaking change which adds functionality) 23 | - [ ] Code style update (formatting, local variables) 24 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 25 | - [ ] This change requires a documentation update 26 | 27 | ## How Has This Been Tested? 28 | 29 | Describe how have you verified the changes made 30 | 31 | ## Checklist: 32 | 36 | - [ ] My code follows the guidelines of this project. 37 | - [ ] I have performed a self-review of my own code. 38 | - [ ] I have commented my code, particularly whereever it was hard to understand. 39 | - [ ] I have made corresponding changes to the documentation. 40 | - [ ] My changes generate no new warnings. 41 | - [ ] I have added test cases that prove my fix is effective or that my feature works. 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /.github/workflows/issue-label.yml: -------------------------------------------------------------------------------- 1 | name: Default 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Label Syncer 11 | uses: micnncim/action-label-syncer@v1.3.0 12 | env: 13 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 14 | GITHUB_REPOSITORY: ${{ github.repository }} 15 | with: 16 | manifest: .github/labels.json 17 | prune: false 18 | -------------------------------------------------------------------------------- /.github/workflows/reviewer_auto_assigner.yml: -------------------------------------------------------------------------------- 1 | name: 'Auto Assign PR Reviewers' 2 | on: pull_request_target 3 | 4 | jobs: 5 | add-reviews: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: kentaro-m/auto-assign-action@v1.1.1 9 | -------------------------------------------------------------------------------- /Algebra/Algebra Operation/Images/IMG_20211003_002224.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Algebra/Algebra Operation/Images/IMG_20211003_002224.jpg -------------------------------------------------------------------------------- /Algebra/Algebra Operation/Images/IMG_20211003_002329.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Algebra/Algebra Operation/Images/IMG_20211003_002329.jpg -------------------------------------------------------------------------------- /Algebra/Algebra Operation/Images/IMG_20211003_002355.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Algebra/Algebra Operation/Images/IMG_20211003_002355.jpg -------------------------------------------------------------------------------- /Algebra/Algebra Operation/Images/IMG_20211003_002420.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Algebra/Algebra Operation/Images/IMG_20211003_002420.jpg -------------------------------------------------------------------------------- /Algebra/Algebra Operation/Images/IMG_20211003_002437.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Algebra/Algebra Operation/Images/IMG_20211003_002437.jpg -------------------------------------------------------------------------------- /Algebra/Algebra Operation/Images/IMG_20211003_002512.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Algebra/Algebra Operation/Images/IMG_20211003_002512.jpg -------------------------------------------------------------------------------- /Algebra/Algebra Operation/Images/IMG_20211003_002530.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Algebra/Algebra Operation/Images/IMG_20211003_002530.jpg -------------------------------------------------------------------------------- /Algebra/Algebra Operation/Images/IMG_20211003_002554.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Algebra/Algebra Operation/Images/IMG_20211003_002554.jpg -------------------------------------------------------------------------------- /Algebra/Algebra Operation/algebra.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | ## VECTOR AND ARRAY OPERATIONS 3 | # Creating 3x4 Matrix 4 | a = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]]) 5 | print(a) 6 | # Create vector of 5 elements 7 | B = np.array([5,6,8,9,7]) 8 | print(B) 9 | # Multiplication of Array 10 | o = np.array([2,3,4,5]) 11 | o*2 12 | print(o) 13 | # Random array creation 14 | C = np.random.randint(10, size=(3,3)) 15 | print(C.shape) 16 | print(C.size) 17 | print(C) 18 | # Dot Product of Matrix 19 | d = np.array([9,8,0]) 20 | e = np.array([6,6,6]) 21 | print(np.dot(d,e)) 22 | # Addition and Subtraction of Matrix 23 | i = np.array([1,2,3]) 24 | k = np.array([1,2,3]) 25 | print("i + k is {}".format(i + k)) 26 | print("i - k is {}".format(i - k)) 27 | # Identity Matrix 28 | I3 = np.identity(3, dtype = int) 29 | print(I3) 30 | # Transpose of Matrix 31 | print(e) 32 | print(e.T) 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Algebra/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Arithmetic/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Arrays/Array Operations/Images/Output1_part1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Arrays/Array Operations/Images/Output1_part1.png -------------------------------------------------------------------------------- /Arrays/Array Operations/Images/Output1_part2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Arrays/Array Operations/Images/Output1_part2.png -------------------------------------------------------------------------------- /Arrays/Array Operations/Images/Output1_part3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Arrays/Array Operations/Images/Output1_part3.png -------------------------------------------------------------------------------- /Arrays/Array Operations/Images/Output1_part4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Arrays/Array Operations/Images/Output1_part4.png -------------------------------------------------------------------------------- /Arrays/Array Operations/Images/Output1_part5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Arrays/Array Operations/Images/Output1_part5.png -------------------------------------------------------------------------------- /Arrays/Array Operations/Images/Output1_part6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Arrays/Array Operations/Images/Output1_part6.png -------------------------------------------------------------------------------- /Arrays/Array Operations/Images/Output1_part7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Arrays/Array Operations/Images/Output1_part7.png -------------------------------------------------------------------------------- /Arrays/Array Operations/requirements.txt: -------------------------------------------------------------------------------- 1 | 2 | Requirements 3 | -- Tools 4 | 1. Install python 3 5 | 2. Any IDE's, I have used Pycharm IDE. 6 | 7 | -Modules required 8 | Array Module (inbuilt) 9 | This module defines an object type which can compactly represent 10 | an array of basic values: characters, integers, floating point numbers. 11 | 12 | - Steps to run: 13 | 1. Install python 3 14 | 2. Open the IDE or python console 15 | 3. Enter $ python3 File_name.py to run the code. 16 | 17 | IDE:- 18 | I have used PyCharm, it is a dedicated Python Integrated Development Environment (IDE) 19 | providing a wide range of essential tools for Python developers, tightly integrated 20 | to create a convenient environment for productive Python, web, and data science development. 21 | 22 | Requirements 23 | -- Tools 24 | 1. Install python 3 25 | 2. Any IDE's, I have used Pycharm IDE. 26 | 27 | -Modules required 28 | Array Module (inbuilt) 29 | This module defines an object type which can compactly represent 30 | an array of basic values: characters, integers, floating point numbers. 31 | 32 | - Steps to run: 33 | 1. Install python 3 34 | 2. Open the IDE or python console 35 | 3. Enter $ python3 File_name.py to run the code. 36 | 37 | IDE:- 38 | I have used PyCharm, it is a dedicated Python Integrated Development Environment (IDE) 39 | providing a wide range of essential tools for Python developers, tightly integrated to 40 | create a convenient environment for productive Python, web, and data science development. 41 | 42 | -------------------------------------------------------------------------------- /Arrays/Divisor Sum/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Arrays/Divisor Sum/Images/ss.png -------------------------------------------------------------------------------- /Arrays/Divisor Sum/README.md: -------------------------------------------------------------------------------- 1 | # Divisor Sum 2 | 3 | ## Aim 4 | 5 | Calculate the sum of all the divisors of the entered number and display it. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to work with arrays. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - We can find the factors of a number by trying to divide it from all the numbers from 1 to the number itself+1. 16 | - All these divisors leave no remainders. 17 | - Such numbers are appended into list. 18 | - The sum of this list is what that is required. 19 | 20 | 21 | ## Workflow of the Project 22 | 23 | Description of functions used in the code and their purpose: 24 | 25 | divisorSum --> Function to find out all divisors and add them up. 26 | 27 | The input is sent to the function which computes the result. 28 | 29 | 30 | ## Compilation Steps 31 | 32 | After the script is run, enter: 33 | 34 | 1. A number. 35 | 36 | That's it! The sum of all its divisors would be printed out. 37 | 38 | 39 | ## Output 40 | 41 | 42 | 43 | 44 | ## Author 45 | 46 | [Manasi Chhibber](https://github.com/Manasi2001) 47 | 48 | -------------------------------------------------------------------------------- /Arrays/Divisor Sum/divisor_sum.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Aim: Calculate the sum of all the divisors of the entered number and display it. 3 | 4 | ''' 5 | 6 | # function to find out all divisors and add them up 7 | def divisorSum(n): 8 | temp = [] 9 | for i in range(1, n+1): 10 | # condition for finding factors 11 | if n%i == 0: 12 | temp.append(i) 13 | # adding all divisors 14 | return sum(temp) 15 | 16 | # getting the input 17 | n = int(input()) 18 | # printing the result 19 | print(divisorSum(n)) 20 | 21 | ''' 22 | COMPLEXITY: 23 | 24 | Time Complexity -> O(N) 25 | Space Complexity -> O(1) 26 | 27 | Sample Input: 28 | 6 29 | Sample Output: 30 | 12 31 | 32 | Explaination: 33 | Divisors/Factors of 6 are --> 1,2,3 and 6. 34 | Adding them up --> 1+2+3+6 = 12. 35 | 36 | ''' -------------------------------------------------------------------------------- /Arrays/README.md: -------------------------------------------------------------------------------- 1 | # Arrays 2 | 3 | ## Check out all the amazing scripts using 'Arrays' here: 4 | 5 | - [Array Operations](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Arrays/Array%20Operations) 6 | - [Divisor Sum](Divisor%20Sum/divisor_sum.py) 7 | - [Trapping Rainwater](Trapping%20Rainwater) 8 | -------------------------------------------------------------------------------- /Arrays/Trapping Rainwater/Images/outputimg5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Arrays/Trapping Rainwater/Images/outputimg5.jpg -------------------------------------------------------------------------------- /Arrays/Trapping Rainwater/README.md: -------------------------------------------------------------------------------- 1 | # Trapping Rainwater 2 | 3 | ## Aim 4 | 5 | Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. 6 | 7 | ## Purpose 8 | 9 | The purpose is to work with arrays. 10 | 11 | 12 | ## Short description of package/script 13 | 14 | - Traverse the array from left to right. 15 | - For every element, traverse the array from start to that index and find the maximum height and traverse the array from the current index to end, and find the maximum height. 16 | - The amount of water that will be stored in this column is minimum of both the heights – array[i], add this value to the total amount of water stored. 17 | - Print the total amount of water stored. 18 | 19 | 20 | ## Workflow of the Project 21 | 22 | Description of functions used in the code and their purpose: 23 | 24 | maxWater- Function to find maximum water stored. 25 | The input is sent to the function which returns the result. 26 | 27 | 28 | ## Compilation Steps 29 | 30 | After the script is run, enter: 31 | 32 | 1. Size of Array. 33 | 2. Elements of array. 34 | 35 | The maximum water stored is printed. 36 | 37 | 38 | ## Output 39 | 40 | ![](Images/outputimg5.jpg) 41 | 42 | 43 | ## Author 44 | 45 | [SiddhiBhanushali](https://github.com/siddhi-244) 46 | -------------------------------------------------------------------------------- /Arrays/Trapping Rainwater/trapping_rainwater.py: -------------------------------------------------------------------------------- 1 | def maxWater(arr, n) : 2 | 3 | # To store the maximum water 4 | # that can be stored 5 | 6 | res = 0 7 | 8 | # For every element of the array 9 | 10 | for i in range(1, n - 1) : 11 | # Find the maximum element on its left 12 | left = arr[i]; 13 | for j in range(i) : 14 | left = max(left, arr[j]); 15 | # Find the maximum element on its right 16 | right = arr[i]; 17 | 18 | for j in range(i + 1 , n) : 19 | right = max(right, arr[j]); # Update the maximum water 20 | 21 | res = res + (min(left, right) - arr[i]); 22 | 23 | 24 | return res 25 | 26 | if __name__ == "__main__" : 27 | 28 | 29 | arr = []; 30 | n = int(input()) 31 | for i in range(n): 32 | e=int(input()) 33 | arr.append(e) 34 | 35 | print("Output",maxWater(arr, n)); -------------------------------------------------------------------------------- /Artificial Intelligence/8 Puzzle Problem using A star Algorithm/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Artificial Intelligence/8 Puzzle Problem using A star Algorithm/Images/ss.png -------------------------------------------------------------------------------- /Artificial Intelligence/8 Puzzle Problem using BFS/Images/ss1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Artificial Intelligence/8 Puzzle Problem using BFS/Images/ss1.png -------------------------------------------------------------------------------- /Artificial Intelligence/8 Puzzle Problem using BFS/Images/ss2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Artificial Intelligence/8 Puzzle Problem using BFS/Images/ss2.png -------------------------------------------------------------------------------- /Artificial Intelligence/8 Puzzle Problem using BFS/Images/ss3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Artificial Intelligence/8 Puzzle Problem using BFS/Images/ss3.png -------------------------------------------------------------------------------- /Artificial Intelligence/8 Puzzle Problem using BFS/Images/ss4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Artificial Intelligence/8 Puzzle Problem using BFS/Images/ss4.png -------------------------------------------------------------------------------- /Artificial Intelligence/README.md: -------------------------------------------------------------------------------- 1 | # Artificial Intelligence 2 | 3 | ## Check out all the amazing scripts using 'Artificial Intelligence' here: 4 | 5 | - [8 Puzzle Problem using A star Algorithm](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Artificial%20Intelligence/8%20Puzzle%20Problem%20using%20A%20star%20Algorithm) 6 | 7 | - [8 Puzzle Problem using BFS](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Artificial%20Intelligence/8%20Puzzle%20Problem%20using%20BFS) 8 | 9 | -------------------------------------------------------------------------------- /Backtracking/Cryptarithmetic Problem/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Cryptarithmetic Problem/Images/ss.png -------------------------------------------------------------------------------- /Backtracking/Cryptarithmetic Problem/README.md: -------------------------------------------------------------------------------- 1 | # Cryptarithmetic Problem 2 | 3 | ## Aim 4 | 5 | Cryptarithmetic problems are mathematical puzzles where digits are replaced by symbols. The aim is to find unique digits(0-9) that the letters should represent, such that they satisfy the given constraints. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to come up with a solution for SEND MORE MONEY Cryptarithmetic problem using backtracking. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | The cryptarithmetic problem that is needed to be solved here is: 16 | 17 | 18 | 19 | Distinct variables are: S, E, N, D, M, O, R, Y 20 | 21 | Domain: {0,...,9} 22 | 23 | 24 | ## Workflow of the Project 25 | 26 | Description of functions used in the code and their purpose: 27 | 28 | add_constraint --> This method adds constraint to variables as per their domains. 29 | 30 | consistent --> This method checks if the value assignment is consistent by checking all constraints. 31 | 32 | backtracking_search --> This method is performing the backtracking search to find the result. 33 | 34 | satisfied --> This method makes sure that only unique values get assigned. If there are duplicate values then it's not a solution. 35 | 36 | 37 | ## Compilation Steps 38 | 39 | Just run the script and solution will get printed. You'll see a unique number from 0-9 associated with each unique alphabet. 40 | 41 | 42 | ## Output 43 | 44 | 45 | 46 | 47 | ## Author 48 | 49 | [Manasi Chhibber](https://github.com/Manasi2001) 50 | -------------------------------------------------------------------------------- /Backtracking/Graph Coloring Problem/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Graph Coloring Problem/Images/ss.png -------------------------------------------------------------------------------- /Backtracking/Graph Coloring Problem/README.md: -------------------------------------------------------------------------------- 1 | # Graph Coloring Problem 2 | 3 | ## Aim 4 | 5 | Given an undirected graph and an integer M. The task is to determine if the graph can be colored with at most M colors such that no two adjacent vertices of the graph are colored with the same color. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to come up with a solution for this problem (if possible) using backtracking. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - The user enters the number of vertices, number of unique colours and the edges for the graph. 16 | - Backtracking is used for check that all the places are filled with diferent colours according to the rule. 17 | - If a solution is possible, 1 is printed out, else 0. 18 | 19 | 20 | ## Workflow of the Project 21 | 22 | Description of functions used in the code and their purpose: 23 | 24 | isSafe --> This checks whether if it safe to color the given node with a particular color i.e checking if the adjacent nodes are different from each other. 25 | 26 | check --> This function iteratively checks different combinations. 27 | 28 | graphcoloring --> This method assigns colors to different nodes. 29 | 30 | After the desired values are entered by the user, the 'graphcoloring' method is called, which sends the control to 'check' function after initializing nodes with different colours. 'isSafe' method is then called to verify that the rules are being followed. 31 | 32 | 33 | ## Compilation Steps 34 | 35 | After the script is run, enter: 36 | 37 | 1. No. of test cases. 38 | 2. Number of vertices. 39 | 3. Total number of unu=ique colours, M. 40 | 4. All edges. 41 | 42 | That's it! If the solution is possible, 1 will get printed, else 0 will get printed. 43 | 44 | 45 | ## Output 46 | 47 | 48 | 49 | 50 | ## Author 51 | 52 | [Manasi Chhibber](https://github.com/Manasi2001) 53 | -------------------------------------------------------------------------------- /Backtracking/Hamiltonian Cycle/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Hamiltonian Cycle/Images/ss.png -------------------------------------------------------------------------------- /Backtracking/Hamiltonian Cycle/README.md: -------------------------------------------------------------------------------- 1 | # Hamiltonian Cycle 2 | 3 | ## Aim 4 | 5 | A Hamiltonian path (or traceable path) is a path in an undirected or directed graph that visits each vertex exactly once. A Hamiltonian cycle (or Hamiltonian circuit) is a Hamiltonian path that is a cycle. The aim is to determine the existance of a Hamiltonian Cycle in the provided undirected graph and return the path if such path exist. The nodes are numbered from 1 to N. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to come up with a solution for this problem (if possible) using backtracking. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - Based on user's choice, the graph is initialized. 16 | - Backtracking is used for keeping track of all the nodes visited already. 17 | - If a solution is possible, it is printed out. 18 | 19 | 20 | ## Workflow of the Project 21 | 22 | Description of functions used in the code and their purpose: 23 | 24 | Move_next_node --> Method to visit the next node in the cycle. 25 | 26 | Hamiltonial_Cycle --> Method to keep a track of already visited node and the answer. 27 | 28 | After the desired values are entered by the user, the control is given to 'Hamiltonial_Cycle' function which calls 'Move_next_node' function to recursively look for a solution. 29 | 30 | 31 | ## Compilation Steps 32 | 33 | After the script is run, enter: 34 | 35 | 1. The number of vertex and edges. 36 | 2. The edges. 37 | 38 | That's it! If hamiltonian cycle exists, the result will get printed. 39 | 40 | 41 | ## Output 42 | 43 | 44 | 45 | 46 | ## Author 47 | 48 | [Manasi Chhibber](https://github.com/Manasi2001) 49 | -------------------------------------------------------------------------------- /Backtracking/Knight's Tour/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Knight's Tour/Images/ss.png -------------------------------------------------------------------------------- /Backtracking/Knight's Tour/README.md: -------------------------------------------------------------------------------- 1 | # Knight's Tour 2 | 3 | ## Aim 4 | 5 | To check whether it is possible for a Knight to visit each cell of the N*N chessboard without visiting any cell twice starting from (X, Y) position. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to come up with a solution for this problem (if possible) using backtracking. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - Based on user's choice, the size of the chessboard is decided. 16 | - Backtracking is used for keeping track of all visited places on the chessboard. 17 | - If a solution is possible, it is printed out. 18 | 19 | 20 | ## Workflow of the Project 21 | 22 | Description of functions used in the code and their purpose: 23 | 24 | move_Knight --> The method to position knight on various coordinates according to the 2+1/2 step move style. 25 | 26 | Knight_Tour --> The method to allot a set of possible moves and keep track of all the visited places on the chessboard. 27 | 28 | After the desired size of chessboard is entered by the user, 'Knight_Tour' function is called to check for the validity of moves and 'move_Knight' to place the knight on all possible coordinates. 29 | 30 | 31 | ## Compilation Steps 32 | 33 | After the script is run, enter: 34 | 35 | 1. The desired chessboard size. 36 | 37 | That's it! If the solution is possible, it will get printed. 38 | 39 | 40 | ## Output 41 | 42 | 43 | 44 | 45 | ## Author 46 | 47 | [Manasi Chhibber](https://github.com/Manasi2001) 48 | 49 | 50 | -------------------------------------------------------------------------------- /Backtracking/N Queens/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/N Queens/Images/ss.png -------------------------------------------------------------------------------- /Backtracking/N Queens/README.md: -------------------------------------------------------------------------------- 1 | # N Queens 2 | 3 | ## Aim 4 | 5 | To place N queens in a N*N Chessboard such that no two queens attack each other. A queen is said to be attacked by another queen if they share same diagonal(right/left), Row or Column. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to come up with a solution for this problem (if possible) using backtracking. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - Based on user's choice, the size of the chessboard is decided. 16 | - Backtracking is used for keeping track of all the possible positions on the chessboard. 17 | - If a solution is possible, it is printed out. 18 | 19 | 20 | ## Workflow of the Project 21 | 22 | Description of functions used in the code and their purpose: 23 | 24 | n_queens --> Method to keep track of occupied and vacant places. 25 | 26 | place_queen --> Recursive method to find vacant spaces and place the queens. 27 | 28 | After the desired values are entered by the user, the 'n_queen' function checks for vacant spaces and then for finding solution, the control is shifted to 'place_queen' function. 29 | 30 | 31 | ## Compilation Steps 32 | 33 | After the script is run, enter: 34 | 35 | 1. Board size. 36 | 37 | That's it! If the solution is possible, it will get printed. 38 | 39 | 40 | ## Output 41 | 42 | 43 | 44 | 45 | ## Author 46 | 47 | [Manasi Chhibber](https://github.com/Manasi2001) 48 | -------------------------------------------------------------------------------- /Backtracking/README.md: -------------------------------------------------------------------------------- 1 | # Backtracking 2 | 3 | ## Check out all the amazing scripts using 'Backtracking' here: 4 | 5 | - [Cryptarithmetic Problem](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Backtracking/Cryptarithmetic%20Problem) 6 | 7 | - [Graph Coloring Problem](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Backtracking/Graph%20Coloring%20Problem) 8 | 9 | - [Hamiltonian Cycle](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Backtracking/Hamiltonian%20Cycle) 10 | 11 | - [Knight's Tour](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Backtracking/Knight's%20Tour) 12 | 13 | - [N Queens](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Backtracking/N%20Queens) 14 | 15 | - [Subset Sum](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Backtracking/Subset%20Sum) 16 | 17 | - [Sudoku Solver](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Backtracking/Sudoku%20Solver) 18 | 19 | - [Tic Tac Toe Game](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Backtracking/Tic%20Tac%20Toe%20Game) 20 | 21 | - [Water Jug Problem](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Backtracking/Water%20Jug%20Problem) 22 | 23 | 24 | -------------------------------------------------------------------------------- /Backtracking/Rat in a Maze/Images/rat1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Rat in a Maze/Images/rat1.PNG -------------------------------------------------------------------------------- /Backtracking/Rat in a Maze/Images/rat2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Rat in a Maze/Images/rat2.PNG -------------------------------------------------------------------------------- /Backtracking/Rat in a Maze/Images/rat3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Rat in a Maze/Images/rat3.PNG -------------------------------------------------------------------------------- /Backtracking/Subset Sum/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Subset Sum/Images/ss.png -------------------------------------------------------------------------------- /Backtracking/Subset Sum/README.md: -------------------------------------------------------------------------------- 1 | # Subset Sum 2 | 3 | ## Aim 4 | 5 | From a list of integers, the aim is to check and return a set of integers whose sum will be equal to the target value K. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to solve this problem using backtracking. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - The user provides the list of integers and target value K. 16 | - Recursively, multiple subsets (combinations of integers) are made. 17 | - If the desired value is reached, the subset gets printed. 18 | 19 | 20 | ## Workflow of the Project 21 | 22 | Description of functions used in the code and their purpose: 23 | 24 | Subset_Sum --> Main Recursive function to find the desired Subset Sum. 25 | 26 | In every consequent iteration, each integer gets subtracted from target value and gets added to a (temporary) subset. 27 | 28 | 29 | ## Compilation Steps 30 | 31 | After the script is run, enter: 32 | 33 | 1. The list of integers. 34 | 2. The target value. 35 | 36 | That's it! If a valid subset exists, it will get printed. 37 | 38 | ## Output 39 | 40 | 41 | 42 | 43 | ## Author 44 | 45 | [Manasi Chhibber](https://github.com/Manasi2001) 46 | -------------------------------------------------------------------------------- /Backtracking/Subset Sum/subset_sum.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Aim: From a list of integers, check and return a set of integers whose sum 3 | will be equal to the target value K. 4 | 5 | ''' 6 | 7 | # Main Recursive function to find the desired Subset Sum 8 | def Subset_Sum(li, target, ans=[]): 9 | 10 | # Base Cases 11 | if target == 0 and ans != []: 12 | return ans 13 | 14 | elif li == []: 15 | return False 16 | 17 | # li[0] is not included in the answer Subset 18 | temp = Subset_Sum(li[1:], target, ans) 19 | if temp: 20 | return temp 21 | 22 | # li[0] included in the answer Subset 23 | temp = Subset_Sum(li[1:], target - li[0], ans + [li[0]]) 24 | 25 | return temp 26 | 27 | # --------------------------- DRIVER CODE------------------------------ 28 | 29 | if __name__ == "__main__": 30 | 31 | li = [int(i) for i in input("Enter the List of Integers: ").split()] 32 | Target = int(input("Enter the Target value: ")) 33 | 34 | ans = Subset_Sum(li, Target) 35 | if not ans: 36 | print("No Subset Sum matched to the Target") 37 | else: 38 | print("The Required Subset is : ", *ans) 39 | 40 | ''' 41 | Sample Input: 42 | Enter the List of Integers: -1 2 6 7 -4 7 5 -2 43 | Enter the Target value: 0 44 | 45 | Sample Output: 46 | The Required Subset is : 6 -4 -2 47 | 48 | Explanation: 49 | 6 - 4 - 2 = 0, the required result 50 | 51 | COMPLEXITY: 52 | 53 | Time Complexity: O(2^N) 54 | Space complexity: O(N) 55 | 56 | ''' -------------------------------------------------------------------------------- /Backtracking/Sudoku Solver/Images/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Sudoku Solver/Images/output.png -------------------------------------------------------------------------------- /Backtracking/Sudoku Solver/Images/output_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Sudoku Solver/Images/output_error.png -------------------------------------------------------------------------------- /Backtracking/Sudoku Solver/Images/sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Sudoku Solver/Images/sample.png -------------------------------------------------------------------------------- /Backtracking/Tic Tac Toe Game/Images/ss1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Tic Tac Toe Game/Images/ss1.png -------------------------------------------------------------------------------- /Backtracking/Tic Tac Toe Game/Images/ss2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Tic Tac Toe Game/Images/ss2.png -------------------------------------------------------------------------------- /Backtracking/Tic Tac Toe Game/README.md: -------------------------------------------------------------------------------- 1 | # Tic Tac Toe Game 2 | 3 | ## Aim 4 | 5 | The aim is to build a Tic Tac Toe Game using minimax algorithm. 6 | 7 | 8 | ## Purpose 9 | 10 | To create a two-player fun game in python. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - The problem is solved using minimax algorithm. 16 | - Backtracking is used for keeping track of all states in the game. 17 | 18 | 19 | ## Workflow of the Project 20 | 21 | Description of functions used in the code and their purpose: 22 | 23 | play_move --> Method for checking the correct move on Tic-Tac-Toe. 24 | 25 | copy_game_state --> Method to copy the current game state to new_state of Tic-Tac-Toe. 26 | 27 | check_current_state --> Method to check the current state of the Tic-Tac-Toe. 28 | 29 | print_board --> Method to print the Tic-Tac-Toe Board. 30 | 31 | getBestMove --> Method for implement the Minimax Algorithm. 32 | 33 | After the desired values are entered by the user, the 'play_move' function gains control and the game begins. 34 | 35 | 36 | ## Compilation Steps 37 | 38 | After the script is run, enter: 39 | 40 | 1. Choose whether you want to go first or after computer. 41 | 2. Accordingly take turns and make your choices. 42 | 3. When the winning pattern is detected, the winner is declared. 43 | 44 | That's it! All the states will be listed too. 45 | 46 | 47 | ## Output 48 | 49 | 50 | 51 | 52 | 53 | ## Author 54 | 55 | [Manasi Chhibber](https://github.com/Manasi2001) 56 | 57 | -------------------------------------------------------------------------------- /Backtracking/Water Jug Problem/Images/ss1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Water Jug Problem/Images/ss1.png -------------------------------------------------------------------------------- /Backtracking/Water Jug Problem/Images/ss2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Water Jug Problem/Images/ss2.png -------------------------------------------------------------------------------- /Backtracking/Water Jug Problem/Images/ss3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Water Jug Problem/Images/ss3.png -------------------------------------------------------------------------------- /Backtracking/Water Jug Problem/Images/ss4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Backtracking/Water Jug Problem/Images/ss4.png -------------------------------------------------------------------------------- /Bit Manipulation/Count Set Bits in an integer/Images/cover_pic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Bit Manipulation/Count Set Bits in an integer/Images/cover_pic.png -------------------------------------------------------------------------------- /Bit Manipulation/Count Set Bits in an integer/Images/io_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Bit Manipulation/Count Set Bits in an integer/Images/io_1.png -------------------------------------------------------------------------------- /Bit Manipulation/Count Set Bits in an integer/Images/io_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Bit Manipulation/Count Set Bits in an integer/Images/io_2.png -------------------------------------------------------------------------------- /Bit Manipulation/Count Set Bits in an integer/brian_kernighans_algo.py: -------------------------------------------------------------------------------- 1 | # Brian Kernighan's algorithm to count the total number of set bits in `n` 2 | def countSetBits(n): 3 | 4 | count = 0 5 | while (n): 6 | 7 | print("{:032b}".format(n)) 8 | n = n&(n-1) 9 | count+= 1 10 | 11 | return count 12 | 13 | if __name__ == '__main__': 14 | n = int(input("n = ")) 15 | print("Set Bits :",countSetBits(n)) -------------------------------------------------------------------------------- /Bit Manipulation/Count Set Bits in an integer/brute_approach.py: -------------------------------------------------------------------------------- 1 | # Naive solution to count the total number of set bits in `n` 2 | def countSetBits(N): 3 | count = 0 4 | 5 | for i in range(32): 6 | if(N & (1 << i)): 7 | count += 1 8 | return count 9 | 10 | 11 | if __name__ == '__main__': 12 | n = int(input("n = ")) 13 | print("Set Bits :",countSetBits(n)) 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Bit Manipulation/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Blockchain/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Ciphers/Affine Cipher/Images/Affine Cipher_Output-2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Ciphers/Affine Cipher/Images/Affine Cipher_Output-2.jpeg -------------------------------------------------------------------------------- /Ciphers/Affine Cipher/Images/Affine Cipher_Output-3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Ciphers/Affine Cipher/Images/Affine Cipher_Output-3.jpeg -------------------------------------------------------------------------------- /Ciphers/Affine Cipher/Images/Affine Cipher_Output-4.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Ciphers/Affine Cipher/Images/Affine Cipher_Output-4.jpeg -------------------------------------------------------------------------------- /Ciphers/Affine Cipher/Images/Affine Cipher_Output.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Ciphers/Affine Cipher/Images/Affine Cipher_Output.jpeg -------------------------------------------------------------------------------- /Ciphers/Affine Cipher/requirements.txt: -------------------------------------------------------------------------------- 1 | Libraries Used: 2 | SystemRandom 3 | random 4 | ascii_lowercase 5 | -------------------------------------------------------------------------------- /Ciphers/Caesar Cipher/Images/Output_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Ciphers/Caesar Cipher/Images/Output_1.png -------------------------------------------------------------------------------- /Ciphers/Caesar Cipher/Images/Output_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Ciphers/Caesar Cipher/Images/Output_2.png -------------------------------------------------------------------------------- /Ciphers/Caesar Cipher/Images/Output_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Ciphers/Caesar Cipher/Images/Output_3.png -------------------------------------------------------------------------------- /Ciphers/README.md: -------------------------------------------------------------------------------- 1 | # Ciphers 2 | 3 | ## Check out all the amazing scripts using 'Ciphers' here: 4 | 5 | - [Vigenere Cipher](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Ciphers/Vigen%C3%A8re%20Cipher) 6 | 7 | 8 | -------------------------------------------------------------------------------- /Ciphers/Vigenère Cipher/Images/Decryption Mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Ciphers/Vigenère Cipher/Images/Decryption Mode.png -------------------------------------------------------------------------------- /Ciphers/Vigenère Cipher/Images/Encryption Mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Ciphers/Vigenère Cipher/Images/Encryption Mode.png -------------------------------------------------------------------------------- /Ciphers/Vigenère Cipher/Images/Vignere Table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Ciphers/Vigenère Cipher/Images/Vignere Table.png -------------------------------------------------------------------------------- /Ciphers/Vigenère Cipher/Vignere_Cipher.py: -------------------------------------------------------------------------------- 1 | LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 2 | def main(): 3 | Message = input("Messge:") #Input your message here that need to be encrypted or decrypted 4 | Key = input("Key:") #Input Key here 5 | Mode = input("Mode(encrypt / decrypt)") #Choose a mode i.e., to encrypt or decrypt 6 | 7 | if Mode.upper() == 'ENCRYPT': #Encrypt condition 8 | translated = encryptMessage(Key, Message) 9 | elif Mode.upper() == 'DECRYPT': #Decrypt condition 10 | translated = decryptMessage(Key, Message) 11 | 12 | print('%sed message:' % (Mode.title())) 13 | print(translated) 14 | print() 15 | 16 | 17 | def encryptMessage(key, message):#Encryption 18 | return translateMessage(key, message, 'encrypt') 19 | 20 | 21 | def decryptMessage(key, message):#Decryption 22 | return translateMessage(key, message, 'decrypt') 23 | 24 | 25 | def translateMessage(key, message, mode): #Translation 26 | translated = [] 27 | keyIndex = 0 28 | key = key.upper() 29 | 30 | for symbol in message: 31 | num = LETTERS.find(symbol.upper()) 32 | if num != -1: 33 | if mode == 'encrypt': #For encryption 34 | num += LETTERS.find(key[keyIndex]) 35 | elif mode == 'decrypt': #For decryption 36 | num -= LETTERS.find(key[keyIndex]) 37 | num %= len(LETTERS) 38 | 39 | if symbol.isupper(): 40 | translated.append(LETTERS[num]) 41 | elif symbol.islower(): 42 | translated.append(LETTERS[num].lower()) 43 | keyIndex += 1 44 | 45 | if keyIndex == len(key): 46 | keyIndex = 0 47 | else: 48 | translated.append(symbol) 49 | return ''.join(translated) 50 | 51 | 52 | if __name__ == '__main__': 53 | main() 54 | -------------------------------------------------------------------------------- /Compressions/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Computer Vision/Face Detection/face_detection.py: -------------------------------------------------------------------------------- 1 | import os 2 | import cv2 3 | 4 | # cascades: https://github.com/opencv/opencv/tree/master/data/haarcascades 5 | face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') 6 | 7 | 8 | def read_file(image_path): 9 | if os.path.isfile(image_path): 10 | img = cv2.imread(image_path) 11 | gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 12 | return True, img, gray 13 | 14 | else: 15 | return False, False 16 | 17 | 18 | while(True): 19 | input_path = str(input("Enter the path of the file: ")) 20 | val, img, gray = read_file(input_path) 21 | if val == True: 22 | break 23 | 24 | rects = face_cascade.detectMultiScale(gray, scaleFactor=1.05, 25 | minNeighbors=10, minSize=(30, 30), 26 | flags=cv2.CASCADE_SCALE_IMAGE) 27 | 28 | 29 | # loop over the bounding boxes 30 | for (x, y, w, h) in rects: 31 | # draw the face bounding box on the image 32 | cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2) 33 | 34 | 35 | # show the output image 36 | cv2.imshow("Image", img) 37 | cv2.waitKey(0) 38 | -------------------------------------------------------------------------------- /Computer Vision/Face Detection/images/Flow_FaceDetection_OpenCV.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Face Detection/images/Flow_FaceDetection_OpenCV.jpg -------------------------------------------------------------------------------- /Computer Vision/Face Detection/images/harry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Face Detection/images/harry.png -------------------------------------------------------------------------------- /Computer Vision/Face Detection/images/snape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Face Detection/images/snape.png -------------------------------------------------------------------------------- /Computer Vision/Face Detection/requirements.txt: -------------------------------------------------------------------------------- 1 | opencv_python==4.5.1.48 2 | -------------------------------------------------------------------------------- /Computer Vision/Face Recognition/Dataset/recognition_list.csv: -------------------------------------------------------------------------------- 1 | NAME,Time 2 | , 3 | BILL GATES,08:53:28 4 | ELON MUSK,08:55:06 5 | NARENDRA MODI,08:55:42 6 | -------------------------------------------------------------------------------- /Computer Vision/Face Recognition/Dataset/train_images/Bill Gates.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Face Recognition/Dataset/train_images/Bill Gates.jpg -------------------------------------------------------------------------------- /Computer Vision/Face Recognition/Dataset/train_images/Elon Musk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Face Recognition/Dataset/train_images/Elon Musk.jpg -------------------------------------------------------------------------------- /Computer Vision/Face Recognition/Dataset/train_images/Narendra Modi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Face Recognition/Dataset/train_images/Narendra Modi.jpg -------------------------------------------------------------------------------- /Computer Vision/Face Recognition/Images/Output/Name_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Face Recognition/Images/Output/Name_list.png -------------------------------------------------------------------------------- /Computer Vision/Face Recognition/Images/Output/Name_list1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Face Recognition/Images/Output/Name_list1.png -------------------------------------------------------------------------------- /Computer Vision/Face Recognition/Images/Output/outout3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Face Recognition/Images/Output/outout3.png -------------------------------------------------------------------------------- /Computer Vision/Face Recognition/Images/Output/output1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Face Recognition/Images/Output/output1.png -------------------------------------------------------------------------------- /Computer Vision/Face Recognition/Images/Output/output2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Face Recognition/Images/Output/output2.png -------------------------------------------------------------------------------- /Computer Vision/Face Recognition/Images/block Diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Face Recognition/Images/block Diagram.png -------------------------------------------------------------------------------- /Computer Vision/Face Recognition/Model/requirements.txt: -------------------------------------------------------------------------------- 1 | Requirements 2 | -- Tools 3 | 1. Install python 3 4 | 2. Any IDE's, I have used Pycharm IDE. 5 | 6 | Modules required 7 | MAIN- 8 | -OpenCV(CV2) 9 | -OS 10 | -Datetime 11 | -numpy 12 | -face-recognition 13 | Support 14 | -cmake 15 | -colorama 16 | -dlib 17 | -enum34 18 | -nicer 19 | -pip 20 | -pkt 21 | -pytz 22 | -setuptools 23 | -typing 24 | 25 | - Steps to run: 26 | 1. Install python 3 27 | 2. Open the IDE or python console 28 | 3. Enter $ python3 File_name.py to run the code. 29 | 30 | IDE:- 31 | I have used PyCharm, it is a dedicated Python Integrated Development Environment (IDE) 32 | providing a wide range of essential tools for Python developers, tightly integrated 33 | to create a convenient environment for productive Python, web, and data science development. 34 | 35 | Steps to run: 36 | st-1: 37 | Under files -> settings -> interpreter install all modules 38 | st-2: 39 | set Face_recognition1.py as the script file in path 40 | st-3: 41 | Add all Images to be trained under train_images folder in format 42 | Name.jpg or Name.jpeg 43 | 44 | st-4: 45 | You are set up can run the script -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/1.jpg -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/2.jpg -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/3.jpg -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/4.jpg -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/5.jpg -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/6.jpg -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/7.jpg -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/8.jpg -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/9.jpg -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/front1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/front1.png -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/front2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/front2.png -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/icon.ico -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/icon.jpg -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/image1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/image1.jpg -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/Images/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/Images/image2.png -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/frozen_inference_graph.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Computer Vision/Human Detection and Counting/frozen_inference_graph.pb -------------------------------------------------------------------------------- /Computer Vision/Human Detection and Counting/requirements.txt: -------------------------------------------------------------------------------- 1 | libraries used : tkinter 2 | from tkinter import filedialog 3 | import tkinter.messagebox 4 | from PIL import ImageTk, Image, ImageDraw 5 | cv2 6 | argparse 7 | os 8 | time 9 | tensorflow 10 | numpy -------------------------------------------------------------------------------- /Computer Vision/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Conversions/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Cryptography/Brute Forcing Caesar Cipher/Images/brute_force_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Cryptography/Brute Forcing Caesar Cipher/Images/brute_force_output.png -------------------------------------------------------------------------------- /Cryptography/Brute Forcing Caesar Cipher/README.md: -------------------------------------------------------------------------------- 1 | # Brute Forcing Caesar Cipher 2 | ## Aim 3 | 4 | To use Brute force on Caesar cipher encrypted message. 5 | 6 | 7 | ## Purpose 8 | 9 | The purpose is to t the decrypted text using all possible keys since you don't have the actual key. 10 | 11 | 12 | ## Short description of package/script 13 | 14 | - The user enters a string.
15 | - To decrypt string using all posibl key combos.
16 | 17 | 18 | ## Workflow of the Project 19 | 20 | input: user enters encrypted string.
21 | string converted to uppercase and loop is run.
22 | Prints all possible messages using different keys.
23 | 24 | 25 | ## Compilation Steps 26 | 27 | After the script is run, enter: 28 | 29 | 1. An encrypted string is input , which has to be decrypted. 30 | 2. Passing the input string to loop. 31 | 3. output of all possible messages with different key's is printted. 32 | 33 | 34 | 35 | ## Output 36 | 37 | 38 | 39 | ## Author 40 | 41 | [Ritika Chand](https://github.com/RC2208) 42 | -------------------------------------------------------------------------------- /Cryptography/Caesar Cipher/Images/DecryptedString.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Cryptography/Caesar Cipher/Images/DecryptedString.png -------------------------------------------------------------------------------- /Cryptography/Caesar Cipher/Images/EncryptedStringOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Cryptography/Caesar Cipher/Images/EncryptedStringOutput.png -------------------------------------------------------------------------------- /Cryptography/Caesar Cipher/Images/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Cryptography/Diffie_Hellmann/Images/diffie1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Cryptography/Diffie_Hellmann/Images/diffie1.PNG -------------------------------------------------------------------------------- /Cryptography/Diffie_Hellmann/Images/diffie2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Cryptography/Diffie_Hellmann/Images/diffie2.PNG -------------------------------------------------------------------------------- /Cryptography/Diffie_Hellmann/Images/diffie3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Cryptography/Diffie_Hellmann/Images/diffie3.PNG -------------------------------------------------------------------------------- /Cryptography/Diffie_Hellmann/requirements.txt: -------------------------------------------------------------------------------- 1 | Need to have Python -3 -------------------------------------------------------------------------------- /Cryptography/README.md: -------------------------------------------------------------------------------- 1 | # Cryptography 2 | 3 | ## Check out all the amazing scripts using 'Cryptography' here: 4 | 5 | - [Caesar Cipher](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Cryptography/Caesar%20Cipher) 6 | 7 | - [Reverse Cipher](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Cryptography/Reverse%20Cipher) 8 | 9 | - [Transposition Cipher](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Cryptography/Transposition%20Cipher) 10 | 11 | - [Brute Forcing Caesar Cipher](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Cryptography/Brute%20Forcing%20Caesar%20Cipher) 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Cryptography/RSA_ElGamal_cryptography/Images/elgamal.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Cryptography/RSA_ElGamal_cryptography/Images/elgamal.PNG -------------------------------------------------------------------------------- /Cryptography/RSA_ElGamal_cryptography/Images/elgamal1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Cryptography/RSA_ElGamal_cryptography/Images/elgamal1.PNG -------------------------------------------------------------------------------- /Cryptography/RSA_ElGamal_cryptography/Images/rsa.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Cryptography/RSA_ElGamal_cryptography/Images/rsa.PNG -------------------------------------------------------------------------------- /Cryptography/RSA_ElGamal_cryptography/Images/rsa1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Cryptography/RSA_ElGamal_cryptography/Images/rsa1.PNG -------------------------------------------------------------------------------- /Cryptography/RSA_ElGamal_cryptography/requirements.txt: -------------------------------------------------------------------------------- 1 | Need to have Python-3 -------------------------------------------------------------------------------- /Cryptography/Reverse Cipher/Images/reverse_cipher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Cryptography/Reverse Cipher/Images/reverse_cipher.png -------------------------------------------------------------------------------- /Cryptography/Reverse Cipher/README.md: -------------------------------------------------------------------------------- 1 | # Reverse Cipher 2 | 3 | ## Aim 4 | 5 | The user enters a string , to implement Reverse Cipher Cryptography 6 | on the inputted string. 7 | 8 | 9 | ## Purpose 10 | 11 | The purpose is to explore Cryptography methods on strings and try it in python. 12 | 13 | 14 | ## Short description of package/script 15 | 16 | - The user enters a string. 17 | - To reverse the input string 18 | 19 | 20 | ## Workflow of the Project 21 | 22 | revers_cipher --> It is a function , which takes in the variable in which , 23 | a user input string is scored 24 | 25 | Note : Since in reverse Cipher the working remains the same. i.e to reverse the 26 | inputted string , hence I haven't segregated encryption and decryption as inputs. 27 | 28 | 29 | 30 | ## Compilation Steps 31 | 32 | After the script is run, enter: 33 | 34 | 1. A string is input , which has to be enrypted/decrypted. 35 | 2. Passing the input parameter to the revers_cipher function. 36 | 3. revers_cipher returns the reversed string , and output is printted 37 | 38 | 39 | 40 | 41 | ## Output 42 | 43 | 44 | 45 | 46 | ## Author 47 | 48 | [Shiwansh Raj](https://github.com/photon149) 49 | -------------------------------------------------------------------------------- /Cryptography/Reverse Cipher/reverse_cipher.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Aim : The user enters a string , to implement 3 | Reverse Cipher on the inputted string. 4 | 5 | ''' 6 | #Reverse Cipher function to reverse the inputted string 7 | def revers_cipher(input_string): 8 | #return the reversed string 9 | return input_string[::-1] 10 | 11 | #getting input from the user 12 | input_string = input('Enter the string which you would like to encrypt or decrypt : ') 13 | 14 | #printing the output 15 | print('The inputted String was ',input_string) 16 | print('Reversed String is ', revers_cipher(input_string)) 17 | 18 | ''' 19 | Note : Since in reverse Cipher the working remains the same. i.e to reverse the 20 | inputted string , hence we haven't segregated encryption and decryption as inputs. 21 | 22 | ''' 23 | 24 | ''' 25 | Sample input : ok so it is cool 26 | Sample output : looc si ti os ko 27 | 28 | Explaination: 29 | The user enters either an encrypted/decrypted string . 30 | After the user has provided the input the variable in which the string 31 | is stored is passed onto a Revers_cipher function. 32 | The Revers_cipher function reverses the string and returns the reversed string. 33 | 34 | ''' -------------------------------------------------------------------------------- /Cryptography/Transposition Cipher/Images/Output1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Cryptography/Transposition Cipher/Images/Output1.PNG -------------------------------------------------------------------------------- /Cryptography/Transposition Cipher/README.md: -------------------------------------------------------------------------------- 1 | # Transposition Cipher 2 | 3 | 4 | ## Aim 5 | 6 | The aim is to create a python code to decrypt or encrpt text using transposition cipher 7 | 8 | ## Short description of project 9 | 10 | The code takes in input string that needs to be encrypted and uses transpositional cipher to encrypt it similarly the reverse is applied for decryption. 11 | 12 | Workflow of the Project 13 | Description of functions used in the code and their purpose: 14 | 15 | encryption --> encrypt the plain text to cipher text using transposition cipher. 16 | 17 | decryption --> decrypt the cipher text to plain text using transposition cipher. 18 | 19 | 20 | After the desired values are entered by the user, the control is passed to the encryption function, which returns the encrypted text and then this text is passed to decryption and output is displayed as both encrypted and decrypted text. 21 | 22 | 23 | ## Setup instructions 24 | Download the code and open it in your prefered code editor, then run it. 25 | 26 | ## Required libraries 27 | 28 | math 29 | 30 | ## Compilation Steps 31 | Run the script, after that : 32 | 33 | 1. User is prompted to enter key (integer) 34 | 2. User is again prompted to enter the string/message to be encrypted or decrypted 35 | 3. The program tells encrypts or decrypts the string 36 | 37 | ## Sample Test Cases 38 | Combination of different keys and your text that you want to encrypt/decrypt. 39 | Eg) Key=5 and mssg= 'Your roommate is a spy' 40 | 41 | # Output 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | ## Author 50 | [Ritika Chand](https://github.com/RC2208) 51 | -------------------------------------------------------------------------------- /Cryptography/Transposition Cipher/transposition_cipher.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | key = int(input("Enter key: ")) 4 | 5 | # Encryption 6 | def encryption(msg): 7 | cipher = "" 8 | text_len = float(len(msg)) 9 | text_list = list(msg) 10 | col = key 11 | 12 | # maximum row of the matrix 13 | row = int(math.ceil(text_len / col)) 14 | 15 | # the empty cells at the end are filled with '/' 16 | fill_null = int((row * col) - text_len) 17 | text_list.extend('/' * fill_null) 18 | 19 | # create Matrix and insert message 20 | matrix = [text_list[i: i + col] for i in range(0, len(text_list), col)] 21 | 22 | #print matrix 23 | for i in matrix: 24 | print(i) 25 | 26 | # read matrix column-wise 27 | key_index = 0 28 | for i in range(col): 29 | cipher += ''.join([row[key_index] for row in matrix]) 30 | key_index += 1 31 | 32 | return cipher 33 | 34 | 35 | def decryption(c, key): 36 | col = key 37 | col, row = key, math.ceil(len(c)/key) 38 | no_of_blanks = row*col-len(c) 39 | filled = row - no_of_blanks 40 | 41 | chars = list(c) 42 | if no_of_blanks != 0: 43 | for i in range (filled,1+key): 44 | chars.insert(row*i-1, " ") 45 | 46 | tmp = [chars[j+i] for j in range(row) for i in range(0,len(chars),row) if (j+i) 41 | 42 | 43 | ## Author 44 | 45 | [Shiwansh Raj](https://github.com/photon149) 46 | -------------------------------------------------------------------------------- /Geometry/Complex To Polar Coordinates/complex_to_polar.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Aim: Read a complex number as input from user, complex_num and print 3 | its value in polar coordinates. 4 | 5 | ''' 6 | 7 | #importing cmath library 8 | import cmath 9 | 10 | #getting the input 11 | complex_num= complex(int(input("Enter your x value : ")),int(input("Enter your y value: "))) 12 | 13 | #using library converting the complex values into coordinates 14 | r = float(abs(complex_num)) 15 | theta = float(cmath.phase(complex_num)) 16 | 17 | #printing the output 18 | print("Your inputed complex number is :",complex_num) 19 | print("r : ",r) 20 | print("theta :",theta) 21 | print("Hence Polar co-ordinates are : {0:0.4f} + i{1:0.4f}".format(r,theta)) 22 | 23 | 24 | ''' 25 | sample input 1 : 26 | x : 4 y : 3 27 | sample output 1 : 28 | r : 5.0 theta : 0.643 29 | 30 | sample input 2 : 31 | x : 1 y : 2 32 | sample output 2 : 33 | r : 2.361 theta : 1.107 34 | 35 | Explaination : 36 | The user enters two values x and y , which stand for x+iy in complex 37 | number notation.This inputted values are then converted into r and theta 38 | using the abs function on x and phase function on y. 39 | 40 | ''' 41 | -------------------------------------------------------------------------------- /Geometry/Find Angle MBC/Images/mbc1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Geometry/Find Angle MBC/Images/mbc1.png -------------------------------------------------------------------------------- /Geometry/Find Angle MBC/Images/mbc2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Geometry/Find Angle MBC/Images/mbc2.png -------------------------------------------------------------------------------- /Geometry/Find Angle MBC/Images/mbc3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Geometry/Find Angle MBC/Images/mbc3.png -------------------------------------------------------------------------------- /Geometry/Find Angle MBC/Images/mbc4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Geometry/Find Angle MBC/Images/mbc4.png -------------------------------------------------------------------------------- /Geometry/Find Angle MBC/Images/mbc5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Geometry/Find Angle MBC/Images/mbc5.png -------------------------------------------------------------------------------- /Geometry/Find Angle MBC/Images/mbc6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Geometry/Find Angle MBC/Images/mbc6.png -------------------------------------------------------------------------------- /Geometry/README.md: -------------------------------------------------------------------------------- 1 | # Geometry 2 | 3 | ## Check out all the amazing scripts using 'Geometry' here: 4 | 5 | - [Complex to Polar](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Geometry/Complex%20To%20Polar%20Coordinates) 6 | 7 | - [Find Angle MBC](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Geometry/Find%20Angle%20MBC) 8 | -------------------------------------------------------------------------------- /Graphs/Breadth First Search/Images/input.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Graphs/Breadth First Search/Images/input.jpg -------------------------------------------------------------------------------- /Graphs/Breadth First Search/Images/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Graphs/Breadth First Search/Images/output.jpg -------------------------------------------------------------------------------- /Graphs/Breadth First Search/bfs.py: -------------------------------------------------------------------------------- 1 | # Create a graph given in the above diagram. 2 | graph = { 3 | 'A': ['B', 'C', 'D'], 4 | 'B': ['A'], 5 | 'C': ['A', 'D'], 6 | 'D': ['A', 'C', 'E'], 7 | 'E': ['D'] 8 | } 9 | 10 | # to print a BFS of a graph 11 | def bfs(node): 12 | 13 | # mark vertices as False means not visited 14 | visited = [False] * (len(graph)) 15 | 16 | # make a empty queue for bfs 17 | queue = [] 18 | 19 | # mark given node as visited and add it to the queue 20 | visited.append(node) 21 | queue.append(node) 22 | 23 | while queue: 24 | # Remove the front vertex or the vertex at 0th index from the queue and print that vertex. 25 | v = queue.pop(0) 26 | print(v, end=" ") 27 | 28 | for neigh in graph[v]: 29 | if neigh not in visited: 30 | visited.append(neigh) 31 | queue.append(neigh) 32 | 33 | 34 | # Driver Code 35 | if __name__ == "__main__": 36 | bfs('A') 37 | -------------------------------------------------------------------------------- /Graphs/DFS/Images/dfs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Graphs/DFS/Images/dfs.jpg -------------------------------------------------------------------------------- /Graphs/DFS/Images/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Graphs/DFS/Images/output.jpg -------------------------------------------------------------------------------- /Graphs/DFS/README.md: -------------------------------------------------------------------------------- 1 | ## Overview: 2 | Two techniques are frequently used for graph traversal: These techniques are called **depth-first search (DFS)** and **breadth-first search (BFS)**, although we will just talk about DFS. DFS involves diving deep into the graph and then backtrack when it reaches the bottom. 3 | 4 | ## What is Depth First Search in Python? 5 | In DFS, *we continue to traverse downwards through linked nodes until we reach the end*, then retrace our steps to check which connected nodes we haven't visited and repeat the process. In depth-first search, we dive deep into the graph and then backtrack when we reach the bottom. 6 | 7 | ## Algorithm of DFS in Python 8 | Every time we reach a new node, we will take the following steps: 9 | 1. We add the node to the top of the stack. 10 | 2. Marked it as visited. 11 | 3. We check if this node has any adjacent nodes: 12 | 1. If it has adjacent nodes, then we ensure that they have not been visited already, and then visited it. 13 | 2. We removed it from the stack if it had no adjacent nodes. 14 | 15 | ## Time & Space Complexity 16 | * **Time Complexity:** 17 | Time complexity of DFS is `O(V+|E|)`, where V is the number of vertices and E is the number of edges. 18 | * **Space Complexity:** 19 | The space complexity of the DFS algorithm is `O(V)`, where V is the number of vertices. 20 | 21 | ## Input & Output: 22 | 23 | 24 | ### Input: 25 | 26 | ```python 27 | graph = { 28 | 0: [2], 29 | 1: [2, 3], 30 | 2: [0, 1, 4], 31 | 3: [1, 4], 32 | 4: [2, 3] 33 | } 34 | ``` 35 | 36 | ### Output: 37 | ```python 38 | Depth-first search: [0, 2, 1, 3, 4] 39 | ``` 40 | 41 | -------------------------------------------------------------------------------- /Graphs/DFS/dfs.py: -------------------------------------------------------------------------------- 1 | def dfs(node, graph, visited, component): 2 | component.append(node) # Store answer 3 | visited[node] = True # Mark visited 4 | 5 | # Traverse to each adjacent node of a node 6 | for child in graph[node]: 7 | if not visited[child]: # Check whether the node is visited or not 8 | dfs(child, graph, visited, component) 9 | 10 | 11 | if __name__ == "__main__": 12 | 13 | # Graph of nodes 14 | graph = { 15 | 0: [2], 16 | 1: [2, 3], 17 | 2: [0, 1, 4], 18 | 3: [1, 4], 19 | 4: [2, 3] 20 | } 21 | node = 0 # Starting node 22 | visited = [False]*len(graph) 23 | component = [] 24 | dfs(node, graph, visited, component) # Traverse to each node of a graph 25 | print(f"Following is the Depth-first search: {component}") # Print the answer 26 | -------------------------------------------------------------------------------- /Graphs/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Greedy/Activity Selection Problem/Images/asp-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Greedy/Activity Selection Problem/Images/asp-1.png -------------------------------------------------------------------------------- /Greedy/Activity Selection Problem/Images/asp-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Greedy/Activity Selection Problem/Images/asp-2.png -------------------------------------------------------------------------------- /Greedy/Huffman Coding/Images/hc-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Greedy/Huffman Coding/Images/hc-1.png -------------------------------------------------------------------------------- /Greedy/Huffman Coding/Images/hc-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Greedy/Huffman Coding/Images/hc-2.png -------------------------------------------------------------------------------- /Greedy/Job Sequencing Problem/Images/jsp-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Greedy/Job Sequencing Problem/Images/jsp-1.png -------------------------------------------------------------------------------- /Greedy/Job Sequencing Problem/Images/jsp-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Greedy/Job Sequencing Problem/Images/jsp-2.png -------------------------------------------------------------------------------- /Greedy/README.md: -------------------------------------------------------------------------------- 1 | ## Implementations of Greedy Algorithms :computer: 2 | 3 | - [**Activity Selection Problem**](https://github.com/abhisheks008/PyAlgo-Tree/tree/main/Greedy/Activity%20Selection%20Problem) 4 | - [**Job Sequencing Problem**](https://github.com/abhisheks008/PyAlgo-Tree/tree/main/Greedy/Job%20Sequencing%20Problem) 5 | - [**Huffman Coding**](https://github.com/abhisheks008/PyAlgo-Tree/tree/main/Greedy/Huffman%20Coding) 6 | -------------------------------------------------------------------------------- /Hashes/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Knapsack/0-1 Knapsack/Images/knapsack1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Knapsack/0-1 Knapsack/Images/knapsack1.PNG -------------------------------------------------------------------------------- /Knapsack/0-1 Knapsack/Images/knapsack2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Knapsack/0-1 Knapsack/Images/knapsack2.PNG -------------------------------------------------------------------------------- /Knapsack/0-1 Knapsack/Images/knapsack3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Knapsack/0-1 Knapsack/Images/knapsack3.jpg -------------------------------------------------------------------------------- /Knapsack/Fractional Knapsack/Images/frac1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Knapsack/Fractional Knapsack/Images/frac1.PNG -------------------------------------------------------------------------------- /Knapsack/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Prathima Kadari 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Lists/Circular Linked List/Images/Output1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Lists/Circular Linked List/Images/Output1.PNG -------------------------------------------------------------------------------- /Lists/Circular Linked List/Images/Output2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Lists/Circular Linked List/Images/Output2.PNG -------------------------------------------------------------------------------- /Lists/Doubly Linked List/Images/screenshot_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Lists/Doubly Linked List/Images/screenshot_1.png -------------------------------------------------------------------------------- /Lists/Doubly Linked List/Images/screenshot_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Lists/Doubly Linked List/Images/screenshot_2.png -------------------------------------------------------------------------------- /Lists/README.md: -------------------------------------------------------------------------------- 1 | # Lists 2 | 3 | ## Check out all the amazing scripts using 'Lists' here: 4 | 5 | - [Singly Linked List](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Lists/Singly%20Linked%20List) 6 | 7 | - [Doubly Linked List](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Lists/Doubly%20Linked%20List) 8 | -------------------------------------------------------------------------------- /Lists/Singly Linked List/Images/Screenshot_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Lists/Singly Linked List/Images/Screenshot_1.png -------------------------------------------------------------------------------- /Machine Learning/Campus Placement Analysis & Prediction/Images/cp1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Campus Placement Analysis & Prediction/Images/cp1.jpg -------------------------------------------------------------------------------- /Machine Learning/Campus Placement Analysis & Prediction/Images/cp2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Campus Placement Analysis & Prediction/Images/cp2.jpg -------------------------------------------------------------------------------- /Machine Learning/Campus Placement Analysis & Prediction/Images/cp3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Campus Placement Analysis & Prediction/Images/cp3.jpg -------------------------------------------------------------------------------- /Machine Learning/Campus Placement Analysis & Prediction/Images/cp4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Campus Placement Analysis & Prediction/Images/cp4.jpg -------------------------------------------------------------------------------- /Machine Learning/Campus Placement Analysis & Prediction/Model/README.md: -------------------------------------------------------------------------------- 1 | # **Campus Placement Analysis & Prediction** 2 | 3 | **GOAL** 4 | 5 | To analyze various factors and predict salary offered to candidates during campus placements using machine learning algorithm. 6 | 7 | **DATASET** 8 | 9 | Dataset can be downloaded from [here](https://www.kaggle.com/benroshan/factors-affecting-campus-placement). 10 | 11 | **WHAT I HAD DONE** 12 | - Step 1: Data Preprocessing & Exploration 13 | - Step 2: Data Training & Model Creation 14 | - Step 3: Performance Evaluation 15 | 16 | 17 | **Screenshots** 18 | 19 | ![](https://github.com/ayushi424/PyAlgo-Tree/blob/main/Machine%20Learning/Campus%20Placement%20Analysis%20%26%20Prediction/Images/cp1.jpg) 20 | ![](https://github.com/ayushi424/PyAlgo-Tree/blob/main/Machine%20Learning/Campus%20Placement%20Analysis%20%26%20Prediction/Images/cp2.jpg) 21 | ![](https://github.com/ayushi424/PyAlgo-Tree/blob/main/Machine%20Learning/Campus%20Placement%20Analysis%20%26%20Prediction/Images/cp3.jpg) 22 | ![](https://github.com/ayushi424/PyAlgo-Tree/blob/main/Machine%20Learning/Campus%20Placement%20Analysis%20%26%20Prediction/Images/cp4.jpg) 23 | **MODEL USED** 24 | - Decision Tree Regressor 25 | 26 | **LIBRARIES NEEDED** 27 | - pandas 28 | - numpy 29 | - matplotlib 30 | - seaborn 31 | - sklearn (For data traning, importing models and performance check) 32 | 33 | 34 | **Accuracy of different models used** 35 | - By using Decision Tree Regressor model 36 | ```python 37 | Accuracy achieved : 1.00 38 | ``` 39 | 40 | 41 | 42 | **CONCLUSION** 43 | 44 | Performance of Decision tree regressor is highyly efficient. 45 | 46 | 47 | **Author** 48 | 49 | [Ayushi Shrivastava](https://github.com/ayushi424) 50 | -------------------------------------------------------------------------------- /Machine Learning/Heart Failure Prediction/Image/Decision Tree Classifier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Heart Failure Prediction/Image/Decision Tree Classifier.png -------------------------------------------------------------------------------- /Machine Learning/Heart Failure Prediction/Image/Gradient Boosting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Heart Failure Prediction/Image/Gradient Boosting.png -------------------------------------------------------------------------------- /Machine Learning/Heart Failure Prediction/Image/KNN.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Heart Failure Prediction/Image/KNN.png -------------------------------------------------------------------------------- /Machine Learning/Heart Failure Prediction/Image/Logistic Regression.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Heart Failure Prediction/Image/Logistic Regression.png -------------------------------------------------------------------------------- /Machine Learning/Heart Failure Prediction/Image/Random Forest Classifier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Heart Failure Prediction/Image/Random Forest Classifier.png -------------------------------------------------------------------------------- /Machine Learning/Heart Failure Prediction/Image/SVM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Heart Failure Prediction/Image/SVM.png -------------------------------------------------------------------------------- /Machine Learning/Heart Failure Prediction/Requirements.txt: -------------------------------------------------------------------------------- 1 | Libraries imported in the Heart Failure Prediction: 2 | 1.pandas 3 | 2.matplotlib 4 | 3.seaborn 5 | 4.plotly -------------------------------------------------------------------------------- /Machine Learning/K-Means Clustering using Iris/K-Means_Clustering_using_Iris.ipynb: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Machine Learning/K-Means Clustering using Iris/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Machine Learning/K-Means Clustering using Iris/requirements.txt: -------------------------------------------------------------------------------- 1 | Add libraries used in your project here. List them out 2 | -------------------------------------------------------------------------------- /Machine Learning/Mobile Price Range Classification/Images/lr1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Mobile Price Range Classification/Images/lr1.jpg -------------------------------------------------------------------------------- /Machine Learning/Mobile Price Range Classification/Images/lr2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Mobile Price Range Classification/Images/lr2.jpg -------------------------------------------------------------------------------- /Machine Learning/Mobile Price Range Classification/Images/lr3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Mobile Price Range Classification/Images/lr3.jpg -------------------------------------------------------------------------------- /Machine Learning/Movie Classification/Images/knn1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Movie Classification/Images/knn1.jpg -------------------------------------------------------------------------------- /Machine Learning/Movie Classification/Images/knn2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Movie Classification/Images/knn2.jpg -------------------------------------------------------------------------------- /Machine Learning/Movie Classification/Images/knn3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Movie Classification/Images/knn3.jpg -------------------------------------------------------------------------------- /Machine Learning/Movie Classification/Images/knn4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Movie Classification/Images/knn4.jpg -------------------------------------------------------------------------------- /Machine Learning/Movie Classification/Images/knn5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Movie Classification/Images/knn5.jpg -------------------------------------------------------------------------------- /Machine Learning/Movie Classification/Images/knn6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Movie Classification/Images/knn6.jpg -------------------------------------------------------------------------------- /Machine Learning/Predicting House Prices/Images/lin1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Predicting House Prices/Images/lin1.png -------------------------------------------------------------------------------- /Machine Learning/Predicting House Prices/Images/lin2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Predicting House Prices/Images/lin2.png -------------------------------------------------------------------------------- /Machine Learning/Predicting House Prices/Images/lin3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Predicting House Prices/Images/lin3.png -------------------------------------------------------------------------------- /Machine Learning/Predicting House Prices/Images/lin4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Predicting House Prices/Images/lin4.png -------------------------------------------------------------------------------- /Machine Learning/Predicting House Prices/Images/lin5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Predicting House Prices/Images/lin5.png -------------------------------------------------------------------------------- /Machine Learning/Predicting House Prices/Images/lin6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Machine Learning/Predicting House Prices/Images/lin6.png -------------------------------------------------------------------------------- /Machine Learning/Predicting House Prices/requirements.txt: -------------------------------------------------------------------------------- 1 | To run this codebase you need to install a python library which is called Sklearn 2 | 3 | Required library : 4 | Sklearn 5 | 6 | It is an in-built library if you use Anaconda Navigator or, Jupyter Notebook. Otherwise if you find that this library is not installed in your system, then do the following steps. 7 | 8 | 1. Open Jupyter Notebook 9 | 2. select any cell and write this code 10 | !pip install sklearn 11 | 3. This will take few seconds to install 12 | 4. Bang! your system is ready to run the code! 13 | -------------------------------------------------------------------------------- /Machine Learning/README.md: -------------------------------------------------------------------------------- 1 | # Machine Learning 2 | 3 | ## Check out all the amazing scripts using 'Machine Learning' here: 4 | 5 | - [K-Means Clustering using IRIS](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Machine%20Learning/K-Means%20Clustering%20using%20Iris) 6 | 7 | - [Mobile Price Range Classification](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Machine%20Learning/Mobile%20Price%20Range%20Classification) 8 | 9 | - [House Prices Prediction](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Machine%20Learning/Predicting%20House%20Prices) 10 | 11 | -------------------------------------------------------------------------------- /Maths/Average Calculator/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Maths/Average Calculator/Images/ss.png -------------------------------------------------------------------------------- /Maths/Average Calculator/README.md: -------------------------------------------------------------------------------- 1 | # Average Calculator 2 | 3 | ## Aim 4 | 5 | To calculate average of all the distinct integers. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to explore arrays and sets in python. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - The user enters a series of integers. 16 | - All unique integers are selected out using sets. 17 | - Finally, average is calculated. 18 | 19 | 20 | ## Workflow of the Project 21 | 22 | Description of functions used in the code and their purpose: 23 | 24 | average --> This method finds all unique integers and then computes the average of them. 25 | 26 | After the user enters the desired details, 'average' function is called which prints out the result. 27 | 28 | 29 | ## Compilation Steps 30 | 31 | After the script is run, enter: 32 | 33 | 1. A series of integers. 34 | 35 | That's it! The average will be computed and printed. 36 | 37 | 38 | ## Output 39 | 40 | 41 | 42 | 43 | ## Author 44 | 45 | [Manasi Chhibber](https://github.com/Manasi2001) 46 | -------------------------------------------------------------------------------- /Maths/Average Calculator/average_calculator.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Aim: To calculate average of all the distinct integers. 3 | 4 | ''' 5 | 6 | def average(array): 7 | # getting all unique numbers 8 | p = set(array) 9 | # calculating the total number of elements 10 | s = len(p) 11 | # computing the average 12 | ans = sum(p)/s 13 | # printing the result 14 | print('Average is:',ans) 15 | 16 | # getting the input 17 | arr = input('Enter numbers: ').strip().split() 18 | # converting elements into integer type for calculating average 19 | arr_int = [] 20 | for i in arr: 21 | arr_int.append(int(i)) 22 | # calling function to compute the average 23 | average(arr_int) 24 | 25 | ''' 26 | COMPLEXITY: 27 | 28 | Time Complexity -> O(1) 29 | Space Complexity -> O(N) 30 | 31 | Sample Input: 32 | Enter numbers: 5 3 1 2 3 4 5 33 | 34 | Sample Output: 35 | Average is: 3.0 36 | 37 | Explanation: 38 | All unique integers --> 1 2 3 4 5 39 | Total count --> 5 40 | Average --> (1+2+3+4+5)/5 = 3.0 41 | 42 | ''' -------------------------------------------------------------------------------- /Maths/Binary Numbers/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Maths/Binary Numbers/Images/ss.png -------------------------------------------------------------------------------- /Maths/Binary Numbers/README.md: -------------------------------------------------------------------------------- 1 | # Binary Numbers 2 | 3 | ## Aim 4 | 5 | Given a base-10 integer, n, convert it to binary (base-2). Then find and print the base-10 integer denoting the maximum number of consecutive 1's in n's binary representation. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to explore different operators for conversion into binary form. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - Whenever decimal to binary conversion is done, the number is repeatedly divided by 2 until it could not be divided any further. 16 | - We keep appending the remainder that is obtained each time in a list. 17 | - Maximum streak of 1's is chosen. 18 | 19 | 20 | ## Workflow of the Project 21 | 22 | - a while loop saves the remainder obtained in each iteration 23 | - a for loop keeps counter for the maximum consecutive 1's 24 | 25 | 26 | ## Compilation Steps 27 | 28 | After the script is run, enter: 29 | 30 | 1. A number in decimal format. 31 | 32 | That's it! The binary form would be computed and printed. 33 | 34 | 35 | ## Output 36 | 37 | 38 | 39 | 40 | ## Author 41 | 42 | [Manasi Chhibber](https://github.com/Manasi2001) 43 | -------------------------------------------------------------------------------- /Maths/Binary Numbers/binary_numbers.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Aim: Given a base-10 integer, n, convert it to binary (base-2). Then find and print the 3 | base-10 integer denoting the maximum number of consecutive 1's in n's binary representation. 4 | 5 | ''' 6 | 7 | n = int(input()) # getting input 8 | remainder = [] 9 | while n > 0: 10 | rm = n % 2 11 | n = n//2 # whenever decimal to binary conversion is done, the number is repeatedly divided by 2 until it could not be divided any further 12 | remainder.append(rm) # appending the remainder that is obtained each time in a list 13 | count,result = 0,0 14 | for i in range(0,len(remainder)): 15 | if remainder[i] == 0: 16 | count = 0 # as soon as '0' is encountered, the counter is set to 0 17 | else: 18 | count += 1 # the counter increases every time consecutive ones are encountered 19 | result = max(result,count) # maximum streak of 1's is chosen 20 | print(result) 21 | 22 | ''' 23 | Sample Test Case: 24 | Input: 25 | 13 26 | Output: 27 | 2 28 | Explaination: 29 | The binary representation of 13 is 1101, so the maximum number of consecutive 1's is 2. 30 | 31 | ''' -------------------------------------------------------------------------------- /Maths/Bitwise AND/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Maths/Bitwise AND/Images/ss.png -------------------------------------------------------------------------------- /Maths/Bitwise AND/README.md: -------------------------------------------------------------------------------- 1 | # Bitwise AND 2 | 3 | ## Aim 4 | 5 | Given set S = {1,2,3,....,N}. Find two integers, I and J (where I 38 | 39 | 40 | ## Author 41 | 42 | [Manasi Chhibber](https://github.com/Manasi2001) 43 | -------------------------------------------------------------------------------- /Maths/Bitwise AND/bitwise_AND.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Aim: Given set S = {1,2,3,....,N}. Find two integers, I and J (where I=0): 17 | for i in range(int(k)): 18 | print(Fibonacci(i)) 19 | else: 20 | print("its a negative number") 21 | except: 22 | print("Hey stupid enter only number") 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Recursion/First Index/Images/output1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Recursion/First Index/Images/output1.jpg -------------------------------------------------------------------------------- /Recursion/First Index/README.md: -------------------------------------------------------------------------------- 1 | # First index of an element in an array. 2 | 3 | ## Aim 4 | 5 | The aim is to create a python code to get first index of an element in an array. 6 | 7 | ## Purpose 8 | 9 | The purpose is to come up with an efficient solution while implementing recursion. 10 | 11 | ## Short description of project 12 | The program takes 3 inputs. 13 | 1.size of array. 14 | 2.Array elements. 15 | 3.Elements whose occurrence is to be found. 16 | 17 | ## Workflow of the Project 18 | * We will divide the array into 2 parts. 19 | 1.The first element. 20 | 2. THE remaining elements. 21 | *We will work on first element and recursion will work on rest. 22 | * First we define the base case which will be if length of array =0 return -1. 23 | * Now we will check if our first element is equal to the element whose occurrence is to be checked. 24 | * If yes then we will return 0. 25 | * If no then we we call recursion on other part of array. 26 | 27 | 28 | ## Required libraries 29 | 30 | None 31 | 32 | ## Compilation Steps 33 | Run the script, after that : 34 | 35 | 1. User is prompted to enter size of array followed by array elements and number whose occurrence is to be checked. 36 | 2. First index on which the element occurred is printed. 37 | 38 | # Sample Input and output 39 | ## Sample Input 1 40 | 5 41 | 2 3 5 1 2 42 | 2 43 | 44 | ## Sample output 1 45 | 0 46 | 47 | ## Sample Input 1 48 | 6 49 | 1 7 1 2 3 2 50 | 5 51 | 52 | ## Sample Output 2 53 | -1 54 | 55 | # Output 56 | ![](Images/output1.jpg) 57 | 58 | 59 | ## Author 60 | [Siddhi Bhanushali](https://github.com/siddhi-244) 61 | -------------------------------------------------------------------------------- /Recursion/First Index/first_index_of_array.py: -------------------------------------------------------------------------------- 1 | #To find first index of an element in an array. 2 | def firstIndex(arr, si, x): 3 | l = len(arr) #length of array. 4 | if l == 0: #base case 5 | return -1 6 | if arr[si] == x: #if element is found at start index of an array then return that index. 7 | return si 8 | return firstIndex(arr, si+1, x) #recursive call. 9 | 10 | arr = [] #initialised array. 11 | n=int(input("Enter size of array : ")) 12 | for i in range(n): #input array. 13 | ele=int(input()) 14 | arr.append(ele) 15 | x=int(input("Enter element to be searched ")) #element to be searched 16 | print(firstIndex(arr, 0, x)) 17 | -------------------------------------------------------------------------------- /Recursion/Last Index/Images/output2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Recursion/Last Index/Images/output2.jpg -------------------------------------------------------------------------------- /Recursion/Last Index/README.md: -------------------------------------------------------------------------------- 1 | # Last index of an element in an array. 2 | 3 | ## Aim 4 | 5 | The aim is to create a python code to get last index of an element in an array. 6 | 7 | ## Purpose 8 | 9 | The purpose is to come up with an efficient solution while implementing recursion. 10 | 11 | ## Short description of project 12 | The program takes 3 inputs. 13 | 1.size of array. 14 | 2.Array elements. 15 | 3.Elements whose last occurrence is to be found. 16 | 17 | ## Workflow of the Project 18 | * We will divide the array into 2 parts. 19 | 1.The first element. 20 | 2. THE remaining elements. 21 | * We will work on first element and recursion will work on rest. 22 | * First we define the base case which will be if startindex of array is greater than length of array , return -1. 23 | * Now we will call recursion on other part of array and see if the element is present there or not. 24 | * If the element is present we return index+1. 25 | * If not then we check the first element. 26 | * If the first element is equal then we return 0 else return -1. 27 | 28 | 29 | ## Required libraries 30 | 31 | None 32 | 33 | ## Compilation Steps 34 | Run the script, after that : 35 | 36 | 1. User is prompted to enter size of array followed by array elements and number whose occurrence is to be checked. 37 | 2. Last index on which the element occurred is printed. 38 | 39 | # Sample Input and output 40 | ## Sample Input 1 41 | 5 42 | 2 3 5 1 2 43 | 2 44 | 45 | ## Sample output 1 46 | 4 47 | 48 | ## Sample Input 1 49 | 6 50 | 1 7 1 2 3 2 51 | 5 52 | 53 | ## Sample Output 2 54 | -1 55 | 56 | # Output 57 | ![](Images/output2.jpg) 58 | 59 | 60 | ## Author 61 | [Siddhi Bhanushali](https://github.com/siddhi-244) 62 | -------------------------------------------------------------------------------- /Recursion/Last Index/last_index.py: -------------------------------------------------------------------------------- 1 | #Program to find last index of an element in array. 2 | def lastIndex(arr, si, x): 3 | l = len(arr) 4 | if si == l: #if the start index is greater than size of array. 5 | return -1 6 | smallerListOutput = lastIndex(arr, si+1, x) #recirsion 7 | if smallerListOutput != -1: 8 | return smallerListOutput # if the element is found in the second part of array return index+1 9 | else: 10 | if arr[si] == x:#if element is not found in second part of array check for 1st element 11 | return si 12 | else: 13 | return -1 14 | 15 | n=int(input("Enter size of array : ")) 16 | a=[] 17 | for i in range(n): 18 | ele=int(input()) 19 | a.append(ele) 20 | x=int(input("Enter element whose last index is to be found : ")) 21 | print(lastIndex(a,0,x)) 22 | 23 | #Example 24 | #Input 5 25 | # 2 1 2 1 3 26 | #1 27 | #Output 28 | #3 -------------------------------------------------------------------------------- /Recursion/Max Path Maze/Images/terminal_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Recursion/Max Path Maze/Images/terminal_output.png -------------------------------------------------------------------------------- /Recursion/Max Path Maze/README.md: -------------------------------------------------------------------------------- 1 | # Max Path Maze 2 | 3 | ## Aim 4 | 5 | Demonstrate a Recursion backtracking technique to keep a count. 6 | 7 | 8 | ## Purpose 9 | 10 | Run through all possible paths from any given spot to the end of 11 | a maze (bottem left corner of a 2D array) 12 | 13 | 14 | ## Short description of package/script 15 | 16 | The script sets up a 2D matrix acting as a maze, it then sets a counter to 0 and sets the coordinates to the first cell of the matrix 17 | in this case (0, 0), then calls upon the recursive function with these parameters to find available paths to the end of the maze. 18 | 19 | ## Workflow of the Project 20 | 21 | - Descriptions of functions used in the code: 22 | valid_cell(x, y) --> check if current cell is out of bounds or if one of the coordinates is illegal (less than 0) 23 | 24 | count_valid_paths(maze, x, y, checked, paths) --> Recursion function, for each cell it will check the cell is valid 25 | and try to find a path to the end of the maze from it. The maze is the 2D array, x and y are the coordinates, checked is a 2D matrix to 26 | keep track of visited cells and paths is the counter for the number of paths 27 | 28 | 29 | ## Compilation Steps 30 | 31 | Run the script in order to see available paths at a given maze, feel free to edit the maze 32 | or the starting point to get diffrent results 33 | 34 | ## Output 35 | 36 | 37 | 38 | ## Author(s) 39 | Yarden Galon -------------------------------------------------------------------------------- /Recursion/Palindrome Check/Images/Palindrome_Check_1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Recursion/Palindrome Check/Images/Palindrome_Check_1.PNG -------------------------------------------------------------------------------- /Recursion/Palindrome Check/Images/Palindrome_Check_2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Recursion/Palindrome Check/Images/Palindrome_Check_2.PNG -------------------------------------------------------------------------------- /Recursion/Palindrome Check/Images/Palindrome_Check_3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Recursion/Palindrome Check/Images/Palindrome_Check_3.PNG -------------------------------------------------------------------------------- /Recursion/Palindrome Check/Images/Palindrome_Check_4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Recursion/Palindrome Check/Images/Palindrome_Check_4.PNG -------------------------------------------------------------------------------- /Recursion/Palindrome Check/README.md: -------------------------------------------------------------------------------- 1 | # Palindrome Check 2 | 3 | 4 | ## Aim 5 | 6 | The aim is to create a python code to check if a given string is palindrome or not by recursion 7 | 8 | ## Purpose 9 | 10 | The purpose is to come up with an efficient solution while implementing recursion (if any) 11 | 12 | ## Short description of project 13 | 14 | The project takes in input the string to be checked, and if it comparisons are case sensitive, 15 | and then checks the string by comparing the first and last member of string and checking on a shorter version of string recursively 16 | 17 | ## Workflow of the Project 18 | 19 | Description of functions used in the code and their purpose: 20 | 21 | isPalindrome --> recursive method to check if it argument string is a palindrome 22 | 23 | After the desired values are entered by the user, the control is passed to the isPalindrome function, which returns True or False, which is then interpreted and an appropriate output is given to the user. 24 | 25 | ## Required libraries 26 | 27 | None 28 | 29 | ## Compilation Steps 30 | Run the script, after that : 31 | 32 | 1. User is prompted to enter a string which will be checked 33 | 2. User is asked if comparisons are to be case sensitive, enter 0 for False, 1 for True 34 | 3. The program tells if the string is a palindrome or not 35 | 36 | 37 | 38 | # Output 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | ## Author 47 | [Pushpit Jain](https://github.com/pushpit-J19) 48 | -------------------------------------------------------------------------------- /Recursion/Palindrome Check/palindrome_check.py: -------------------------------------------------------------------------------- 1 | 2 | ## Palindrome checker 3 | 4 | def isPalindrome(s): 5 | """This function checks if a string is palindrome or not using recursion 6 | Input: String to be checked 7 | Output: True if it is a palindrome, False if it is not 8 | """ 9 | if len(s) == 0: 10 | return True 11 | if s[0] != s[len(s)-1]: 12 | return False 13 | 14 | return isPalindrome(s[1:-1]) 15 | 16 | 17 | ## DRIVER CODE 18 | 19 | if __name__ == "__main__": 20 | s = input("\nEnter the string to be checked: ") 21 | 22 | # This section asks user if comparisons are case sensitive 23 | case = input("\nIs it case sensitive? (1/0): ") 24 | if case == '0': 25 | tmp = s.lower() 26 | else: 27 | tmp = s[:] 28 | 29 | # Calling the function 30 | ans = isPalindrome(tmp) 31 | 32 | # Formatting output based on the result 33 | if ans: 34 | print (f"\n\"{s}\" is a palindrome\n") 35 | else: 36 | print (f"\n\"{s}\" is not a palindrome\n") 37 | -------------------------------------------------------------------------------- /Recursion/README.md: -------------------------------------------------------------------------------- 1 | # Recursion 2 | 3 | ## Check out all the amazing scripts using 'Recursion' here: 4 | 5 | - [Palindrome Check](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Recursion/Palindrome%20Check) 6 | 7 | - [All Indices](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Recursion/All%20indices) 8 | 9 | - [Fibonnacci Series](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Recursion/Fibonacci) 10 | 11 | - [First Index](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Recursion/First%20Index) 12 | 13 | - [Last Index](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Recursion/Last%20Index) 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Scheduling/Round Robin Scheduling/Images/Round_Robin_Scheduling_output1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Scheduling/Round Robin Scheduling/Images/Round_Robin_Scheduling_output1.jpeg -------------------------------------------------------------------------------- /Scheduling/Round Robin Scheduling/Images/Round_Robin_Scheduling_output2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Scheduling/Round Robin Scheduling/Images/Round_Robin_Scheduling_output2.jpeg -------------------------------------------------------------------------------- /Scheduling/Round Robin Scheduling/Images/Round_Robin_Scheduling_output3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Scheduling/Round Robin Scheduling/Images/Round_Robin_Scheduling_output3.jpeg -------------------------------------------------------------------------------- /Searching/Binary Search/Images/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Searching/Binary Search/Images/output.jpg -------------------------------------------------------------------------------- /Searching/Binary Search/binary_search.py: -------------------------------------------------------------------------------- 1 | def binary_search(arr, x): 2 | start= 0 3 | end = len(arr) - 1 4 | mid = 0 5 | while start<= end: 6 | mid = (start+ end) // 2 7 | # If x is greater, search in right array 8 | if arr[mid] < x: 9 | start = mid + 1 10 | 11 | # If x is smaller, search in left array 12 | elif arr[mid] > x: 13 | end= mid - 1 14 | # if x is present at mid 15 | else: 16 | return mid 17 | 18 | 19 | # when we reach at the end of array, then the element was not present 20 | return -1 21 | 22 | 23 | arr = [ ] 24 | n=int(input("Enter size of array : ")) 25 | print("Enter array elements : ") 26 | for i in range(n): 27 | e=int(input()) 28 | arr.append(e) 29 | x = int(input("Enter element to search ")) 30 | ans = binary_search(arr, x) 31 | if(ans==-1): 32 | print("Element not found") 33 | else: 34 | print("Element found at ",ans) -------------------------------------------------------------------------------- /Searching/Depth First Search/Images/ss1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Searching/Depth First Search/Images/ss1.png -------------------------------------------------------------------------------- /Searching/Depth First Search/Images/ss2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Searching/Depth First Search/Images/ss2.png -------------------------------------------------------------------------------- /Searching/Depth First Search/README.md: -------------------------------------------------------------------------------- 1 | # Depth First Search 2 | 3 | ## Aim 4 | 5 | To implement depth first search. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to understand the functioning of DFS Algorithm in AI. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - First the graph is created, according to the edges entered by the user. 16 | - The details of visited nodes are maintained. 17 | - According to the algorithm, all the nodes are traversed one by one. 18 | 19 | 20 | ## Workflow of the Project 21 | 22 | Description of functions used in the code and their purpose: 23 | 24 | add_vertex --> Vertex is added to the graph dictionary and it's adjacency list is declared. 25 | 26 | add_edge --> Directional edges are added in this function. The edge is directional, i.e., going from source to destination. 27 | 28 | add_edge_bidirected --> Bidirectional graph edges are added in this function. The edge is bidirectional, i.e., the edge goes both ways. 29 | 30 | dfs_helper --> Function to assist in calling dfs. Also prints the final dfs traversal. 31 | 32 | Based on the graph that is obtained according to the user's details, the DFS is done. 33 | 34 | 35 | ## Compilation Steps 36 | 37 | After the script is run, enter: 38 | 39 | 1. The number of vertices. 40 | 2. Name of all the vertices. 41 | 3. The number of edges. 42 | 4. All the edges as a pair. 43 | 5. The start node for traversal. 44 | 45 | That's it! The complete traversal will get printed out. 46 | 47 | 48 | ## Output 49 | 50 | 51 | 52 | 53 | 54 | ## Author 55 | 56 | [Manasi Chhibber](https://github.com/Manasi2001) 57 | -------------------------------------------------------------------------------- /Searching/Linear Search/Images/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Searching/Linear Search/Images/output.jpg -------------------------------------------------------------------------------- /Searching/Linear Search/README.md: -------------------------------------------------------------------------------- 1 | # Script Name 2 | Linear Search Algorithm. 3 | 4 | ## Aim 5 | To write a program for Linear search. 6 | 7 | 8 | ## Purpose 9 | 10 | To get a understanding about linear search. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - It is a python program for linear search Algorithm. 16 | - It is written in a way that it takes user input. 17 | - It can be used to search an element from an array,list etc. 18 | 19 | 20 | ## Workflow of the Project 21 | 22 | - First a function is written to perform linear Search,which 23 | traverses the whole array and then finds the element. 24 | - Then outside the function user is prompted to input array size,array 25 | elements and element to be searched. 26 | 27 | 28 | 29 | ## Detailed explanation of script, if needed 30 | Linear Search is one of the easiest searching algorithm. 31 | The main aim of a searching algorithm is to search for a 32 | desired element in the whole array. Linear Search sequentially 33 | searches for an element in an array. 34 | 35 | ## Algorithm 36 | * In Linear Search, we start from the 0th index of the array, 37 | we compare each element with the key (desired element). 38 | 39 | * If the key is same as the element of array ,we return the index 40 | of that element. 41 | 42 | * If the key does not match any element then ,we return -1. 43 | 44 | 45 | ## Examples 46 | ``` 47 | We need to search 6 in the array. 48 | 49 | |1|5|2|0|6|8| 50 | |______________ is a[0]==6 no then we move to next element. 51 | |_____________is a[1]==6 no then we move to next element. 52 | |___________is a[2]==6 no we move to next element. 53 | |________is a[3]==6 no we move to next element. 54 | |_____is a[4]==6 yes ,thus we return 4. 55 | ``` 56 | 57 | ## Output 58 | ![](Images/output.jpg) 59 | 60 | ### Author(s) 61 | [Siddhi Bhanushali](https://github.com/siddhi-244) 62 | -------------------------------------------------------------------------------- /Searching/Linear Search/linear_search.py: -------------------------------------------------------------------------------- 1 | #Linear Search in python 2 | #Linear Search is one of the easiest searching algorithm. The main aim of a searching algorithm is to search for a desired element in the whole array. Linear Search sequentially searches for an element in an array. 3 | #algorithm 4 | #In Linear Search, we start from the 0th index of the array, we compare each element with the key (desired element). 5 | #If the key is same as the element of array ,we return the index of that element. 6 | #If the key does not match any element then ,we return -1. 7 | def search(arr, x): #function to search. 8 | for i in range(len(arr)): #traverses the whole array. 9 | if arr[i] == x: #if element is found. 10 | return i 11 | return -1 #if element is not found. 12 | 13 | #user input 14 | n=int(input("Enter Size of array: ")) 15 | arr=[] 16 | print("Enter array elements: ") 17 | for i in range(n): 18 | e=int(input()) 19 | arr.append(e) 20 | x=int(input("Enter element to be searched: ")) 21 | ans=search(arr,x) #function call 22 | if ans==-1: 23 | print("Element not found ") 24 | else: 25 | print("Element found at ",ans) 26 | 27 | -------------------------------------------------------------------------------- /Searching/README.md: -------------------------------------------------------------------------------- 1 | # Searching 2 | 3 | ## Check out all the amazing scripts using 'Searching' here: 4 | 5 | - [Binary Search](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Searching/Binary%20Search) 6 | - [Depth First Search](Depth%20First%20Search/depth_first_search.py) 7 | - [Linear Search](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Searching/Linear%20Search) 8 | 9 | 10 | -------------------------------------------------------------------------------- /Sets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Sorting/Bubble Sort/Images/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Sorting/Bubble Sort/Images/output.jpg -------------------------------------------------------------------------------- /Sorting/Bubble Sort/bubble_sort.py: -------------------------------------------------------------------------------- 1 | #Link to problem:- 2 | #Bubble sort is a sorting algorithm. Sorting algorithms are used to arrange the array in particular order.In,Bubble sort larger elements are pushed at the end of array in each iteration.It works by repeatedly swapping the adjacent elements if they are in wrong order. 3 | 4 | def bubbleSort(a): 5 | n = len(a) 6 | # Traverse through all array elements 7 | 8 | for i in range(n-1): 9 | # Last i elements are already in place 10 | for j in range(0, n-i-1): 11 | 12 | # traverse the array from 0 to n-i-1 13 | # Swap if the element found is greater 14 | # than the next element 15 | if arr[j] > arr[j + 1] : 16 | arr[j], arr[j + 1] = arr[j + 1], arr[j] 17 | 18 | arr = [] 19 | n=int(input("Enter size of array: ")) 20 | for i in range(n): 21 | e=int(input()) 22 | arr.append(e) 23 | bubbleSort(arr) 24 | print ("Sorted array is:") 25 | for i in range(len(arr)): 26 | print(arr[i]) 27 | 28 | #Time complexity - O(n^2) 29 | #Space complexity - O(1) -------------------------------------------------------------------------------- /Sorting/Heap Sort/Images/heap_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Sorting/Heap Sort/Images/heap_sort.png -------------------------------------------------------------------------------- /Sorting/Heap Sort/heap_sort.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of heap Sort 2 | # To heapify subtree rooted at index i and n is size of heap 3 | def heapify(arr,n,i): 4 | largest = i # Initialize largest as root 5 | l = 2*i +1 # left = 2*i + 1 6 | r = 2*i +2 # right = 2*i + 2 7 | 8 | # See if left child of root exists and is 9 | # greater than root 10 | if l= 0 and val< a[j] : 9 | a[j+1]=a[j] # right element getting val of left 10 | j=j-1 11 | swaps=swaps+1 #increments swaps var 12 | comp=comp +1 13 | 14 | a[j+1]=val #replaces the swapped number into its sorted location 15 | if (val>a[j]): #increments comparisions for case when no swaps are made 16 | comp=comp+1 17 | 18 | print('No. of swaps= %d'%swaps) 19 | print('No. of comparisions=%d'% comp) 20 | print("Sorted Array is: ") 21 | for i in range(len(a)): 22 | print ("% d" % a[i],end=' ') 23 | 24 | 25 | # Test cases" 26 | '''input: 27 | a = [34,5,77,33] 28 | 29 | output 30 | 31 | 5, 33, 34, 77 along with 32 | no. of swaps = 3 33 | no. of comparisons=5 34 | 35 | ### Test case 2 36 | input 37 | a=[90,8,11,3,2000,700,478] 38 | 39 | Output: 40 | 41 | No. of swaps= 8 42 | No. of comparisions=12 43 | Sorted Array is: 44 | 3 8 11 90 478 700 2000 45 | 46 | ### Test case 3 47 | input 48 | a=[0,33,7000,344,-88,2000] 49 | 50 | output: 51 | 52 | No. of swaps= 6 53 | No. of comparisions=10 54 | Sorted Array is: 55 | -88 0 33 344 2000 7000''' 56 | -------------------------------------------------------------------------------- /Sorting/Merge Sort/Images/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Sorting/Merge Sort/Images/output.png -------------------------------------------------------------------------------- /Sorting/Merge Sort/README.md: -------------------------------------------------------------------------------- 1 | ## Script Name 2 | Merge Sort Algorithm. 3 | 4 | ## Aim 5 | To write a program for Merge sort. 6 | 7 | 8 | ## Purpose 9 | 10 | To get a understanding about Merge sort. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - It is a python program of Merge sort Algorithm. 16 | - It is written in a way that it takes user input. 17 | 18 | 19 | ## Workflow of the Project 20 | 21 | - First a function is written to perform diving array in two halves. 22 | - Then another funtion perform merging of array. 23 | 24 | 25 | 26 | ## Detailed explanation of script, if needed 27 | Merge Sort is a Divide and Conquer algorithm. It divides the input array into two halves, 28 | calls itself for the two halves, and then merges the two sorted halves. 29 | 30 | ### Algorithm 31 | * Find the middle point to divide the array into two halves: 32 | middle m = l+ (r-l)/2 33 | * Call mergeSort for first half: 34 | Call merge_sort(arr, l, m) 35 | * Call mergeSort for second half: 36 | Call merge_sort(arr, m+1, r) 37 | * Merge the two halves sorted in step 2 and 3: 38 | Call merge_array(arr, l, m, r) 39 | * call the array again using recursion. 40 | 41 | 42 | ## Output 43 | ![](Images/output.png) 44 | 45 | 46 | ## Author(s) 47 | 48 | [Rajpurohit Vijesh](https://github.com/AlexAdvent) 49 | -------------------------------------------------------------------------------- /Sorting/Merge Sort/merge_sort.py: -------------------------------------------------------------------------------- 1 | # function for merge sort 2 | def merge_sort(arr): 3 | if len(arr) > 1: 4 | 5 | # mid element of array 6 | mid = len(arr) // 2 7 | 8 | # Dividing the array and calling merge sort on array 9 | left = arr[:mid] 10 | 11 | # into 2 halves 12 | right = arr[mid:] 13 | 14 | # merge sort for array first 15 | merge_sort(left) 16 | 17 | # merge sort for array second 18 | merge_sort(right) 19 | 20 | # merging function 21 | merge_array(arr, left, right) 22 | 23 | 24 | def merge_array(arr, left, right): 25 | i = j = k = 0 26 | 27 | # merging two array left right in sorted order 28 | while i < len(left) and j < len(right): 29 | if left[i] < right[j]: 30 | arr[k] = left[i] 31 | i += 1 32 | else: 33 | arr[k] = right[j] 34 | j += 1 35 | k += 1 36 | 37 | # merging any remaining element 38 | while i < len(left): 39 | arr[k] = left[i] 40 | i += 1 41 | k += 1 42 | 43 | while j < len(right): 44 | arr[k] = right[j] 45 | j += 1 46 | k += 1 47 | 48 | 49 | # printing array 50 | def print_array(arr): 51 | for i in range(len(arr)): 52 | print(arr[i], end=" ") 53 | print() 54 | 55 | 56 | total_element = int(input("Number of element in array ")) 57 | arr = [] 58 | for i in range(total_element): 59 | arr.append(int(input(f"Enter {i}th element "))) 60 | print("Input array is ", end="\n") 61 | print_array(arr) 62 | 63 | merge_sort(arr) 64 | print("array after sort is: ", end="\n") 65 | print_array(arr) 66 | 67 | -------------------------------------------------------------------------------- /Sorting/Quick Sort/Images/output1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Sorting/Quick Sort/Images/output1.png -------------------------------------------------------------------------------- /Sorting/Quick Sort/Images/output2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Sorting/Quick Sort/Images/output2.png -------------------------------------------------------------------------------- /Sorting/README.md: -------------------------------------------------------------------------------- 1 | # Sorting 2 | 3 | ## Check out all the amazing scripts using 'Sorting' here: 4 | 5 | - [Bubble Sort](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Sorting/Bubble%20Sort) 6 | 7 | - [Heap Sort](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Sorting/Heap%20Sort) 8 | 9 | - [Insertion Sort](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Sorting/Insertion%20Sort) 10 | 11 | - [Merge Sort](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Sorting/Merge%20Sort) 12 | 13 | - [Quick Sort](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Sorting/Quick%20Sort) 14 | 15 | - [Selection Sort](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Sorting/Selection%20Sort) 16 | 17 | - [Shell Sort](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Sorting/Shell%20Sort) 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Sorting/Radix Sort/Images/radix-sort-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Sorting/Radix Sort/Images/radix-sort-1.png -------------------------------------------------------------------------------- /Sorting/Radix Sort/Images/radix-sort-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Sorting/Radix Sort/Images/radix-sort-2.png -------------------------------------------------------------------------------- /Sorting/Selection Sort/Images/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Sorting/Selection Sort/Images/output.jpg -------------------------------------------------------------------------------- /Sorting/Selection Sort/selection_sort.py: -------------------------------------------------------------------------------- 1 | def selectionSort(array, n): 2 | 3 | for i in range(n): 4 | minimum = i 5 | 6 | for j in range(i + 1, n): 7 | 8 | # to sort in descending order, change > to < in this line 9 | # select the minimum element in each loop 10 | if array[j] < array[minimum]: 11 | minimum = j 12 | 13 | # put min at the correct position 14 | (array[i], array[minimum]) = (array[minimum], array[i]) 15 | 16 | 17 | data = [ ] 18 | size = int(input("Enter size of array : ")) 19 | print("Enter array elements: ") 20 | for i in range(size): 21 | e=int(input()) 22 | data.append(e) 23 | selectionSort(data, size) 24 | print('Sorted Array in Ascending Order:') 25 | print(data) -------------------------------------------------------------------------------- /Sorting/Shell Sort/Images/Output1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Sorting/Shell Sort/Images/Output1.png -------------------------------------------------------------------------------- /Sorting/Shell Sort/Images/Output2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Sorting/Shell Sort/Images/Output2.png -------------------------------------------------------------------------------- /Sorting/Shell Sort/Images/shell_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Sorting/Shell Sort/Images/shell_sort.png -------------------------------------------------------------------------------- /Sorting/Shell Sort/shell_sort.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of Shell Sort 2 | ''' 3 | Shell sort is a highly efficient sorting algorithm and is based on insertion sort algorithm. 4 | Shell sort is the generalization of insertion sort which overcomes the drawbacks of insertion sort by comparing elements separated by a gap of several positions. 5 | 6 | Shell sort divides the array in the form of N/2 , N/4 , …, 1 (where N is the length of array) 7 | and then sorting is done. This breaking of sequence and sorting takes place until the entire array is sorted. 8 | ''' 9 | 10 | def shellSort(arr): 11 | 12 | # Start with a big gap, then reduce the gap 13 | size = len(arr) 14 | gap = size // 2 15 | 16 | # Do a gapped insertion sort for this gap size. 17 | while gap > 0: 18 | 19 | for i in range(gap, size): 20 | 21 | # add a[i] to the elements that have been gap sorted 22 | # save a[i] in temp and make a hole at position i 23 | temp = arr[i] 24 | 25 | # shift earlier gap-sorted elements up until the correct 26 | # location for a[i] is found 27 | j = i 28 | while j >= gap and arr[j - gap] > temp: 29 | arr[j] = arr[j - gap] 30 | j -= gap 31 | 32 | # put temp (the original a[i]) in its correct location 33 | arr[j] = temp 34 | gap //= 2 35 | 36 | 37 | arr = [] 38 | size = int(input('Enter size: ')) 39 | print ('Enter elements:') 40 | for i in range(0, size): 41 | item = int(input()) 42 | arr.append(item) 43 | 44 | shellSort(arr) 45 | 46 | print ('\nSorted Array:') 47 | for i in range(size): 48 | print (arr[i]) 49 | 50 | ''' 51 | INPUT 52 | Enter size: 5 53 | Enter elements: 54 | 5 55 | 4 56 | 3 57 | 2 58 | 1 59 | 60 | Sorted Array: 61 | 1 62 | 2 63 | 3 64 | 4 65 | 5 66 | 67 | Time Complexity: O(n^2) 68 | Space Complexity: O(1) 69 | ''' 70 | -------------------------------------------------------------------------------- /Stacks/Infix to Postfix Conversion/Images/infix_to_postfix_conversion1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Stacks/Infix to Postfix Conversion/Images/infix_to_postfix_conversion1.PNG -------------------------------------------------------------------------------- /Stacks/Infix to Postfix Conversion/Images/infix_to_postfix_conversion2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Stacks/Infix to Postfix Conversion/Images/infix_to_postfix_conversion2.PNG -------------------------------------------------------------------------------- /Stacks/Infix to Postfix Conversion/Images/infix_to_postfix_conversion3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Stacks/Infix to Postfix Conversion/Images/infix_to_postfix_conversion3.PNG -------------------------------------------------------------------------------- /Stacks/Infix to Postfix Conversion/README.md: -------------------------------------------------------------------------------- 1 | # Infix to Postfix Conversion 2 | 3 | 4 | ## Aim 5 | 6 | The aim is to create a python code to convert an infix expression to its equivalent postfix expression 7 | 8 | ## Purpose 9 | 10 | The purpose is to come up with an efficient solution while implementing stacks (if any) 11 | 12 | ## Short description of project 13 | 14 | The project takes in input the infix expression to be converted, 15 | and then it parses through the expression, checking the type of character and performing the required operation according to the algorithm. 16 | The resultant postfix expression is then returned and printed. 17 | 18 | ## Workflow of the Project 19 | 20 | Description of functions used in the code and their purpose: 21 | 22 | isEmpty --> Function, takes in a list, returns True if it is empty, and False if not 23 | 24 | infix_to_postfix --> Converts infix expression to postfix using stack, takes argument : infix expression string, returns : equivalent postfix expressiion string 25 | 26 | After the infix expression is passed to the infix_to_postfix function, control is passed to that function, it uses the stack algorithm to generate the equivalent postfix expression and returns it, 27 | which is then printed with a proper output by the driver code. 28 | 29 | ## Required libraries 30 | 31 | None 32 | 33 | ## Compilation Steps 34 | Run the script, after that : 35 | 36 | 1. The expression is made manually here, to focus on conversion part 37 | 2. The program tells the equivalent postfix expression 38 | 39 | 40 | 41 | # Output 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | ## Author 50 | [Pushpit Jain](https://github.com/pushpit-J19) 51 | -------------------------------------------------------------------------------- /Stacks/README.md: -------------------------------------------------------------------------------- 1 | # Stacks 2 | 3 | ## Check out all the amazing scripts using 'Stacks' here: 4 | 5 | - [Infix to Postfix Conversion](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Stacks/Infix%20to%20Postfix%20Conversion) 6 | -------------------------------------------------------------------------------- /Streaming/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Strings/Bad String/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Strings/Bad String/Images/ss.png -------------------------------------------------------------------------------- /Strings/Bad String/README.md: -------------------------------------------------------------------------------- 1 | # Bad String 2 | 3 | ## Aim 4 | 5 | Read a string, S and print its integer value. If S cannot be converted to an integer, print Bad String. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to explore strings and try and except keywords in python. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - The user enters a string. 16 | - Try and except blocks are used to avoid getting an error. 17 | 18 | 19 | ## Workflow of the Project 20 | 21 | try --> if it's possible to convert the entered string into an integer then this block will execute. 22 | 23 | except --> if it's not possible, then this block will be executed 24 | 25 | In try block, 'int' function is used for conversion, if this results in an error the control goes to except block where a print statement gets executed. 26 | 27 | 28 | ## Compilation Steps 29 | 30 | After the script is run, enter: 31 | 32 | 1. A string. 33 | 34 | That's it! If it's possible to convert it into integer, then you'll get the integer else you'll see a 'Bad String' alert. 35 | 36 | 37 | ## Output 38 | 39 | 40 | 41 | 42 | ## Author 43 | 44 | [Manasi Chhibber](https://github.com/Manasi2001) 45 | -------------------------------------------------------------------------------- /Strings/Bad String/bad_string.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Aim: Read a string, S and print its integer value. If S cannot be converted to 3 | an integer, print Bad String. 4 | 5 | ''' 6 | 7 | # getting the input 8 | S = input().strip() 9 | try: 10 | # if it's possible to convert the entered string into an integer then this block will execute 11 | print(int(S)) 12 | except: 13 | # if it's not possible, then this block will be executed 14 | print('Bad String') 15 | 16 | ''' 17 | COMPLEXITY: 18 | 19 | Time Complexity -> O(1) 20 | Space Complexity -> O(1) 21 | 22 | Sample Input 1: 23 | 3 24 | Sample Output 1: 25 | 3 26 | Sample Input 2: 27 | SB 28 | Sample Output 2: 29 | Bad String 30 | 31 | Explaination: 32 | '3' as a string can be converted into the integer 3, whereas SB can't be 33 | converted to an integer hence the 'except' block is executed and 'Bad String' 34 | is printed. 35 | 36 | ''' -------------------------------------------------------------------------------- /Strings/Capitalizing/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Strings/Capitalizing/Images/ss.png -------------------------------------------------------------------------------- /Strings/Capitalizing/README.md: -------------------------------------------------------------------------------- 1 | # Capitalizing 2 | 3 | ## Aim 4 | 5 | To replace the first character of all the words with their upper case characters. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to explore string functions like slicing. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - The user enters a string consisting of space separated words. 16 | - The string is sliced on the basis of spaces and the first letter of each word is capitalized. 17 | 18 | 19 | ## Workflow of the Project 20 | 21 | - According to all the spaces in the string, words in the string are split. 22 | - First letter of each word is then capitalized using `capitalize()` function. 23 | - Updated string is then printed out. 24 | 25 | 26 | ## Compilation Steps 27 | 28 | After the script is run, enter: 29 | 30 | 1. Enter the string. 31 | 32 | That's it! First letter of all the words in the string is capitalized. 33 | 34 | 35 | ## Output 36 | 37 | 38 | 39 | 40 | ## Author 41 | 42 | [Manasi Chhibber](https://github.com/Manasi2001) 43 | -------------------------------------------------------------------------------- /Strings/Capitalizing/capitalizing.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Aim: To replace the first character of all the words with their upper case characters. 3 | 4 | ''' 5 | 6 | # Complete the solve function below. 7 | def solve(s): 8 | # splitting the string into words 9 | for x in s[:].split(): 10 | # replacing the character with it's capital form 11 | s = s.replace(x, x.capitalize()) 12 | print('Updated string:',s) 13 | 14 | # getting the input 15 | s = input('Enter string: ') 16 | # calling function to compute the result 17 | solve(s) 18 | 19 | ''' 20 | COMPLEXITY: 21 | 22 | Time Complexity -> O(N) 23 | Space Complexity -> O(N) 24 | 25 | Sample Input: 26 | Enter string: summer of code 27 | 28 | Sample Output: 29 | Updated string: Summer Of Code 30 | 31 | Explanation: 32 | All the initial characters of the words are capitalized. 33 | 34 | ''' -------------------------------------------------------------------------------- /Strings/Determining DNA Health/Images/dna1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Strings/Determining DNA Health/Images/dna1.png -------------------------------------------------------------------------------- /Strings/Determining DNA Health/Images/dna2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Strings/Determining DNA Health/Images/dna2.png -------------------------------------------------------------------------------- /Strings/Determining DNA Health/Images/dna3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Strings/Determining DNA Health/Images/dna3.png -------------------------------------------------------------------------------- /Strings/Determining DNA Health/Images/dna4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Strings/Determining DNA Health/Images/dna4.png -------------------------------------------------------------------------------- /Strings/Determining DNA Health/Images/dna5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Strings/Determining DNA Health/Images/dna5.png -------------------------------------------------------------------------------- /Strings/README.md: -------------------------------------------------------------------------------- 1 | # Strings 2 | 3 | ## Check out all the amazing scripts related to 'Strings' here: 4 | 5 | - [Bad String](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Strings/Bad%20String) 6 | - [Capitalizing](Capitalizing/capitalizing.py) 7 | - [Determining DNA Health](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Strings/Determining%20DNA%20Health) 8 | -------------------------------------------------------------------------------- /Tests/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Traversals/Inorder Preorder Postorder/Images/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Traversals/Inorder Preorder Postorder/Images/output.png -------------------------------------------------------------------------------- /Traversals/README.md: -------------------------------------------------------------------------------- 1 | ## Check out all the amazing scripts for 'Traversals' here: 2 | 3 | - [Inorder, Preorder, and Postorder Traversal of Tree](Inorder%20Preorder%20Postorder/inorder_preorder_postorder.py) 4 | -------------------------------------------------------------------------------- /Trees/BST Level Order Traversal/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/BST Level Order Traversal/Images/ss.png -------------------------------------------------------------------------------- /Trees/BST Level Order Traversal/README.md: -------------------------------------------------------------------------------- 1 | # BST - Level Order Traversal 2 | 3 | ## Aim 4 | 5 | To perform Level Order Traversal on a Binary Search Tree. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to explore a type of traversal for BST. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - The user enters the numbers to be used for constructing a BST. 16 | - The BST is constructed according to the rules, with each node having an element entered by the user. 17 | - Level by level the numbers are displayed. 18 | 19 | 20 | ## Workflow of the Project 21 | 22 | - The tree is initialized. 23 | - Nodes are inserted. 24 | - Level order traversal is performed. 25 | - The values will be printed according to the level they are in. 26 | 27 | 28 | ## Compilation Steps 29 | 30 | After the script is run, enter: 31 | 32 | 1. Total number of nodes. 33 | 2. All the nodes one by one. 34 | 35 | That's it! The numbers will accordingly get printed. 36 | 37 | 38 | ## Output 39 | 40 | 41 | 42 | 43 | ## Author 44 | 45 | [Manasi Chhibber](https://github.com/Manasi2001) 46 | -------------------------------------------------------------------------------- /Trees/Binary Search Tree/Images/output1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Binary Search Tree/Images/output1.png -------------------------------------------------------------------------------- /Trees/Binary Search Tree/Images/output2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Binary Search Tree/Images/output2.png -------------------------------------------------------------------------------- /Trees/Binary Search Tree/Images/output3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Binary Search Tree/Images/output3.png -------------------------------------------------------------------------------- /Trees/Binary Search Tree/Images/output4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Binary Search Tree/Images/output4.png -------------------------------------------------------------------------------- /Trees/Binary Search Tree/Images/output5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Binary Search Tree/Images/output5.png -------------------------------------------------------------------------------- /Trees/Binary Tree To DLL/Images/binary_tree_to_dll_output1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Binary Tree To DLL/Images/binary_tree_to_dll_output1.PNG -------------------------------------------------------------------------------- /Trees/Binary Tree To DLL/Images/binary_tree_to_dll_output2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Binary Tree To DLL/Images/binary_tree_to_dll_output2.PNG -------------------------------------------------------------------------------- /Trees/Binary Tree To DLL/Images/binary_tree_to_dll_output3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Binary Tree To DLL/Images/binary_tree_to_dll_output3.PNG -------------------------------------------------------------------------------- /Trees/Expression Tree Evaluation/Images/expression_tree_evaluation_output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Expression Tree Evaluation/Images/expression_tree_evaluation_output.PNG -------------------------------------------------------------------------------- /Trees/Expression Tree Evaluation/Images/expression_tree_evaluation_output2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Expression Tree Evaluation/Images/expression_tree_evaluation_output2.PNG -------------------------------------------------------------------------------- /Trees/Expression Tree Evaluation/README.md: -------------------------------------------------------------------------------- 1 | # Expression Tree Evaluation 2 | 3 | 4 | ## Aim 5 | 6 | The aim is to create a python code to evaluate an expression tree using recursion 7 | 8 | ## Purpose 9 | 10 | The purpose is to come up with an efficient solution while implementing recursion (if any) 11 | 12 | ## Short description of project 13 | 14 | The project takes in input the expression tree to be checked, 15 | and then checks the evaluated the from the root node, bu recursively calling its left and right subtrees. 16 | 17 | ## Workflow of the Project 18 | 19 | Description of functions used in the code and their purpose: 20 | 21 | Node --> Class to define each node of the tree 22 | 23 | expression_tree_evaluation --> recursive method to evaluate expression tree 24 | 25 | After the root node of the tree is passed to the function, the control is passed to the isPalindrome function, which returns the evaluated value, 26 | which is then printed with an appropriate output to the user. 27 | 28 | ## Required libraries 29 | 30 | None 31 | 32 | ## Compilation Steps 33 | Run the script, after that : 34 | 35 | 1. The expression tree is made manually here, to focus on evaluation part 36 | 2. The program tells the value of the expression calculated from the tree 37 | 38 | 39 | 40 | # Output 41 | 42 | 43 | 44 | 45 | 46 | 47 | ## Author 48 | [Pushpit Jain](https://github.com/pushpit-J19) 49 | -------------------------------------------------------------------------------- /Trees/Height of a BST/Images/ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Height of a BST/Images/ss.png -------------------------------------------------------------------------------- /Trees/Height of a BST/README.md: -------------------------------------------------------------------------------- 1 | # Height of BST 2 | 3 | ## Aim 4 | 5 | To form a Binary Search Tree of the integers entered and display its height. 6 | 7 | 8 | ## Purpose 9 | 10 | The purpose is to work with trees. 11 | 12 | 13 | ## Short description of package/script 14 | 15 | - The user enters the numbers to be used for constructing a BST. 16 | - The BST is constructed according to the rules, with each node having an element entered by the user. 17 | - A recursive function calculates the height of the tree. 18 | 19 | 20 | ## Workflow of the Project 21 | 22 | - The tree is initialized. 23 | - Nodes are inserted. 24 | - Recursion is performed. 25 | - Height is accordingly printed. 26 | 27 | 28 | ## Compilation Steps 29 | 30 | After the script is run, enter: 31 | 32 | 1. Total number of nodes. 33 | 2. All the nodes one by one. 34 | 35 | That's it! The height of the BST thus formed will get printed. 36 | 37 | 38 | ## Output 39 | 40 | 41 | 42 | 43 | ## Author 44 | 45 | [Manasi Chhibber](https://github.com/Manasi2001) 46 | 47 | -------------------------------------------------------------------------------- /Trees/Height of a BST/height_of_BST.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Aim: To form a Binary Search Tree of the integers entered and display its height. 3 | 4 | ''' 5 | 6 | # initializing the tree 7 | class Node: 8 | def __init__(self,data): 9 | self.right=self.left=None 10 | self.data = data 11 | 12 | class Solution: 13 | # function for inserting values according to BST rules 14 | def insert(self,root,data): 15 | if root == None: 16 | return Node(data) 17 | else: 18 | if data <= root.data: 19 | cur = self.insert(root.left,data) 20 | root.left = cur 21 | else: 22 | cur = self.insert(root.right,data) 23 | root.right = cur 24 | return root 25 | 26 | # calculating the height of the tree 27 | def getHeight(self,root): 28 | if root == None: 29 | return -1 30 | return 1 + max(self.getHeight(root.left), self.getHeight(root.right)) 31 | 32 | # getting the input for total number of integers to be entered 33 | T = int(input()) 34 | # making an object of the class 35 | myTree = Solution() 36 | root = None 37 | 38 | # inserting values 39 | for i in range(T): 40 | data = int(input()) 41 | root = myTree.insert(root,data) 42 | # geeting the height calculated 43 | height = myTree.getHeight(root) 44 | 45 | # printing the result 46 | print("Height of BST:",height) 47 | 48 | ''' 49 | COMPLEXITY: 50 | 51 | Time Complexity -> O(N) 52 | Space Complexity -> O(N) 53 | 54 | Sample Input: 55 | 7 56 | 3 57 | 5 58 | 2 59 | 1 60 | 4 61 | 6 62 | 7 63 | Sample Output: 64 | Height of BST: 3 65 | 66 | Explaination: 67 | The BST looks something like this: 68 | 69 | 3 70 | 2 5 71 | 1 4 6 72 | 7 73 | 74 | So, the height is --> 3. 75 | 76 | ''' -------------------------------------------------------------------------------- /Trees/Lowest Common Ancestor Binary Search Tree/Images/lowest_common_ancestor_binary_search_tree_output1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Lowest Common Ancestor Binary Search Tree/Images/lowest_common_ancestor_binary_search_tree_output1.PNG -------------------------------------------------------------------------------- /Trees/Lowest Common Ancestor Binary Search Tree/Images/lowest_common_ancestor_binary_search_tree_output2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Lowest Common Ancestor Binary Search Tree/Images/lowest_common_ancestor_binary_search_tree_output2.PNG -------------------------------------------------------------------------------- /Trees/Lowest Common Ancestor Binary Search Tree/Images/lowest_common_ancestor_binary_search_tree_output3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Lowest Common Ancestor Binary Search Tree/Images/lowest_common_ancestor_binary_search_tree_output3.PNG -------------------------------------------------------------------------------- /Trees/Lowest Common Ancestor Binary Tree/Images/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Trees/Lowest Common Ancestor Binary Tree/Images/lowest_common_ancestor_binary_tree_output1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Lowest Common Ancestor Binary Tree/Images/lowest_common_ancestor_binary_tree_output1.PNG -------------------------------------------------------------------------------- /Trees/Lowest Common Ancestor Binary Tree/Images/lowest_common_ancestor_binary_tree_output2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Lowest Common Ancestor Binary Tree/Images/lowest_common_ancestor_binary_tree_output2.PNG -------------------------------------------------------------------------------- /Trees/Lowest Common Ancestor Binary Tree/Images/lowest_common_ancestor_binary_tree_output3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Lowest Common Ancestor Binary Tree/Images/lowest_common_ancestor_binary_tree_output3.PNG -------------------------------------------------------------------------------- /Trees/Lowest Common Ancestor Binary Tree/Images/lowest_common_ancestor_binary_tree_output4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Lowest Common Ancestor Binary Tree/Images/lowest_common_ancestor_binary_tree_output4.PNG -------------------------------------------------------------------------------- /Trees/README.md: -------------------------------------------------------------------------------- 1 | ## Check out all the amazing scripts using 'Trees' here: 2 | 3 | - [BST Level Order Traversal](BST%20Level%20Order%20Traversal/BST_level_order_traversal.py) 4 | - [Binary Tree To DLL](Binary%20Tree%20To%20DLL/binary_tree_to_dll.py) 5 | - [Expression Tree Evaluation](Expression%20Tree%20Evaluation/expression_tree_evaluation.py) 6 | - [Height of a BST](Height%20of%20a%20BST/height_of_BST.py) 7 | - [Lowest Common Ancestor Binary Tree](Lowest%20Common%20Ancestor%20Binary%20Tree/lowest_common_ancestor_binary_tree.py) 8 | - [Lowest Common Ancestor Binary Search Tree](Lowest%20Common%20Ancestor%20Binary%20Search%20Tree/lowest_common_ancestor_binary_search_tree.py) 9 | - [Segment Tree Creation](Segment%20Tree%20Creation/segment_tree_creation.py) 10 | - [Segment Tree Update Query](Segment%20Tree%20Update%20Query/segment_tree_update_query.py) 11 | - [Segment Tree Range Sum Query](Segment%20Tree%20Range%20Sum%20Query/segment_tree_sum_range_query.py) 12 | - [Binary Search Tree](https://github.com/prathimacode-hub/PyAlgo-Tree/tree/main/Trees/Binary%20Search%20Tree) 13 | -------------------------------------------------------------------------------- /Trees/Segment Tree Creation/Images/creation_output1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Segment Tree Creation/Images/creation_output1.PNG -------------------------------------------------------------------------------- /Trees/Segment Tree Creation/Images/creation_output2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Segment Tree Creation/Images/creation_output2.PNG -------------------------------------------------------------------------------- /Trees/Segment Tree Creation/Images/creation_output3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Segment Tree Creation/Images/creation_output3.PNG -------------------------------------------------------------------------------- /Trees/Segment Tree Creation/README.md: -------------------------------------------------------------------------------- 1 | # Segment tree Creation 2 | 3 | 4 | ## Aim 5 | 6 | The aim is to create a python code to create a segment tree of a given array of numbers 7 | 8 | ## Purpose 9 | 10 | The purpose is to come up with an efficient solution (if any) 11 | 12 | ## Short description of project 13 | 14 | The project takes in input the array whose segment tree needs to be created, 15 | and then it parses through the array, summing the array elements, creating the tree. 16 | The resultant segment tree is then returned and printed. 17 | 18 | ## Workflow of the Project 19 | 20 | Description of functions used in the code and their purpose: 21 | 22 | segment_tree_creation --> Function, takes in a list, returns corresponding segment tree 23 | 24 | After the list is passed to the segment_tree_creation function, control is passed to that function, it uses the iterative approach to generate the segment tree and returns it, 25 | which is then printed with a proper output by the driver code. 26 | 27 | ## Required libraries 28 | 29 | math library --> for ceil and log2 functions 30 | 31 | ## Compilation Steps 32 | Run the script, after that : 33 | 34 | 1. The expression is made manually here, to focus on conversion part 35 | 2. The program tells the equivalent segment tree 36 | 37 | 38 | 39 | # Output 40 | 41 | 42 | 43 | 44 | 45 | 46 | ## Author 47 | [Pushpit Jain](https://github.com/pushpit-J19) 48 | -------------------------------------------------------------------------------- /Trees/Segment Tree Range Sum Query/Images/range_sum_query_output1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Segment Tree Range Sum Query/Images/range_sum_query_output1.PNG -------------------------------------------------------------------------------- /Trees/Segment Tree Range Sum Query/Images/range_sum_query_output2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Segment Tree Range Sum Query/Images/range_sum_query_output2.PNG -------------------------------------------------------------------------------- /Trees/Segment Tree Range Sum Query/README.md: -------------------------------------------------------------------------------- 1 | # Segment Tree Range Sum Query 2 | 3 | 4 | ## Aim 5 | 6 | The aim is to create a python code to do range sum query on a segment tree of a given array of numbers 7 | ## Purpose 8 | 9 | The purpose is to come up with an efficient solution (if any) 10 | 11 | ## Short description of project 12 | 13 | The project takes in input the array, 14 | and then it is converted to a segment tree and returned to a new variable, 15 | then queries are called to do range sum over a range and the answer is then printed 16 | 17 | ## Workflow of the Project 18 | 19 | Description of functions used in the code and their purpose: 20 | 21 | segment_tree_creation --> Function, takes in a list, returns corresponding segment tree 22 | 23 | segment_tree_range_sum_query --> Function, takes in tree, lower and upper index of range whose sum is to be calculated, returns the sum 24 | 25 | After the list is passed to the segment_tree_creation function, control is passed to that function, it uses the iterative approach to generate the segment tree and returns it, 26 | this segment tree is passed to the segment_tree_range_sum_query function, which calculates the sum in the given range and returns it, which is then printed 27 | 28 | ## Required libraries 29 | 30 | math library --> for ceil and log2 functions 31 | 32 | ## Compilation Steps 33 | Run the script, after that : 34 | 35 | 1. The expression is made manually here, to focus on conversion part 36 | 2. The program tells the equivalent segment tree 37 | 3. The program is then run to do range sum queries, and it shows the updated array and tree 38 | 39 | 40 | 41 | # Output 42 | 43 | 44 | 45 | 46 | 47 | 48 | ## Author 49 | [Pushpit Jain](https://github.com/pushpit-J19) 50 | -------------------------------------------------------------------------------- /Trees/Segment Tree Update Query/Images/update_query_output1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Segment Tree Update Query/Images/update_query_output1.PNG -------------------------------------------------------------------------------- /Trees/Segment Tree Update Query/Images/update_query_output2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prathimacode-hub/PyAlgo-Tree/0ca0e0f3c423c3cb6e94960213ad446e06f1c81e/Trees/Segment Tree Update Query/Images/update_query_output2.PNG -------------------------------------------------------------------------------- /Trees/Segment Tree Update Query/README.md: -------------------------------------------------------------------------------- 1 | # Segment tree Update Query 2 | 3 | 4 | ## Aim 5 | 6 | The aim is to create a python code to do update query on a segment tree of a given array of numbers to store the sums 7 | 8 | ## Purpose 9 | 10 | The purpose is to come up with an efficient solution (if any) 11 | 12 | ## Short description of project 13 | 14 | The project takes in input the array, 15 | and then it is converted to a segment tree and returned to a new variable, 16 | then queries are called to update, which start from leaf node updating the array element, 17 | moving up to the root node, updating the nodes. 18 | 19 | ## Workflow of the Project 20 | 21 | Description of functions used in the code and their purpose: 22 | 23 | segment_tree_creation --> Function, takes in a list, returns corresponding segment tree 24 | 25 | segment_tree_update_query --> Function, takes in array, tree, index and new value to be updated, returns the updated array and tree 26 | 27 | After the list is passed to the segment_tree_creation function, control is passed to that function, it uses the iterative approach to generate the segment tree and returns it, 28 | this segment tree is passed to the segment_tree_update_query function, which updates all the nodes from that array element (leaf) to the root. 29 | 30 | ## Required libraries 31 | 32 | math library --> for ceil and log2 functions 33 | 34 | ## Compilation Steps 35 | Run the script, after that : 36 | 37 | 1. The expression is made manually here, to focus on conversion part 38 | 2. The program tells the equivalent segment tree 39 | 3. The program is then run to update queries, and it shows the updated array and tree 40 | 41 | 42 | 43 | # Output 44 | 45 | 46 | 47 | 48 | 49 | ## Author 50 | [Pushpit Jain](https://github.com/pushpit-J19) 51 | -------------------------------------------------------------------------------- /Unix/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman --------------------------------------------------------------------------------