├── Ai ├── 3steps-neural_network.md ├── AI_Environments.md ├── A_star_Algorithm.md ├── Ai.md ├── Alpha-Beta-pruning.md ├── Ann.md ├── bayes_theorem.md ├── data-links.md ├── html.jpg ├── min_max_algorithm.md ├── neural-network.md ├── reinforcement_learning.md └── state_space_search.md ├── C++ ├── [feature Added Game to Guess Numbers] ├── cpp.md ├── digitalclock.cpp └── fractional knapsack.cpp ├── CONTRIBUTING.md ├── CSS Framework └── css-framework.md ├── Cloud └── Cloud-Computing.md ├── Computer Network & Security ├── Computer_network.md ├── Information Security.md ├── Interview_Questions.md ├── Threat_Actor.md ├── Threat_intelligence.md ├── authentication_controls.md ├── cryptographic_concept.md ├── malware.md ├── network_security.md ├── password_attacks.md └── social_engineering.md ├── Computer Organisation and Architecture ├── InstructionSetArchitecture.md ├── MemoryAddressing.md └── SingleBusOrganisation.md ├── Computer Program Games ├── Tic Tac Toe │ ├── readme.md │ └── tic_tac_toe.py └── TicTacToe_2P │ ├── README.md │ ├── TicTacToe_2P.md │ └── image │ ├── o.png │ ├── tictactoe.png │ └── x1.2.png ├── Contributors List ├── Apoorv266.md ├── Avni Arora.md ├── Caffeine-Overflows.md ├── Chitrakshi2531.md ├── DCBisht.md ├── Hariom.md ├── Krishanu_Chakraborty.md ├── README.md ├── Ritik Kumar.md ├── ShashvatJain.md ├── SreeHaran.md ├── Srishti2128.md ├── TGFlame.md ├── Vaishnvee-Shinde.md ├── [feature Added contributing.md file] ├── aaakashkumar.md ├── adityaajay29.md ├── its-red-eagle.md ├── jerik-george.md ├── mayank.md ├── nandini.md ├── phoenix.md ├── roshan-byte.md ├── sushant_agawane.md └── theDreamer911.md ├── DBMS ├── DBMS_resources.md ├── Database Management System │ └── readme.md ├── Database Transactions.md ├── ER Model │ ├── 12310.png │ ├── 33333-1.png │ ├── Database-Management-S-ystem-ER-Model-9.png │ ├── Database-Management-System-ER-Model-10.png │ ├── Database-Management-System-ER-Model-12.png │ ├── Database-Management-System-ER-Model-13.png │ ├── Database-Management-System-ER-Model-14.png │ ├── Database-Management-System-ER-Model-15.png │ ├── Database-Management-System-ER-Model-16.png │ ├── Database-Management-System-ER-Model-17.png │ ├── Database-Management-System-ER-Model-18.png │ ├── Database-Management-System-ER-Model-2.png │ ├── Database-Management-System-ER-Model-3.png │ ├── Database-Management-System-ER-Model-4.png │ ├── Database-Management-System-ER-Model-5.png │ ├── Database-Management-System-ER-Model-6.png │ ├── Database-Management-System-ER-Model-7.png │ ├── Database-Management-System-ER-Model-8.png │ ├── Database-Management-System-ER-Model.png │ └── readme.md ├── Indexing-and-RAID.md └── Normalization │ └── readme.md ├── Data Structures and Algorithms ├── Best_Time_to_Buy_and_Sell_Stock_I.md ├── Best_Time_to_Buy_and_Sell_Stock_II.md ├── Binary-Search-Tree ├── Breadth-First-Search.md ├── Circular_Linked_List ├── DP │ ├── 01-knapsak.cpp │ ├── Coin_Change.md │ ├── Coin_Change_II.md │ ├── Longest_Common_subsquence.md │ └── Longest_Increasing_subsquence.md ├── Depth-First-Search.md ├── Dijkstra's Algorithm.cpp ├── Graph │ ├── Bipartite_graph.cpp │ ├── Dense_Graph_vs_Sparse_graph.txt │ ├── Maximum_Diameter_in_N_ary_tree.cpp.cpp │ ├── Robber_&_you.cpp │ ├── Rotten_Oranges_(Multisource_BFS).cpp │ ├── Simple_Prim's.cpp.txt │ ├── Standard Algos │ │ ├── Dijiktra's_Algo.cpp │ │ ├── Disjoint_set.cpp │ │ ├── Graph_Articulation_point_and_Bridges.cpp │ │ ├── Kahn's_Algo_(Topological_sort_BFS).cpp │ │ ├── Kosaraju_SCC(Strongly_Connected_Components).cpp │ │ ├── Kruskal_algo.cpp.txt │ │ ├── Prim's_Algorithm.cpp │ │ ├── Prim's_algo.cpp.txt │ │ └── floyd_Warshell.cpp │ ├── Topological_sort_DFS.cpp.txt │ ├── labyrinth_cses_graph.cpp │ ├── round_trip.cpp │ └── sum_from_each_node_to_each_node.cpp ├── Heap.md ├── Kadens_algorithm.cpp ├── LRU_Cache.cpp ├── LinkedList │ ├── Intersection of Two Linked List │ │ ├── Approach_1.cpp │ │ └── Approach_2.cpp │ ├── Linked List Cycle ll │ │ ├── Approach_1.cpp │ │ └── Approach_2.cpp │ ├── merge_k_sorted_list.cpp │ ├── palindrome_linked_list.cpp │ ├── reorder_list.cpp │ ├── rotate_list.cpp │ ├── sort_list.cpp │ └── sorted_list_to_binary_search_tree.cpp ├── Manacher's_Algo.cpp ├── Merge_Sort_Algorithm.md ├── Queue ├── Rabin-Karp-String-Matching-Algo.md ├── Segment Tree │ ├── Explanation.txt │ ├── Range_minimum_query.cpp │ └── Range_sum_query.cpp ├── Sliding-Window-Algo.md ├── Sorting Algos │ ├── Bucket_sort.cpp │ ├── Count_sort.cpp │ ├── Merger_Sort.cpp │ └── Quicksort.cpp ├── Sparse Matrix ├── Stack ├── String Maching Algos │ ├── Knuth_Morris_Pratt.cpp.txt │ └── Z_Algo.cpp.txt ├── Tim-Sort.md ├── Trie Data Structure │ ├── Trie Algorithm │ ├── bhumithakur.md │ └── explanation of trie with pseudocode ├── binary-search.md └── two_pointer_technique.md ├── DevOps ├── CircleCI.md ├── Docker.md ├── Introduction to DevOps.md ├── Jenkins.md ├── Kubernetes.md ├── Linux └── Terraform.md ├── Euclid_algo └── gcd.cpp ├── Euler Totient └── code.cpp ├── Java ├── Calculator.java ├── Currency_converter.java ├── Java Basics.md ├── Variables in Java.md ├── conditional.md └── javaAsLanguage.md ├── Javascript for react ├── 1. Arrow functions.md ├── 2. Import export.md ├── 3. Classes.md ├── 4. Spread and rest operator.md └── 5. Destructuring.md ├── LICENSE ├── Machine Learning ├── CNN1.ipynb ├── RNN.ipynb ├── computer_vision_interview.md ├── deep-learning.md └── machine-learning.md ├── OOPs ├── oops-basics.md └── oops_interview_questions.md ├── Operating System ├── Deadlock.md ├── First Come First Serve Algorithm.md ├── Interview_Questions.md ├── Priority Scheduling.md ├── Process Synchronization.md ├── Round Robin Scheduling Algorithm.md ├── Scheduling Algorithm (SJF).md ├── Semaphore and Thrashing.md ├── Threads_and_Concurrency.md ├── backbone_os.md ├── boot_grub.md ├── idt_interrupt.md ├── memory_management.md ├── os.md ├── virtual_os.md └── x86_os.md ├── Programming Languages ├── Types.md └── introduction.md ├── Python ├── Python Basics ├── Python Projects For Beginners ├── Python_Interview_Questions ├── Shape_AI.ipynb ├── [feature] PasswordManager ├── algorithmia.md ├── contact_list.py ├── email_slicer.py ├── img_to_sketch.py ├── person_correlation.py ├── python.md ├── python_interview_questions.md ├── qr_generator.py └── rock_pape_scissors.py ├── README.md ├── React ├── 1. Intro.md ├── 2. Setting Up React.md ├── 3. Modifying React Application.md ├── 4. ES6.md ├── 5. React Render.md ├── 6. React JSX.md ├── 7. React Components.md └── react_best_practices.md ├── SQL ├── Commands.md ├── Introduction.md ├── SQL Clause.md ├── SQL Keys.md ├── SQL Select.md ├── SQL_Joins.md └── sql_interview_questions.md ├── Theory of Computation and Compiler Design ├── Aspose.Words.0622bb25-4a63-4e23-9ca4-4aede3188d90.001.png ├── Aspose.Words.0622bb25-4a63-4e23-9ca4-4aede3188d90.002.png ├── Aspose.Words.0622bb25-4a63-4e23-9ca4-4aede3188d90.003.jpeg ├── Aspose.Words.64b0950e-2857-417e-92b9-18dbe7754dd6.001.png ├── Aspose.Words.64b0950e-2857-417e-92b9-18dbe7754dd6.002.png ├── Compiler Design.md ├── TOC.md └── Theory-of-Computation notes.pdf └── Web Technology ├── Backend-design-roadmap.jpeg ├── Email-Checker ├── index.html └── index.php ├── Front-End-Frameworks-and-Libraries.png ├── IOT.md ├── WebTechnology.md └── solidity-cheatsheet.md /Ai/3steps-neural_network.md: -------------------------------------------------------------------------------- 1 | 2 | # Train a neural network in just 3 lines of code! 3 | # 4 | # the notes for this class can be found at: 5 | 6 | from __future__ import print_function, division 7 | from builtins import range 8 | 9 | # Note: you may need to update your version of future 10 | # sudo pip install -U future 11 | 12 | 13 | import sys 14 | sys.path.append('../ann_logistic_extra') 15 | from process import get_data 16 | 17 | from sklearn.neural_network import MLPClassifier 18 | from sklearn.utils import shuffle 19 | 20 | # get the data 21 | Xtrain, Ytrain, Xtest, Ytest = get_data() 22 | 23 | # create the neural network 24 | model = MLPClassifier(hidden_layer_sizes=(20, 20), max_iter=2000) 25 | 26 | # train the neural network 27 | model.fit(Xtrain, Ytrain) 28 | 29 | # print the train and test accuracy 30 | train_accuracy = model.score(Xtrain, Ytrain) 31 | test_accuracy = model.score(Xtest, Ytest) 32 | print("train accuracy:", train_accuracy, "test accuracy:", test_accuracy) -------------------------------------------------------------------------------- /Ai/AI_Environments.md: -------------------------------------------------------------------------------- 1 | # MOST COMMENLY KNOWN AI ENVIRONMENTS 2 | 3 | In the field of artificial intelligence (AI), there are various types of environments that serve as settings for AI agents to operate and learn. These environments can be classified into four main categories: fully observable, partially observable, deterministic, and stochastic. Each type of environment presents unique challenges and characteristics that influence how AI agents perceive and interact with their surroundings. 4 | 5 | # Fully Observable Deterministic Environment: 6 | 7 | In a fully observable deterministic environment, an AI agent has complete knowledge of the current state and can accurately predict the outcome of its actions. These environments are predictable and have no randomness or uncertainty. An example of such an environment is a game of chess. The AI agent can observe the entire chessboard and know the state of all the pieces. It can evaluate all possible moves and their consequences, allowing it to make optimal decisions. 8 | 9 | # Partially Observable Deterministic Environment: 10 | 11 | In a partially observable deterministic environment, an AI agent has limited or incomplete information about the current state. However, the environment itself is still deterministic, meaning that the outcomes of actions are predictable. A classic example is the game of Poker. The AI agent does not have access to the opponents' cards, which makes the state of the game partially observable. Despite the limited information, the agent can still apply strategies and make decisions based on the observed actions and probabilities. 12 | 13 | # Fully Observable Stochastic Environment: 14 | 15 | In a fully observable stochastic environment, an AI agent has complete knowledge of the current state, but the environment introduces randomness or uncertainty into the outcomes of actions. An example of this type of environment is a weather prediction system. The agent can observe the current weather conditions and apply mathematical models to forecast the future. However, due to the inherent unpredictability of weather patterns, the predictions will have some degree of uncertainty. 16 | 17 | # Partially Observable Stochastic Environment: 18 | 19 | In a partially observable stochastic environment, both incomplete information and randomness exist. This type of environment poses significant challenges for AI agents. An example is autonomous driving. The agent must make decisions based on the limited information available from sensors (such as cameras and lidar) and account for the uncertainty and unpredictability of other vehicles, pedestrians, and road conditions. 20 | 21 | It's worth noting that these categories are not mutually exclusive, and real-world environments often exhibit a combination of characteristics. AI researchers and engineers strive to develop algorithms and techniques that can handle the complexities of different environments, allowing AI agents to adapt, learn, and make informed decisions based on the available information. 22 | 23 | # SUMMARY 24 | 25 | In summary,the types of environments in AI can be classified based on observability (fully or partially observable) and determinism (deterministic or stochastic). Each type presents unique challenges and opportunities for AI agents, requiring the development of specialized algorithms and approaches to effectively navigate and interact with their surroundings. 26 | 27 | -------------------------------------------------------------------------------- /Ai/A_star_Algorithm.md: -------------------------------------------------------------------------------- 1 | 2 | # A* algorithm in Python: 3 | 4 | import heapq 5 | 6 | # CREATING A NODE 7 | class Node: 8 | def __init__(self, position, parent=None): 9 | self.position = position 10 | self.parent = parent 11 | self.g = 0 12 | self.h = 0 13 | self.f = 0 14 | 15 | def __lt__(self, other): 16 | return self.f < other.f 17 | 18 | # A METHOD TO CALCULATE THE DISTANCE FROM START TO END 19 | def calculate_distance(start, end): 20 | # Euclidean distance heuristic 21 | return ((end[0] - start[0]) ** 2 + (end[1] - start[1]) ** 2) ** 0.5 22 | 23 | # A METHOD TO START A * 24 | def a_star(grid, start, end): 25 | rows = len(grid) 26 | cols = len(grid[0]) 27 | 28 | # Define the possible movements (right, left, down, up, diagonals) 29 | 30 | movements = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (-1, 1), (1, -1), (-1, -1)] 31 | 32 | open_list = [] 33 | closed_set = set() 34 | 35 | start_node = Node(start) 36 | end_node = Node(end) 37 | 38 | heapq.heappush(open_list, start_node) 39 | 40 | # LOOP TO PERFORME THE ITERATIONS 41 | while open_list: 42 | current_node = heapq.heappop(open_list) 43 | 44 | if current_node.position == end_node.position: 45 | path = [] 46 | while current_node: 47 | path.append(current_node.position) 48 | current_node = current_node.parent 49 | return path[::-1] 50 | 51 | closed_set.add(current_node.position) 52 | 53 | # CHANGING THE POSITIONS AND INCREMENTING THE MOVEMENT 54 | for movement in movements: 55 | row = current_node.position[0] + movement[0] 56 | col = current_node.position[1] + movement[1] 57 | 58 | if ( 59 | row < 0 60 | or row >= rows 61 | or col < 0 62 | or col >= cols 63 | or grid[row][col] == 1 64 | or (row, col) in closed_set 65 | ): 66 | continue 67 | 68 | new_node = Node((row, col), parent=current_node) 69 | new_node.g = current_node.g + 1 70 | new_node.h = calculate_distance(new_node.position, end_node.position) 71 | new_node.f = new_node.g + new_node.h 72 | 73 | heapq.heappush(open_list, new_node) 74 | 75 | return None 76 | 77 | # A BREIF ABOUT A * ALGORITHM 78 | 79 | The A* algorithm is a popular pathfinding algorithm used to find the shortest path between two nodes in a graph. It combines the Dijkstra's algorithm, which explores all possible paths, and a heuristic function that guides the search towards the goal. 80 | 81 | # ABOUT AOVE EXAMPLE CODE 82 | 83 | In the example code, we have a grid-based implementation of A*. The Node class represents a node in the graph, containing its position, parent, and values for the cost g, heuristic h, and total estimated cost f. The calculate_distance function is a heuristic function that calculates the Euclidean distance between two points. 84 | 85 | The a_star function takes a grid, start position, and end position as input. It initializes the open list, closed set, start node, and end node. The algorithm then iteratively expands nodes, calculating their costs and adding them to the open list. The open list is a priority queue sorted by the total estimated cost f. 86 | 87 | # FINAL OUTCOME OF A* ALGORITHM 88 | If the goal node is reached, the function constructs the path from the end node back to the start node and returns it. If the open list is empty and no path is found, the function returns None. 89 | 90 | # DIFFERENT APPROACH 91 | You can use the algorithm as follows: 92 | 93 | grid = [ 94 | [0, 0, 0, 0, 0], 95 | [0, 1, 1, 0, 0], -------------------------------------------------------------------------------- /Ai/Ai.md: -------------------------------------------------------------------------------- 1 | 2 | # Artificial Intelligence 3 | 4 | # Artificial Intelligence 5 | 6 | ## **What is artificial intelligence?** 7 | 8 | **Artificial intelligence (AI) is the simulation of human intelligence processes by machines, especially computer systems. AI research has been highly successful in developing effective techniques for solving a wide range of problems, from game playing to medical diagnosis.** 9 | 10 | **Types of AI** 11 | 12 | There are many different types of AI, but some of the most common include: 13 | 14 | - **Reactive machines:** 15 |  These machines can only react to their environment. They do not have any memory or ability to learn. 16 | 17 | - **Limited memory machines:**  18 | These machines can remember past events and use that information to make decisions. However, they cannot learn from their experiences. 19 | 20 | - **Theory of mind machines:**  21 | These machines can understand the intentions of other agents. They can also learn from their experiences and use that knowledge to improve their performance. 22 | 23 | - **Self-aware machines:** 24 |  These machines are aware of themselves and their own existence. They can also understand the thoughts and feelings of other agents. 25 | 26 | **Applications of AI** 27 | 28 | AI is being used in a wide range of applications, including: 29 | 30 | - **Game playing:**  31 | AI has been used to develop very successful game-playing programs, such as Deep Blue, which defeated Garry Kasparov in chess. 32 | 33 | - **Medical diagnosis:**  34 | AI is being used to develop systems that can help doctors diagnose diseases. These systems can analyze medical data and identify patterns that may indicate a particular disease. 35 | 36 | - **Fraud detection:**  37 | AI is being used to develop systems that can detect fraudulent transactions. These systems can analyze financial data and identify patterns that may indicate fraud. 38 | - 39 | **Self-driving cars:** 40 |  AI is being used to develop self-driving cars. These cars use sensors and cameras to perceive their environment and make decisions about how to drive. 41 | 42 | ### **Future of AI** 43 | 44 | The future of AI is very promising. AI is expected to have a major impact on many different industries, including healthcare, transportation, and manufacturing. AI is also expected to be used to develop new products and services that we can't even imagine today. 45 | 46 | ### **Challenges of AI** 47 | 48 | **There are also some challenges that need to be addressed before AI can reach its full potential. One challenge is that AI systems can be biased. This is because they are trained on data that is collected from the real world, which may contain biases. Another challenge is that AI systems can be hacked. This is because they are complex and often contain vulnerabilities.** 49 | 50 | ### Conclusion 51 | 52 | AI is a powerful technology that has the potential to change the world. However, it is important to be aware of the challenges that need to be addressed before AI can reach its full potential. With careful development and careful use, AI can be a force for good in the world. 53 | 54 | ### **Here are some additional points about AI:** 55 | 56 | - AI is a rapidly evolving field, and new advances are being made all the time. 57 | - AI is already having a significant impact on our world, and its impact is only going to grow in the future. 58 | - There are both ethical and legal challenges associated with AI, and it is important to consider these challenges as AI develops. 59 | - AI has the potential to solve some of the world's most pressing problems, but it also has the potential to be used for harmful purposes. 60 | 61 | It is important to be aware of the potential benefits and risks of AI, and to use this technology responsibly. AI has the potential to make our world a better place, but it is up to us to ensure that it is used for good. 62 | -------------------------------------------------------------------------------- /Ai/Alpha-Beta-pruning.md: -------------------------------------------------------------------------------- 1 | # ALPHA - BETA PRUNING ALGORITHM 2 | 3 | -> Alpha-beta pruning is a search algorithm used in game theory and artificial intelligence to optimize the evaluation of nodes in 4 | aminimax search tree. 5 | 6 | -> It aims to reduce the number of nodes that need to be evaluated by eliminating unnecessary branches. 7 | 8 | -> The algorithm maintains two values, alpha and beta, which represent the minimum and maximum values that the maximizing and 9 | minimizing players can guarantee, respectively. 10 | 11 | -> The initial call to the alpha-beta function passes in alpha as negative infinity and beta as positive infinity. 12 | 13 | -> During the search, the algorithm updates the alpha and beta values as it explores different paths in the game tree. 14 | 15 | -> When evaluating a maximizing node, if the algorithm finds a value that is greater than or equal to beta, it prunes the remaining 16 | children nodes of that parent node. 17 | 18 | -> Conversely, when evaluating a minimizing node, if the algorithm finds a value that is less than or equal to alpha, it prunes the 19 | remaining children nodes. 20 | 21 | # EXAMPLE ON HOW GRAPH ARE REPRESENTED WITH ALPHA-BETA PRUNING 22 | 23 | -> Example with a graph: Suppose we have a game tree with multiple levels, and at a certain depth, we encounter a maximizing node 24 | labeled A with two child nodes B and C. 25 | 26 | -> Initially, we set alpha to negative infinity and beta to positive infinity. We start evaluating node B, which returns a value of 8. 27 | 28 | -> We update alpha to 8 since it is a maximizing node. We continue evaluating node C and find its value to be 5. 29 | 30 | ->As we explore more sibling nodes, if we encounter a node with a value greater than or equal to 8 (alpha), we can prune the 31 | remaining siblings because the maximizing player will always choose the path with a guaranteed outcome of at least 8. 32 | 33 | -> Similarly, if we encounter a node with a value less than or equal to 5 (beta), we can prune the remaining siblings for minimizing 34 | nodes since the minimizing player will always choose the path with a guaranteed outcome of at most 5. 35 | 36 | # CONCLUSION 37 | -> By pruning these unnecessary branches, the algorithm can focus on evaluating promising paths, reducing the computational effort 38 | required. -------------------------------------------------------------------------------- /Ai/bayes_theorem.md: -------------------------------------------------------------------------------- 1 | # BAYES' THEOREM DISCRIPTION 2 | 3 | -Bayes' Theorem is a fundamental concept in probability theory that allows us to update the probability of an event based on new -evidence. It describes the relationship between conditional probabilities and is widely used in various fields, including -statistics, machine learning, and data analysis. 4 | 5 | -The theorem can be stated as follows: 6 | # CONDITIONAL PROBABILITY : 7 | 8 | P(A|B) = (P(B|A) * P(A)) / P(B) 9 | 10 | Where: 11 | 12 | P(A|B) is the probability of event A given event B has occurred. 13 | P(B|A) is the probability of event B given event A has occurred. 14 | P(A) is the prior probability of event A. 15 | P(B) is the prior probability of event B. 16 | 17 | # EXAMPLE : 18 | 19 | -Let's consider a medical scenario where we want to determine the probability of a patient having a certain disease (A) given that -they test positive (B). We have the following information: 20 | 21 | -The probability of having the disease (P(A)) is 0.01 (1% of the population has the disease). 22 | -The probability of testing positive given that the patient has the disease (P(B|A)) is 0.95 (the test is 95% accurate). 23 | -The probability of testing positive given that the patient does not have the disease (P(B|¬A)) is 0.05 (false positive rate of 5%). 24 | -Now, we can use Bayes' Theorem to calculate the probability of having the disease given a positive test result: 25 | 26 | P(A|B) = (P(B|A) * P(A)) / P(B) 27 | P(A|B) = (0.95 * 0.01) / (P(B|A) * P(A) + P(B|¬A) * P(¬A)) 28 | P(A|B) = (0.95 * 0.01) / (0.95 * 0.01 + 0.05 * 0.99) 29 | P(A|B) ≈ 0.161 (approximately 16.1%) 30 | 31 | # CONCLUSION OF ABOVE EXAMPLE: 32 | 33 | -This means that even with a positive test result, the probability of actually having the disease is only around 16.1% due to the -relatively low prevalence of the disease in the population and the presence of false positives. 34 | 35 | -Regarding "navy bays theorem," there is no specific theorem by that name. It seems to be a typographical error or confusion. Bayes' -Theorem is the correct term to refer to the probability theorem explained above. -------------------------------------------------------------------------------- /Ai/data-links.md: -------------------------------------------------------------------------------- 1 | 2 | Colab Basics 3 | 4 | TF2.0 Loading Data : 5 | 6 | # download the data from a URL 7 | # source: https://archive.ics.uci.edu/ml/datasets/Arrhythmia 8 | # alternate URL: https://lazyprogrammer.me/course_files/arrhythmia.data 9 | #!wget --no-check-certificate https://archive.ics.uci.edu/ml/machine-learning-databases/arrhythmia/arrhythmia.data 10 | !wget https://lazyprogrammer.me/course_files/arrhythmia.data 11 | 12 | 13 | # use keras get_file to download the auto MPG dataset 14 | # source: https://archive.ics.uci.edu/ml/datasets/Auto+MPG 15 | #url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data' 16 | 17 | 18 | ### alternate URL : 19 | 20 | url = 'https://raw.githubusercontent.com/lazyprogrammer/machine_learning_examples/master/tf2.0/auto-mpg.data' 21 | 22 | # another method: upload your own file 23 | 24 | # if you must, then get the file from here: 25 | # https://raw.githubusercontent.com/lazyprogrammer/machine_learning_examples/master/tf2.0/daily-minimum-temperatures-in-me.csv 26 | 27 | Machine Learning Basics => 28 | 29 | TF2.0 Linear Regression : 30 | !wget https://raw.githubusercontent.com/lazyprogrammer/machine_learning_examples/master/tf2.0/moore.csv 31 | 32 | ANN 33 | 34 | CNN 35 | 36 | RNN 37 | TF2.0 Stock Returns 38 | # yes, you can read dataframes from URLs! 39 | df = pd.read_csv('https://raw.githubusercontent.com/lazyprogrammer/machine_learning_examples/master/tf2.0/sbux.csv') 40 | 41 | Natural Language Processing : 42 | 43 | TF2.0 Spam Detection 44 | # Unfortunately this URL doesn't work directly with pd.read_csv 45 | !wget -nc https://lazyprogrammer.me/course_files/spam.csv 46 | 47 | Recommender Systems : 48 | 49 | # data is from: https://grouplens.org/datasets/movielens/ 50 | # in case the link changes in the future 51 | 52 | 53 | !wget -nc http://files.grouplens.org/datasets/movielens/ml-20m.zip 54 | 55 | Transfer Learning : 56 | # Data from: https://mmspg.epfl.ch/downloads/food-image-datasets/ 57 | # !wget --passive-ftp --prefer-family=ipv4 --ftp-user FoodImage@grebvm2.epfl.ch \ 58 | # --ftp-password Cahc1moo -nc ftp://tremplin.epfl.ch/Food-5K.zip 59 | !wget -nc https://lazyprogrammer.me/course_files/Food-5K.zip 60 | 61 | 62 | STANFORD'S LECTURES ON ARTIFICIAL INTELLIGENCE 63 | 64 | https://www.youtube.com/watch?v=J8Eh7RqggsU&list=PLoROMvodv4rO1NB9TD4iUZ3qghGEGtqNX 65 | -------------------------------------------------------------------------------- /Ai/html.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/Ai/html.jpg -------------------------------------------------------------------------------- /Ai/min_max_algorithm.md: -------------------------------------------------------------------------------- 1 | 2 | # Below is a simplified implementation of the Min-Max algorithm in Python: 3 | 4 | def min_max(board, depth, maximizing_player): 5 | # Base case: check if the game is over or depth limit reached 6 | if game_over(board) or depth == 0: 7 | return evaluate(board) 8 | 9 | if maximizing_player: 10 | max_eval = float('-inf') 11 | for move in get_possible_moves(board): 12 | new_board = make_move(board, move) 13 | eval = min_max(new_board, depth - 1, False) 14 | max_eval = max(max_eval, eval) 15 | return max_eval 16 | else: 17 | min_eval = float('inf') 18 | for move in get_possible_moves(board): 19 | new_board = make_move(board, move) 20 | eval = min_max(new_board, depth - 1, True) 21 | min_eval = min(min_eval, eval) 22 | return min_eval 23 | 24 | # CODE EXPLANATION : 25 | 26 | ->In this code, the min_max function takes three parameters: board, depth, and maximizing_player. The board represents the current ->state of the game, depth specifies the maximum depth to explore in the game tree, and maximizing_player indicates whether it's the ->turn of the maximizing player or not. 27 | 28 | ->The function recursively evaluates each possible move by alternating between maximizing and minimizing players. It uses a utility ->function, evaluate, to assign scores to terminal states. The get_possible_moves function retrieves all the valid moves for a given ->board state, and make_move function applies a move to the board. 29 | 30 | ->The algorithm starts with the maximizing player and iterates through all possible moves. For each move, it generates a new board ->state and recursively calls min_max with a decreased depth and the opposite value for maximizing_player. The best score (maximum ->or minimum) is stored and returned at each level. 31 | 32 | ->Keep in mind that this is a simplified implementation, and you'll need to adapt it to your specific game and game rules by ->implementing the game_over, evaluate, get_possible_moves, and make_move functions accordingly. 33 | -------------------------------------------------------------------------------- /Ai/neural-network.md: -------------------------------------------------------------------------------- 1 | 2 | # neural network in TensorFlow very simple example. 3 | # 4 | 5 | from __future__ import print_function, division 6 | from builtins import range 7 | # Note: you may need to update your version of future 8 | # sudo pip install -U future 9 | 10 | import tensorflow as tf 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | 14 | 15 | # create random training data again 16 | Nclass = 500 17 | D = 2 # dimensionality of input 18 | M = 3 # hidden layer size 19 | K = 3 # number of classes 20 | 21 | X1 = np.random.randn(Nclass, D) + np.array([0, -2]) 22 | X2 = np.random.randn(Nclass, D) + np.array([2, 2]) 23 | X3 = np.random.randn(Nclass, D) + np.array([-2, 2]) 24 | X = np.vstack([X1, X2, X3]).astype(np.float32) 25 | 26 | Y = np.array([0]*Nclass + [1]*Nclass + [2]*Nclass) 27 | 28 | # let's see what it looks like 29 | plt.scatter(X[:,0], X[:,1], c=Y, s=100, alpha=0.5) 30 | plt.show() 31 | 32 | N = len(Y) 33 | # turn Y into an indicator matrix for training 34 | T = np.zeros((N, K)) 35 | for i in range(N): 36 | T[i, Y[i]] = 1 37 | 38 | 39 | # tensor flow variables are not the same as regular Python variables 40 | 41 | def init_weights(shape): 42 | return tf.Variable(tf.random_normal(shape, stddev=0.01)) 43 | 44 | 45 | def forward(X, W1, b1, W2, b2): 46 | Z = tf.nn.sigmoid(tf.matmul(X, W1) + b1) 47 | return tf.matmul(Z, W2) + b2 48 | 49 | 50 | tfX = tf.placeholder(tf.float32, [None, D]) 51 | tfY = tf.placeholder(tf.float32, [None, K]) 52 | 53 | W1 = init_weights([D, M]) # create symbolic variables 54 | b1 = init_weights([M]) 55 | W2 = init_weights([M, K]) 56 | b2 = init_weights([K]) 57 | 58 | logits = forward(tfX, W1, b1, W2, b2) 59 | 60 | cost = tf.reduce_mean( 61 | tf.nn.softmax_cross_entropy_with_logits_v2( 62 | labels=tfY, 63 | logits=logits 64 | ) 65 | ) 66 | 67 | # compute costs 68 | 69 | # WARNING: This op expects unscaled logits, 70 | 71 | # since it performs a softmax on logits 72 | 73 | # internally for efficiency. 74 | 75 | # Do not call this op with the output of softmax, 76 | 77 | # as it will produce incorrect results. 78 | 79 | train_op = tf.train.GradientDescentOptimizer(0.05).minimize(cost) # construct an optimizer 80 | 81 | # input parameter is the learning rate 82 | 83 | 84 | predict_op = tf.argmax(logits, 1) 85 | 86 | # input parameter is the axis on which to choose the max -------------------------------------------------------------------------------- /Ai/reinforcement_learning.md: -------------------------------------------------------------------------------- 1 | # REINFORCEMENT LEARNING 2 | ->Reinforcement Learning (RL) is a branch of machine learning that focuses on training agents to make decisions in an environment ->through trial and error. It involves learning optimal actions to maximize a cumulative reward signal. 3 | 4 | ->Here's an example of reinforcement learning and a code snippet in Python using the OpenAI Gym library: 5 | 6 | # Example: 7 | ->Let's consider the scenario of training an RL agent to play a simple game called CartPole. In this game, the agent controls a cart ->hat must balance a pole on top. The agent can take actions to move the cart left or right to keep the pole balanced. 8 | 9 | # Code in Python: 10 | To run this code, you need to install the OpenAI Gym library by running pip install gym in your Python environment. 11 | 12 | 13 | import gym 14 | 15 | # Create the CartPole environment 16 | env = gym.make('CartPole-v1') 17 | 18 | # Set the number of episodes and steps per episode 19 | num_episodes = 100 20 | num_steps = 200 21 | 22 | # Loop through episodes 23 | for episode in range(num_episodes): 24 | # Reset the environment for a new episode 25 | state = env.reset() 26 | total_reward = 0 27 | 28 | # Loop through steps in the episode 29 | for step in range(num_steps): 30 | # Render the environment (optional) 31 | env.render() 32 | 33 | # Choose an action 34 | action = env.action_space.sample() 35 | 36 | # Take the chosen action in the environment 37 | next_state, reward, done, _ = env.step(action) 38 | 39 | # Update the total reward 40 | total_reward += reward 41 | 42 | # Update the state 43 | state = next_state 44 | 45 | # Check if the episode is finished 46 | if done: 47 | print("Episode {} finished after {} steps with a total reward of {}".format(episode + 1, step + 1, total_reward)) 48 | break 49 | 50 | # Close the environment 51 | env.close() 52 | 53 | # BREIF ABOUT THE CODE 54 | This code demonstrates a basic RL setup using the CartPole environment from OpenAI Gym. It runs a fixed number of episodes and within each episode, takes random actions to interact with the environment. The total reward accumulated in each episode is printed, indicating the agent's performance. -------------------------------------------------------------------------------- /Ai/state_space_search.md: -------------------------------------------------------------------------------- 1 | # STATE SPACE TREE ALGORITHM 2 | 3 | ->One common algorithm for state space search is the breadth-first search (BFS) algorithm. BFS explores all the neighboring states ->of a given state before moving on to the next level of states. Here's an example of how the BFS algorithm works: 4 | 5 | # EXAMPLE : 6 | ->Let's consider a simple problem of finding a path from a starting point to a goal point on a grid. The grid has obstacles, and you ->can only move up, down, left, or right. 7 | 8 | # Define the problem: 9 | # THEM FIRST 10 | State: Each state represents a point on the grid. 11 | Initial state: The starting point. 12 | Goal state: The desired destination. 13 | Actions: Moving up, down, left, or right. 14 | Transition model: Determines the result of taking an action in a given state. 15 | Goal test: Checks if the current state is the goal state. 16 | Path cost: The cost associated with each step. 17 | Implement the BFS algorithm: 18 | 19 | # SECOND 20 | Create a queue to store states. 21 | Enqueue the initial state into the queue. 22 | Create a set to store visited states. 23 | Add the initial state to the set of visited states. 24 | While the queue is not empty: 25 | Dequeue a state from the queue. 26 | If the state is the goal state, return the path. 27 | Generate all possible neighboring states from the current state. 28 | For each neighbor: 29 | If it is not in the set of visited states: 30 | Add it to the set of visited states. 31 | Enqueue the neighbor into the queue. 32 | Example: 33 | Let's say we have a 4x4 grid: 34 | Start: (1, 1) 35 | Goal: (4, 4) 36 | Obstacles: (2, 2), (3, 2), (3, 3) 37 | 38 | # Using BFS, the algorithm would explore the states in the following order: 39 | 40 | Level 1: (1, 1) 41 | Level 2: (2, 1), (1, 2) 42 | Level 3: (3, 1), (2, 2), (1, 3) 43 | Level 4: (4, 1), (3, 2), (2, 3) 44 | Level 5: (3, 3), (4, 2), (2, 4) 45 | Level 6: (4, 3), (3, 4) 46 | Level 7: (4, 4) 47 | The algorithm would return the path: (1, 1) -> (2, 1) -> (3, 1) -> (4, 1) -> (4, 2) -> (4, 3) -> (4, 4) 48 | 49 | # CONCLUSION 50 | BFS guarantees that it will find the shortest path if one exists, but it may require a lot of memory if the state space is large. -------------------------------------------------------------------------------- /C++/digitalclock.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int sec_prev=0; 10 | while(1) 11 | { 12 | int seconds, minutes, hours; 13 | string str; 14 | 15 | //storing total seconds 16 | time_t total_seconds=time(0); 17 | 18 | //getting values of seconds, minutes and hours 19 | struct tm* ct=localtime(&total_seconds); 20 | 21 | seconds=ct->tm_sec; 22 | minutes=ct->tm_min; 23 | hours=ct->tm_hour; 24 | 25 | //converting it into 12 hour format 26 | if(hours>=12) 27 | str="PM"; 28 | else 29 | str="AM"; 30 | hours=hours>12?hours-12:hours; 31 | 32 | 33 | //printing the result 34 | if(seconds==sec_prev+1 || (sec_prev==59 && seconds==0)) 35 | { 36 | system("CLS"); 37 | cout<< (hours<10?"0":"") << hours <<":" << (minutes<10?"0":"") << minutes << ":" << (seconds<10?"0":"") << seconds << " " << str < 2 | using namespace std; 3 | int main() 4 | { 5 | int array[2][100], n, w, i, curw, used[100], maxi = -1, totalprofit = 0; 6 | //input number of objects 7 | cout << "Enter number of objects: "; 8 | cin >> n; 9 | //input max weight of knapsack 10 | cout << "Enter the weight of the knapsack: "; 11 | cin >> w; 12 | /* Array's first row is to store weights 13 | second row is to store profits */ 14 | for (i = 0; i < n; i++) 15 | { 16 | cin >> array[0][i] >> array[1][i]; 17 | } 18 | for (i = 0; i < n; i++) 19 | { 20 | used[i] = 0; 21 | } 22 | curw = w; 23 | //loop until knapsack is full 24 | while (curw >= 0) 25 | { 26 | maxi = -1; 27 | //loop to find max profit object 28 | for (i = 0; i < n; i++) 29 | { 30 | if ((used[i] == 0) && ((maxi == -1) || (((float) array[1][i] 31 | / (float) array[0][i]) > ((float) array[1][maxi] 32 | / (float) array[0][maxi])))) 33 | { 34 | maxi = i; 35 | } 36 | } 37 | used[maxi] = 1; 38 | //decrease current wight 39 | curw -= array[0][maxi]; 40 | //increase total profit 41 | totalprofit += array[1][maxi]; 42 | if (curw >= 0) 43 | { 44 | cout << "\nAdded object " << maxi + 1 << " Weight: " 45 | << array[0][maxi] << " Profit: " << array[1][maxi] 46 | << " completely in the bag, Space left: " << curw; 47 | } 48 | else 49 | { 50 | cout << "\nAdded object " << maxi + 1 << " Weight: " 51 | << (array[0][maxi] + curw) << " Profit: " 52 | << (array[1][maxi] / array[0][maxi]) * (array[0][maxi] 53 | + curw) << " partially in the bag, Space left: 0" 54 | << " Weight added is: " << curw + array[0][maxi]; 55 | totalprofit -= array[1][maxi]; 56 | totalprofit += ((array[1][maxi] / array[0][maxi]) * (array[0][maxi] 57 | + curw)); 58 | } 59 | } 60 | //print total worth of objects filled in knapsack 61 | cout << "\nBags filled with objects worth: " << totalprofit; 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Star and follow to support 2 | 3 | # Computer-Science 4 | 5 | ## Add about: 6 | 7 | Internet 8 | DBMS 9 | Cloud 10 | Computing 11 | Programming Languages 12 | Software Engineering 13 | Algorithms 14 | Object Oriented Programming 15 | Machine Learning 16 | Operating Systems 17 | Computer Network & Security 18 | Computer Organization & Architecture 19 | Web Development 20 | 21 | ### etc... 22 | 23 | # Instructions: 24 | 25 | - Only quality contributions will be merged. 26 | - Create Folder in this repo and Add relevant topic you wanted to contribute. 27 | - Will be creating website based on your contributed materials and your profile will be linked with the contributed topic. 28 | - Add your linkedin profile using the following format: 29 | - Create a file using your github username with extension .md and add it into contributors profile folder. 30 | Example : its-red-eagle.md 31 | - In markdown file write: 32 | - Your name 33 | - Your email id 34 | - your github profile link 35 | - your linkedin profile link 36 | - and other platforms link if you want 37 | Example: 38 | Folder Name: its-red-eagle.md 39 | " 40 | Yor Name (< >ADD two space after each line) 41 | Email Id... 42 | https://github.com/......../ 43 | https://www.linkedin.com/.........../ 44 | " 45 | 46 | ## Star and follow to support 47 | 48 | # Table of Contents 49 | 50 | - [Web Technology](Web%20Technology/WebTechnology.md) 51 | - [DBMS](DBMS/Database%20Management%20System/readme.md) 52 | - [Database Management System](DBMS/Database%20Management%20System/readme.md) 53 | - [ER Model](DBMS/ER%20Model/readme.md) 54 | - [Normalization](DBMS/Normalization/readme.md) 55 | - [Data Structures & Algorithms]() 56 | - [Rabin-Karp String Matching Algorithm](Data%20Structures%20and%20Algorithms/Rabin-Karp-String-Matching-Algo.md) 57 | - [Sliding Window Algorithm](Data%20Structures%20and%20Algorithms/Sliding-Window-Algo.md) 58 | - [Tim Sort Algorithm](Data%20Structures%20and%20Algorithms/Tim-Sort.md) 59 | - [Python](Python/python.md) 60 | - [Machine Learning]() 61 | - [Machine Learning](Machine%20Learning/deep-learning.md) 62 | - [Deep Learning](Machine%20Learning/deep-learning.md) 63 | - [Operating System](Operating%20System/os.md) 64 | - [First Come First Serve Algorithm](Operating%System/First%Come%First%Serve%Algorithm.md) 65 | - [Round Robin Scheduling Algorithm](Operating%System/Round%Robin%Scheduling%Algorithm.md) 66 | - [Priority Scheduling](Operating%System/Priority%Scheduling.md) 67 | For more, [click here](Operating%20System) 68 | - [Computer Organisation and Architecture]() 69 | - [Instruction Set Architecture](Computer%20Organisation%20and%20Architecture/InstructionSetArchitecture.md) 70 | - [MemoryAddressing](Computer%20Organisation%20and%20Architecture/MemoryAddressing.md) 71 | - [Computer Network & Security]() 72 | - [Computer Network](Computer%20Network%20&%20Security/Computer_network.md) 73 | - [Network Security](Computer%20Network%20&%20Security/network_security.md) 74 | - [SQL]() 75 | - [Introduction](SQL/Introduction.md) 76 | - [Commands](SQL/Commands.md) 77 | - [Python](Python/python.md) 78 | - [Programming Languages]() 79 | - [Introduction](Programming%20Languages/introduction.md) 80 | - [Types](Programming%20Languages/Types.md) 81 | 82 | # CONTRIBUTORS 83 | 84 | 85 | 86 | 87 | 88 | - [CONTRIBUTORS LIST, CLICK HERE](Contributors%20List/README.md) 89 | -------------------------------------------------------------------------------- /Cloud/Cloud-Computing.md: -------------------------------------------------------------------------------- 1 | # Awesome Cloud Computing [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 2 | 3 | A curated list of amazingly awesome resources for cloud computing. 4 | 5 | ## What is Cloud Computing? 6 |

7 | 8 |

9 | > Cloud computing is an internet-based computing model for enabling ubiquitous, convenient, 10 | > on-demand network access to a shared pool of configurable computing 11 | > resources (e.g., networks, servers, storage, applications and services) that can 12 | > be rapidly provisioned and released with minimal management effort. 13 | > 14 | > It is a model for enabling ubiquitous, on-demand access to a shared pool of configurable computing resources. 15 | > 16 | > It relies on sharing of resources to achieve coherence and economies of scale, similar to a utility (like the electricity grid) over a network. 17 | 18 | ## Where to Start? 19 | 20 | ## Platforms 21 | ### Amazon Web Services 22 | 23 | ### Google App Engine 24 | 25 | ## Cloud Computing Models 26 | 27 | ### Software as a Service (SaaS) 28 | 29 | ### Platform as a Service (PaaS) 30 | 31 | ### Infrastructure as a Service (IaaS) 32 | 33 | ## Cloud Computing Deployment Types 34 | 35 | ### Open Clouds 36 | 37 | ### Hybrid Clouds 38 | 39 | ### Private Clouds 40 | 41 | ## Tools 42 | 43 | ### Monitoring 44 | - [Riemann](http://riemann.io/) - Monitors distributed systems. 45 | 46 | ## Resources 47 | 48 | ## Security 49 | 50 | ## Key Concepts 51 | 52 | ### Consensus Protocols 53 | - [Paxos Made Live](http://static.googleusercontent.com/media/research.google.com/en//archive/paxos_made_live.pdf) 54 | - [ZooKeeper Consensus](http://diyhpl.us/~bryan/papers2/distributed/distributed-systems/zab.totally-ordered-broadcast-protocol.2008.pdf) 55 | - [Raft](https://ramcloud.atlassian.net/wiki/download/attachments/6586375/raft.pdf) 56 | 57 | ### Consistency 58 | 59 | ### Conflict-Free Data Structures 60 | 61 | ### Distributed Programming 62 | 63 | ## Distributed Systems in the Wild 64 | - [Bitcoin](https://bitcoin.org/bitcoin.pdf) 65 | 66 | ## Books 67 | - [Kubernetes: Up and Running](http://www.amazon.com/Kubernetes-Running-Dive-Future-Infrastructure/dp/1491935677) 68 | - [Docker: Up & Running](http://www.amazon.com/Docker-Up-Running-Karl-Matthias/dp/1491917571) 69 | - [Building Microservices](http://www.amazon.com/Building-Microservices-Sam-Newman/dp/1491950358) 70 | 71 | ## Presentations 72 | 73 | ## Conferences 74 | - [Container Camp](https://container.camp/) 75 | - [Kubecon](https://kubecon.io/) 76 | - [dotScale](http://2015.dotscale.io/) 77 | 78 | ## Other Awesome Lists 79 | - [Awesome Docker](https://github.com/veggiemonk/awesome-docker) 80 | - [Awesome Kubernetes](https://github.com/ramitsurana/awesome-kubernetes) -------------------------------------------------------------------------------- /Computer Network & Security/Computer_network.md: -------------------------------------------------------------------------------- 1 |

Computer Network

2 | 3 | Computer network security consists of measures taken by business or some organizations to monitor and prevent unauthorized access from the outside attackers. 4 | 5 | Different approaches to computer network security management have different requirements depending on the size of the computer network. For example, a home office requires basic network security while large businesses require high maintenance to prevent the network from malicious attacks. 6 | 7 | Network Administrator controls access to the data and software on the network. A network administrator assigns the user ID and password to the authorized person. 8 | 9 |

Aspects of Network Security:

10 | Following are the desirable properties to achieve secure communication: 11 | 12 |

Privacy:

Privacy means both the sender and the receiver expects confidentiality. The transmitted message should be sent only to the intended receiver while the message should be opaque for other users. Only the sender and receiver should be able to understand the transmitted message as eavesdroppers can intercept the message. Therefore, there is a requirement to encrypt the message so that the message cannot be intercepted. This aspect of confidentiality is commonly used to achieve secure communication. 13 | 14 |

Message Integrity:

Data integrity means that the data must arrive at the receiver exactly as it was sent. There must be no changes in the data content during transmission, either maliciously or accident, in a transit. As there are more and more monetary exchanges over the internet, data integrity is more crucial. The data integrity must be preserved for secure communication. 15 | 16 |

End-point authentication:

Authentication means that the receiver is sure of the sender?s identity, i.e., no imposter has sent the message. 17 | Non-Repudiation: Non-Repudiation means that the receiver must be able to prove that the received message has come from a specific sender. The sender must not deny sending a message that he or she send. The burden of proving the identity comes on the receiver. For example, if a customer sends a request to transfer the money from one account to another account, then the bank must have a proof that the customer has requested for the transaction. 18 | 19 | -------------------------------------------------------------------------------- /Computer Organisation and Architecture/InstructionSetArchitecture.md: -------------------------------------------------------------------------------- 1 |

Instructure Set Architecture

2 | 3 |

What is instruction Set Architecture?

4 | The Instruction Set Architecture (ISA) is the part of the processor that is visible to the programmer or compiler writer. It is not hardware nor is it software, it is instead an interface between hardware and software. 5 | It is the guide to the hardware describing how and where the operations specified by the user (using software) should be managed. 6 | 7 | As such, ISA of a processor can be described using 5 paramaters/questions. Since all data processes can be described using operators and operands, such terms are used here as well. 8 | 1. What is the number of operands? 9 | (are they 0,1,2 or more than 2?) 10 | 2. Where are they stored? 11 | (Accumulator, Stack, Register and Memory are the available types of storage) 12 | 3. What is size and type of operands? 13 | (Are the operands of type float, int, character, double or string?) 14 | 4. What is the addressing mode? 15 | (How is the hardware referring to the data?) 16 | 17 | Consider an n bit instruction, of which m are reserved for the operation code (opcode for short). 18 | Operation code is used to identify the type of operation that the hardware must perform. There are 19 | basically 7 types of operations in every computer, regardless of specs: 20 | 1. Data transfer 21 | 2. Arithmetic 22 | 3. Logical 23 | 4. Conversion 24 | 5. I/O 25 | 6. System control 26 | 7. Transfer of control 27 | 28 | Coming back to the topic at hand, we have n-m bits left for keeping track of the data. 29 | Now, if there is one operand, we only have to store one addressing mode data and one data type. 30 | Similarly, if there are two operands we have to store 2 two addressing modes and two data types in the n-m bits. 31 | Next, we have to decide where to store the data, on basis of which of we will decide the addressing mode. 32 | Accumulators and Stacks are not used is this day and age so we have to choose between Register and Memory. 33 | Register is faster but has less space in comparison to Memory. So it is upto the designed what they want to use. 34 | 35 | Now, there are two types of Instruction Set Architectures. CISC and RISC. 36 | CISC refers Complex Instruction Set computer and RISC refers to Reduced Instruction Set Computer. 37 | In RISC, the instuction lengths are fixed and there are no joint instructions. Thus less instructions are provided and the less significant instructions are thrown out. 38 | In CISC, the instruction size varies from 16-96 bits and as such, there is a lot of room of joint instructions and it can also support backward compatitbility. 39 | Next, I will cover Memory Addressing. 40 | 41 | 42 | -------------------------------------------------------------------------------- /Computer Organisation and Architecture/MemoryAddressing.md: -------------------------------------------------------------------------------- 1 |

Memory Addressing Modes

2 | 3 | There are many ways to locate data and instructions in primary memory and these methods are known as Memory Address Modes. 4 | 5 | There are essentially 4 types of Memory Addressing modes: 6 | 1. Immediate 7 | 2. Direct 8 | 3. Indirect 9 | 4. Indexed 10 | 5. Implied 11 | 6. Register Direct 12 | 7. Register Indirect 13 | 8. Relative 14 | 9. Base 15 | 10. Auto-increment 16 | 11. Auto-decrement 17 | 18 |

Immediate Addressing mode

19 | -> It basically means that the data is hard-coded into the instruction itself. 20 | -> It neither requires memory accesses nor fetching of memory so it is, by far, the fastest method of addressing. 21 | -> the major disadvantage of this mode is the size constraint. 22 |

Direct Addressing mode

23 | ->It is a very straightforward method of addressing data, we basically provide the memory location of the data. 24 | -> It requires a memory access so while it is fairly fast, it is slower than Immediate addressing. 25 |

Indirect Addressing mode

26 | -> It essentially means that the address of the data is stored at an intermediate location so we basically have to find the intermediate location first which then gives us the address of the data. 27 | -> there are two memory accesses required so it is slower than both direct and immediate but it contain data of larger sizes. 28 |

Indexed Addressing mode

29 | -> It means that the final address of the data has to be found using an offest from the base address. 30 | -> It is ideal for storing and accessing values of arrays because they require contiguous memory locations so we need only the address of the first element to find the location of the other elements in the array. 31 |

Implied Adressing mode

32 | ->In this addressing mode, 33 | The definition of the instruction itself specify the operands implicitly. 34 | It is also called as implicit addressing mode. 35 |

Register Direct Addressing mode

36 | ->In this addressing mode, 37 | 38 | The operand is contained in a register set. 39 | The address field of the instruction refers to a CPU register that contains the operand. 40 | No reference to memory is required to fetch the operand. 41 |

Register Indirect Addresssing mode

42 | ->In this addressing mode, 43 | 44 | The address field of the instruction refers to a CPU register that contains the effective address of the operand. 45 | Only one reference to memory is required to fetch the operand. 46 |

Relative Addressing mode

47 | ->In this addressing mode, 48 | 49 | Effective address of the operand is obtained by adding the content of program counter with the address part of the instruction. 50 |

Base Register Addressing mode

51 | ->In this addressing mode, 52 | 53 | Effective address of the operand is obtained by adding the content of program counter with the address part of the instruction. 54 |

Auto-Increment Addressing mode

55 | ->In this addressing mode, 56 | 57 | After accessing the operand, the content of the register is automatically incremented by step size ‘d’. 58 | Step size ‘d’ depends on the size of operand accessed. 59 | Only one reference to memory is required to fetch the operand. 60 |

Auto-decrement Adreesing mode

61 | ->In this addressing mode, 62 | 63 | First, the content of the register is decremented by step size ‘d’. 64 | Step size ‘d’ depends on the size of operand accessed. 65 | After decrementing, the operand is read. 66 | Only one reference to memory is required to fetch the operand. -------------------------------------------------------------------------------- /Computer Program Games/Tic Tac Toe/readme.md: -------------------------------------------------------------------------------- 1 | ## About Game 2 | This is the tic tac toe game which can be played between computer and the user. 3 | Bothe players have to choose a sign for playing. 4 | Bothe players have to make moves for making a line of their signs. 5 | The first person who makes the line of their sign wins. 6 | 7 | ## About Program 8 | There is a board made in the program for making moves O and X. 9 | The board is divided in 9 boxes (1-9). 10 | The winning conditions and possible moves are written in the program. 11 | The check program for cheking possible moves is also written in the program. 12 | User will have to enter the number of box to make a move. 13 | 14 | ## How To Play 15 | Run The Program in your local machine 16 | Computer will choose the character X or O. The other one will be of user 17 | Computer will ask user to make a move he/she want (i.e enter a number from 1 to 9) 18 | Now computer will chek if the move is valid and possible 19 | Then computer will make it's move 20 | This process will continue till the game ends 21 | The player who will make a line first will win 22 | If there is no possible move then the game will be declared as tie. 23 | 24 | 25 | 26 | GOOD LUCK !! -------------------------------------------------------------------------------- /Computer Program Games/Tic Tac Toe/tic_tac_toe.py: -------------------------------------------------------------------------------- 1 | import random 2 | import sys 3 | board=[i for i in range(0,9)] 4 | player, computer = '','' 5 | 6 | moves=((1,7,3,9),(5,),(2,4,6,8)) 7 | 8 | winners=((0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6)) 9 | 10 | tab=range(1,10) 11 | def print_board(): 12 | x=1 13 | for i in board: 14 | end = ' | ' 15 | if x%3 == 0: 16 | end = ' \n' 17 | if i != 1: end+='---------\n' 18 | char=' ' 19 | if i in ('X','O'): char=i 20 | x+=1 21 | print(char,end=end) 22 | def select_char(): 23 | chars=('X','O') 24 | if random.randint(0,1) == 0: 25 | return chars[::-1] 26 | return chars 27 | def can_move(brd, player, move): 28 | if move in tab and brd[move-1] == move-1: 29 | return True 30 | return False 31 | def can_win(brd, player, move): 32 | places=[] 33 | x=0 34 | for i in brd: 35 | if i == player: places.append(x) 36 | x+=1 37 | win=True 38 | for tup in winners: 39 | win=True 40 | for ix in tup: 41 | if brd[ix] != player: 42 | win=False 43 | break 44 | if win == True: 45 | break 46 | return win 47 | def make_move(brd, player, move, undo=False): 48 | if can_move(brd, player, move): 49 | brd[move-1] = player 50 | win=can_win(brd, player, move) 51 | if undo: 52 | brd[move-1] = move-1 53 | return (True, win) 54 | return (False, False) 55 | 56 | def computer_move(): 57 | move=-1 58 | # If I can win, others do not matter. 59 | for i in range(1,10): 60 | if make_move(board, computer, i, True)[1]: 61 | move=i 62 | break 63 | if move == -1: 64 | # If player can win,I can try to block him. 65 | for i in range(1,10): 66 | if make_move(board, player, i, True)[1]: 67 | move=i 68 | break 69 | if move == -1: 70 | # Otherwise, try to take one of desired places. 71 | for tup in moves: 72 | for mv in tup: 73 | if move == -1 and can_move(board, computer, mv): 74 | move=mv 75 | break 76 | return make_move(board, computer, move) 77 | def space_exist(): 78 | return board.count('X') + board.count('O') != 9 79 | player, computer = select_char() 80 | print('Player is [%s] and computer is [%s]' % (player, computer)) 81 | result='%%% Deuce ! %%%' 82 | while space_exist(): 83 | print_board() 84 | print('#Make your move ! [1-9] : ', end='') 85 | move = int(input()) 86 | moved, won = make_move(board, player, move) 87 | if not moved: 88 | print(' Invalid number ! Try again !') 89 | continue 90 | if won: 91 | result='*** Congratulations ! You won ! ***' 92 | break 93 | elif computer_move()[1]: 94 | result='=== You lose ! ==' 95 | break 96 | print_board() 97 | print(result) -------------------------------------------------------------------------------- /Computer Program Games/TicTacToe_2P/README.md: -------------------------------------------------------------------------------- 1 | # About the code 2 | 3 | The code is a Python implementation of a Tic Tac Toe game using the Pygame library. It allows two players to play the game on a graphical interface. 4 | 5 | # Here's a breakdown of the code: 6 | 7 | 1. Import necessary libraries: The code starts by importing the required libraries, including `pygame`, `math`, and `time`. 8 | 9 | 2. Initialize Pygame: The Pygame library is initialized using `pygame.init()`. 10 | 11 | 3. Set up the game window: The code sets up the game window with a specified width and caption using the `pygame.display.set_mode()` and `pygame.display.set_caption()` functions. 12 | 13 | 4. Define color variables: Several color variables are defined using RGB values. 14 | 15 | 5. Load and display images: The code loads and displays images on the game window using the `pygame.image.load()` and `pygame.transform.scale()` functions. The images include the tic-tac-toe board, X, and O symbols. 16 | 17 | 6. Define font for end messages: The code defines a font for displaying end messages. 18 | 19 | 7. Draw grid and initialize game array: The `draw_grid()` function is defined to draw the tic-tac-toe grid on the game window. The `initialize_grid()` function initializes the game array, which represents the state of the game board, with empty cells. 20 | 21 | 8. Handle mouse click events: The `click()` function handles mouse click events. It checks the position of the mouse click and determines the corresponding cell on the game board. If the cell is empty, it updates the game array and the current player's turn. 22 | 23 | 9. Check for a win: The `has_won()` function checks if a player has won the game by examining the game array. It checks for winning combinations in rows, columns, and diagonals. 24 | 25 | 10. Check for a draw: The `has_drawn()` function checks if the game has resulted in a draw by examining the game array. If all cells are filled and no player has won, it is considered a draw. 26 | 27 | 11. Display end messages: The `display_mess()` function displays end messages on the game window. It is called when a player wins or the game ends in a draw. 28 | 29 | 12. Render the game: The `render()` function updates the game window by filling it with the background color, drawing the grid, and rendering the X and O symbols on the board. 30 | 31 | 13. Main game loop: The `main()` function contains the main game loop. It handles events, calls the `click()` function, renders the game, and checks for a win or draw condition. The loop continues until a win or draw occurs. 32 | 33 | 14. Execute the game: The game is executed by calling the `main()` function within an infinite loop. 34 | 35 | # Please note that the code assumes the existence of image files (`tictactoe.png`, `x1.2.png`, and `o.png`) in a directory named "image" relative to the code file. 36 | 37 | If you have any specific questions or need further clarification, feel free to ask. -------------------------------------------------------------------------------- /Computer Program Games/TicTacToe_2P/image/o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/Computer Program Games/TicTacToe_2P/image/o.png -------------------------------------------------------------------------------- /Computer Program Games/TicTacToe_2P/image/tictactoe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/Computer Program Games/TicTacToe_2P/image/tictactoe.png -------------------------------------------------------------------------------- /Computer Program Games/TicTacToe_2P/image/x1.2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/Computer Program Games/TicTacToe_2P/image/x1.2.png -------------------------------------------------------------------------------- /Contributors List/Apoorv266.md: -------------------------------------------------------------------------------- 1 | Name - Apoorv Sharma
2 | email ID - apoorvsharma7181@gmail.com
3 | github - https://github.com/Apoorv266
4 | linkdin - https://www.linkedin.com/in/the-apoorv-sharma/
5 | -------------------------------------------------------------------------------- /Contributors List/Avni Arora.md: -------------------------------------------------------------------------------- 1 | Avni Arora 2 | https://github.com/Avni17 3 | https://www.linkedin.com/in/avni-arora2002/ -------------------------------------------------------------------------------- /Contributors List/Caffeine-Overflows.md: -------------------------------------------------------------------------------- 1 | Riya Gupta 2 | https://github.com/Caffeine-Overflows/ 3 | https://www.linkedin.com/in/riyagupta42/ 4 | -------------------------------------------------------------------------------- /Contributors List/Chitrakshi2531.md: -------------------------------------------------------------------------------- 1 | Name - Chitrakshi Bohra\ 2 | Email - chitrakshi2531@gmail.com\ 3 | Linkedin - https://www.linkedin.com/in/chitrakshi-bohra-bb8988209 4 | Github - https://github.com/Chitrakshi2531 5 | -------------------------------------------------------------------------------- /Contributors List/DCBisht.md: -------------------------------------------------------------------------------- 1 | Divya Chakshu Bisht 2 | 3 | https://github.com/DCBisht 4 | chakshubisht459@gmail.com 5 | 6 | https://www.linkedin.com/in/divya-chakshu-bisht-527393203/ 7 | 8 | 9 | -------------------------------------------------------------------------------- /Contributors List/Hariom.md: -------------------------------------------------------------------------------- 1 | Name - Hariom Kumar 2 | 3 | Email - hariom14may11@gmail.com 4 | 5 | Linkedin - https://www.linkedin.com/in/imharry404/ 6 | 7 | Github - https://github.com/imHarry404 8 | -------------------------------------------------------------------------------- /Contributors List/Krishanu_Chakraborty.md: -------------------------------------------------------------------------------- 1 | Krishanu Chakraborty
2 | https://github.com/go4krishanu/
3 | https://www.linkedin.com/in/go4krishanu/ 4 | -------------------------------------------------------------------------------- /Contributors List/README.md: -------------------------------------------------------------------------------- 1 | # CONTRIBUTORS 2 | 3 | - [Vikash Patel](its-red-eagle.md) 4 | - [Akash Kumar](aaakashkumar.md) 5 | - [Sushant Agawane](sushant_agawane.md) 6 | - [Jerik George](jerik-george.md) 7 | - [Basil Baby Skaria](phoenix.md) 8 | - [Krishanu Chakraborty](krishanu_chakraborty.md) 9 | - [Nandini Tiwari](nandini.md) 10 | - [Advait Manke](TGFlame.md) 11 | - [Chitrakshi Bohra](Chitrakshi2531.md) 12 | - [Handhika Yanuar Pratama](theDreamer911.md) 13 | - [Srishti Shukla](Srishti2128.md) 14 | - [Sree Haran](SreeHaran.md) 15 | - [Shashvat Jain](ShashvatJain.md) 16 | - [Mohd Adnan](MohdAdnan.md) 17 | - [Black TImber](BlackTimber.md) 18 | -------------------------------------------------------------------------------- /Contributors List/Ritik Kumar.md: -------------------------------------------------------------------------------- 1 | Ritik Kumar 2 | https://github.com/johmn123-wq/ 3 | https://www.linkedin.com/in/ritik-kumar-0340931a8/ -------------------------------------------------------------------------------- /Contributors List/ShashvatJain.md: -------------------------------------------------------------------------------- 1 | Shashvat Jain 2 | https://github.com/Shashvat-Jain 3 | https://www.linkedin.com/in/shashvat-jain-847089210/ 4 | -------------------------------------------------------------------------------- /Contributors List/SreeHaran.md: -------------------------------------------------------------------------------- 1 | Sree Haran 2 | https://github.com/SreeHaran/ 3 | https://www.linkedin.com/in/sreeharan/ -------------------------------------------------------------------------------- /Contributors List/Srishti2128.md: -------------------------------------------------------------------------------- 1 | Name - Srishti Shukla 2 | 3 | Email - srishtishukla66721@gmail.com 4 | 5 | Linkedin - https://www.linkedin.com/in/srishti-shukla28/ 6 | 7 | Github - https://github.com/Srishti2128 8 | -------------------------------------------------------------------------------- /Contributors List/TGFlame.md: -------------------------------------------------------------------------------- 1 | Advait Manke 2 | 3 | advit2003@gmail.com 4 | 5 | 6 | https://github.com/TGFlame 7 | 8 | 9 | https://www.linkedin.com/in/advait-manke-65168622a/ 10 | -------------------------------------------------------------------------------- /Contributors List/Vaishnvee-Shinde.md: -------------------------------------------------------------------------------- 1 | Name: Vaishnvee Subhash Shinde 2 | 3 | 4 | Email Id: Vaishnvee.s.shinde@gmail.com 5 | 6 | 7 | Github profile link: Vaishnvee-Shinde 8 | 9 | 10 | Linkedin profile link:VaishnveeShinde 11 | 12 | 13 | Other platforms link: 14 | 15 | 16 | Leetcode:VaishnveeShinde_LeetCode 17 | 18 | 19 | Portfolio:VaishnveeShinde_Portfollio 20 | -------------------------------------------------------------------------------- /Contributors List/[feature Added contributing.md file]: -------------------------------------------------------------------------------- 1 | Vikas Tripathi 2 | https://github.com/ervikasji/ 3 | https://www.linkedin.com/in/vikas/ 4 | -------------------------------------------------------------------------------- /Contributors List/aaakashkumar.md: -------------------------------------------------------------------------------- 1 | Akash Kumar 2 | https://github.com/aaakashkumar/ 3 | https://www.linkedin.com/in/akashkumar09/ -------------------------------------------------------------------------------- /Contributors List/adityaajay29.md: -------------------------------------------------------------------------------- 1 | Aditya Ajay 2 | 3 | https://github.com/adityaajay29 4 | 5 | https://www.linkedin.com/in/aditya-ajay2662/ 6 | -------------------------------------------------------------------------------- /Contributors List/its-red-eagle.md: -------------------------------------------------------------------------------- 1 | Vikash Patel 2 | https://github.com/its-red-eagle/ 3 | https://www.linkedin.com/in/its-red-eagle/ 4 | -------------------------------------------------------------------------------- /Contributors List/jerik-george.md: -------------------------------------------------------------------------------- 1 | Jerik George 2 | https://github.com/jerik-george/ 3 | https://www.linkedin.com/in/jerikgeorge/ 4 | -------------------------------------------------------------------------------- /Contributors List/mayank.md: -------------------------------------------------------------------------------- 1 | Name - mayank 2 | email ID - mayankjohari877@gmail.com 3 | github - https://github.com/mayankmj 4 | linkdin - https://www.linkedin.com/in/mayank-johari-52aa05202/ 5 | -------------------------------------------------------------------------------- /Contributors List/nandini.md: -------------------------------------------------------------------------------- 1 | Nandini Tiwari 2 | https://github.com/nandinit02 3 | https://www.linkedin.com/in/nandini-tiwari-873a091a6/ 4 | -------------------------------------------------------------------------------- /Contributors List/phoenix.md: -------------------------------------------------------------------------------- 1 | Basil Baby Skaria 2 | https://github.com/Basilbabyskaria 3 | www.linkedin.com/in/basil-baby-494557183 4 | -------------------------------------------------------------------------------- /Contributors List/roshan-byte.md: -------------------------------------------------------------------------------- 1 | Name Roshan Kumar 2 | 3 | Email rkrockstar9990@gmail.com 4 | 5 | Github https://github.com/roshan-byte/ 6 | 7 | LinkedIn https://www.linkedin.com/in/r0shan-kumar/ 8 | 9 | 10 | -------------------------------------------------------------------------------- /Contributors List/sushant_agawane.md: -------------------------------------------------------------------------------- 1 | Sushant Agawane 2 | https://github.com/Sushant-1999 3 | https://www.linkedin.com/in/sushant-agawane-a7095a174/ 4 | -------------------------------------------------------------------------------- /Contributors List/theDreamer911.md: -------------------------------------------------------------------------------- 1 | Handhika Yanuar Pratama 2 | 3 | thetrulydreamer@gmail.com 4 | 5 | 6 | https://github.com/theDreamer911 7 | 8 | 9 | https://www.linkedin.com/in/handhikayp/ 10 | -------------------------------------------------------------------------------- /DBMS/ER Model/12310.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/12310.png -------------------------------------------------------------------------------- /DBMS/ER Model/33333-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/33333-1.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-S-ystem-ER-Model-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-S-ystem-ER-Model-9.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-10.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-12.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-13.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-14.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-15.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-16.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-17.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-18.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-2.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-3.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-4.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-5.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-6.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-7.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model-8.png -------------------------------------------------------------------------------- /DBMS/ER Model/Database-Management-System-ER-Model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/DBMS/ER Model/Database-Management-System-ER-Model.png -------------------------------------------------------------------------------- /Data Structures and Algorithms/Best_Time_to_Buy_and_Sell_Stock_I.md: -------------------------------------------------------------------------------- 1 |

Best Time to Buy and Sell Stock

2 | 3 |

Problem:

4 | You are given an integer array prices where prices[i] is the price of a given stock on the ith day. 5 | 6 | On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, you can buy it then immediately sell it on the same day. 7 | 8 | Find and return the maximum profit you can achieve. 9 | 10 |

Algorithm:

11 | Greedy Approach 12 | 13 |

Implementation in C++:

14 | 15 | ``` 16 | #include 17 | using namespace std; 18 | 19 | int maxProfit(vector& prices) { 20 | 21 | int n = prices.size(),mxprofit=0; 22 | for(int i=1;i0){ 25 | mxprofit += prices[i]-prices[i-1]; 26 | 27 | } 28 | } 29 | return mxprofit; 30 | } 31 | 32 | int main(){ 33 | 34 | int n = 6; 35 | vector price = {7,1,5,3,6,4}; 36 | cout<<"Maximum Profit: "<Best Time to Buy and Sell Stock 2 | 3 |

Problem:

4 | You are given an array prices where prices[i] is the price of a given stock on the ith day. 5 | 6 | You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. 7 | 8 | Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. 9 | 10 |

Algorithm:

11 | Kadane's Algorithm 12 | 13 |

Implementation in C++:

14 | 15 | ``` 16 | 17 | ##include 18 | using namespace std; 19 | 20 | int maxProfit(vector& prices) { 21 | 22 | int n=prices.size(), mn=prices[0],mx = prices[0] ,mn_ind=0,mx_ind=0; 23 | 24 | int s[n]; 25 | s[n-1]=prices[n-1]; 26 | for(int i=n-2;i>=0;i--){ 27 | s[i] = max(prices[i],s[i+1]); 28 | 29 | } 30 | 31 | int res=0; 32 | for(int i=0;i price = {7,1,5,3,6,4}; 42 | cout<<"Maximum Profit: "< 16 | #include 17 | struct node 18 | { 19 | 20 | int data; 21 | struct node* next; 22 | }*first=NULL; 23 | void create(int A[],int n) 24 | { 25 | struct node* last=NULL; 26 | first=(struct node*)malloc(sizeof(struct node)); 27 | first->data=A[0]; 28 | first->next=NULL; 29 | last=first; 30 | first->next=first; 31 | for(int i=1;idata=A[i]; 35 | temp->next=NULL; 36 | last->next=temp; 37 | last=temp; 38 | last->next=first; 39 | 40 | } 41 | } 42 | void insert(int pos,int key) 43 | { 44 | struct node* p=first; 45 | struct node* temp=(struct node*)malloc(sizeof(struct node)); 46 | temp->data=key; 47 | temp->next=NULL; 48 | if(pos==0) 49 | { 50 | while(p->next!=first) 51 | { 52 | p=p->next; 53 | } 54 | p->next=temp; 55 | temp->next=first; 56 | first=temp; 57 | 58 | } 59 | else 60 | { 61 | 62 | for(int i=1;inext; 65 | } 66 | temp->next=p->next; 67 | p->next=temp; 68 | } 69 | } 70 | int deletei(int pos) 71 | { 72 | struct node* p=first; 73 | struct node* q; 74 | if(pos==0) 75 | { 76 | while(p->next!=first) 77 | { 78 | p=p->next; 79 | } 80 | q=first; 81 | p->next=first->next; 82 | first=first->next; 83 | free(q); 84 | } 85 | else 86 | { 87 | for(int i=1;inext; 90 | } 91 | q=p->next; 92 | p->next=p->next->next; 93 | free(q); 94 | } 95 | } 96 | void display(struct node* p) 97 | { 98 | do 99 | { 100 | printf("%d ",p->data); 101 | p=p->next; 102 | 103 | }while(p!=first); 104 | } 105 | int main() 106 | { 107 | int A[]={2,3,4,5,6}; 108 | create(A,5); 109 | insert(5,88); 110 | deletei(5); 111 | display(first); 112 | } 113 | 114 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/DP/01-knapsak.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int dp[1000][1000]={0}; 5 | 6 | void knapsack(int wt[],int val [],int W,int n){ 7 | 8 | for(int i=1;i<=n;i++){ 9 | for(int j=1;j<=W;j++){ 10 | 11 | if(wt[i-1]<=j) 12 | dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]); 13 | else 14 | dp[i][j]=dp[i-1][j]; 15 | } 16 | } 17 | 18 | // using recursion.... 19 | // if(n==0||W==0) 20 | // return 0; 21 | 22 | // if(wt[n-1]<=W) 23 | // return max(val[n-1]+knapsack(wt,val,W-wt[n-1],n-1),knapsack(wt,val,W,n-1)); 24 | // else 25 | // return knapsack(wt,val,W,n-1); 26 | 27 | } 28 | 29 | int main(){ 30 | 31 | int n = 5; 32 | int wt[n] = {7,2,4,5,6}; 33 | int val[n] = {34,55,62,32,71}; 34 | int W = 50; 35 | 36 | knapsack(wt,val,W,n); 37 | 38 | cout<<"TOTAL PROFIT: "<Coin Change 2 | 3 |

Problem:

4 | You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. 5 | 6 | Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1. 7 | 8 | You may assume that you have an infinite number of each kind of coin. 9 | 10 |

Algorithm:

11 | Dynamic Programming - Bottom Approach 12 | 13 |

Implementation in C++:

14 | 15 | ``` 16 | #include 17 | using namespace std; 18 | 19 | int coinChange(vector& coins, int amount) { 20 | 21 | if(amount==0)return 0; 22 | sort(coins.begin(), coins.end()); 23 | int n = coins.size(); 24 | vectorprev(amount+1,1e4), curr(amount+1,1e4); 25 | 26 | for(int i=1;i<=n;i++){ 27 | curr[0] = 0; 28 | for(int j=1;j<=amount;j++){ 29 | 30 | curr[j] = prev[j]; 31 | if(j-coins[i-1]>=0) 32 | curr[j] = min(curr[j],1 + curr[j-coins[i-1]]); 33 | } 34 | prev = curr; 35 | 36 | } 37 | return curr[amount]== 1e4 ? -1 : curr[amount]; 38 | } 39 | 40 | int main(){ 41 | 42 | vectorcoins = {1,2,5}; 43 | int amount = 11; 44 | 45 | cout<<"Fewest Nunber of coins required: "<Coin Change II 2 | 3 |

Problem:

4 | You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. 5 | 6 | Return the number of combinations that make up that amount. If that amount of money cannot be made up by any combination of the coins, return 0. 7 | 8 | You may assume that you have an infinite number of each kind of coin. 9 | 10 | The answer is guaranteed to fit into a signed 32-bit integer. 11 | 12 | 13 |

Algorithm:

14 | Dynamic Programming - Bottom Approach 15 | 16 |

Implementation in C++:

17 | 18 | ``` 19 | #include 20 | using namespace std; 21 | 22 | int change(int amount, vector& coins) { 23 | 24 | int dp[amount+1]; 25 | int m = coins.size(); 26 | memset(dp,0,sizeof dp); 27 | 28 | dp[0] = 1; 29 | 30 | for(int j=0;j=0) 34 | dp[i] += dp[i-coins[j]]; 35 | } 36 | 37 | } 38 | 39 | return dp[amount]; 40 | } 41 | 42 | int main(){ 43 | 44 | vectorcoins = {1,2,5}; 45 | int amount = 5; 46 | 47 | cout<<"Number of Combinations: "<Longest Common Subsequence 2 | 3 |

Problem:

4 | Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. 5 | 6 |

Algorithm:

7 | Bottom-up DP utilizes a matrix m where we track LCS sizes for each combination of i and j. 8 | 9 | If a[i] == b[j], LCS for i and j would be 1 plus LCS till the i-1 and j-1 indexes. 10 | Otherwise, we will take the largest LCS if we skip a charracter from one of the string (max(dp[i - 1][j], dp[i][j - 1]). 11 | 12 |

Implementation in C++:

13 | 14 | ``` 15 | 16 | #include 17 | using namespace std; 18 | int dp[100][100]={0}; 19 | 20 | int res; 21 | int LCS(string a,string b){ 22 | 23 | 24 | for(int i=1;i<=a.size();i++){ 25 | for(int j=1;j<=b.size();j++){ 26 | if(a[i-1]==b[j-1]) 27 | dp[i][j]=dp[i-1][j-1]+1; 28 | else 29 | dp[i][j]=max(dp[i-1][j],dp[i][j-1]); 30 | 31 | res=dp[i][j]; 32 | } 33 | } 34 | return res; 35 | // if(a.empty()||b.empty()) 36 | // return 0; 37 | 38 | 39 | // if(a[0]==b[0]) 40 | // return 1+LIS(a.substr(1),b.substr(1)); 41 | // else 42 | // return max(LIS(a.substr(1),b),LIS(a,b.substr(1))); 43 | 44 | 45 | } 46 | 47 | int main(){ 48 | 49 | string a,b; 50 | cin>>a>>b; 51 | 52 | cout<< LCS(a,b); 53 | 54 | for(int i=0;i<=a.size();i++){ 55 | for(int j=0;j<=b.size();j++){ 56 | cout<Longest Common Subsequence 2 | 3 |

Problem:

4 | Given an integer array nums, return the length of the longest strictly increasing subsequence. For example, [3,6,2,7] is a subsequence of the array [0,3,1,6,2,2,7]. 5 | 6 |

Algorithm:

7 | Input : arr[] = {3, 10, 2, 11} 8 | LIS[] = {1, 1, 1, 1} (initially) 9 | Iteration-wise simulation : 10 | 11 | 1. arr[2] > arr[1] {LIS[2] = max(LIS [2], LIS[1]+1)=2} 12 | 2. arr[3] < arr[1] {No change} 13 | 3. arr[3] < arr[2] {No change} 14 | 4. arr[4] > arr[1] {LIS[4] = max(LIS [4], LIS[1]+1)=2} 15 | 5. arr[4] > arr[2] {LIS[4] = max(LIS [4], LIS[2]+1)=3} 16 | 6. arr[4] > arr[3] {LIS[4] = max(LIS [4], LIS[3]+1)=3} 17 | 18 |

Implementation in C++:

19 | 20 | ``` 21 | #include 22 | using namespace std; 23 | 24 | int LIS(int *a,int n){ 25 | int list[n]; 26 | int mx=-1; 27 | vectorv; 28 | fill_n(list,n,1); 29 | 30 | for(int i=1;ia[j]){ 34 | list[i]=max(list[j]+1,list[i]); 35 | 36 | if(mxDepth First Search Algorithm 3 | The DFS algorithm is a recursive algorithm that uses the idea of backtracking. It involves exhaustive searches of all the nodes by going ahead, if possible, else by backtracking.Here, the word backtrack means that when you are moving forward and there are no more nodes along the current path, you move backwards on the same path to find nodes to traverse. All the nodes will be visited on the current path till all the unvisited nodes have been traversed after which the next path will be selected. 4 | Applications of DFS are finding connected components, Topological sorting, solving puzzles with only one solution, such as mazes. (DFS can be adapted to find all solutions to a maze by only including nodes on the current path in the visited set.), determining whether a species is closer to one species or another in a phylogenetic tree etc. 5 | 6 |

How does DFS algorithm work?

7 | This recursive nature of DFS can be implemented using stacks. The basic idea is as follows: 8 | Pick a starting node and push all its adjacent nodes into a stack. Pop a node from stack to select the next node to visit and push all its adjacent nodes into a stack. 9 | Repeat this process until the stack is empty. However, ensure that the nodes that are visited are marked. This will prevent you from visiting the same node more than once. If you do not mark the nodes that are visited and you visit the same node more than once, you may end up in an infinite loop. 10 | 11 |

Implementation in C++:

12 | 13 | ``` 14 | #include 15 | #define ll long long int 16 | #define f first 17 | #define s second 18 | #define pii pair 19 | #define pic pair 20 | using namespace std; 21 | 22 | // TC = O(V+E); 23 | // SC = O(V+E) + O(V) + O(V) 24 | // for adjlist col array Auxilery space for recursion 25 | 26 | void DFS(int i, int par, vector adj[], vector &vis){ 27 | 28 | vis[i] = 1; 29 | 30 | cout<<"Visited "<>v>>e; 41 | 42 | vectoradj[v+1]; 43 | vectorvis(v,0); 44 | 45 | for(int i=0;i>a>>b; 47 | --a,--b; 48 | adj[a].push_back(b); 49 | adj[b].push_back(a); 50 | } 51 | 52 | for(int i=0;i 2 | #define ll long long int 3 | #define f first 4 | #define s second 5 | #define pii pair 6 | #define pic pair 7 | using namespace std; 8 | 9 | // TC = O(V+E); 10 | // SC = O(V+E) + O(V) + O(V) 11 | // for adjlist col array Auxilery space for recursion 12 | 13 | int bipartite_DFS(int i, int par, vectoradj[], vector &col){ 14 | 15 | if(col[i]==-1)col[i] = 1; 16 | 17 | for(auto x: adj[i]){ 18 | 19 | if(col[x]==-1){ // not colored yet 20 | 21 | col[x] = 1-col[i]; 22 | 23 | if(!bipartite_DFS(x,i,adj,col)) // if one node return false then graph will not remain bipatitite 24 | return 0; 25 | 26 | } 27 | else if(col[x]==col[i]){ // x is visited now check x has different color to it's parent i or not 28 | return 0; 29 | } 30 | } 31 | 32 | return 1; 33 | 34 | } 35 | 36 | int main(){ 37 | 38 | int v,e;cin>>v>>e; 39 | 40 | vectoradj[v+1]; 41 | vectorvis(v,-1); 42 | 43 | for(int i=0;i>a>>b; 45 | --a,--b; 46 | adj[a].push_back(b); 47 | adj[b].push_back(a); 48 | } 49 | 50 | int flag = 0; 51 | 52 | for(int i=0;i 2 | using namespace std; 3 | #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL); 4 | #define f first 5 | #define s second 6 | #define pb push_back 7 | #define ll long long 8 | int MOD = 1e9+7; 9 | 10 | int ans=0; 11 | int DFS(int i,int par,vectoradj[]){ 12 | 13 | int mx = 0, premax = 0; 14 | for(auto x: adj[i]){ 15 | if(x != par){ 16 | int height = DFS(x,i,adj); 17 | if(mx < height ) 18 | premax = mx, mx = height; 19 | else if(premax < height) 20 | premax = height; 21 | } 22 | } 23 | ans = max(ans, mx+premax+1); 24 | return 1 + mx; 25 | } 26 | int main(){ 27 | 28 | int n;cin>>n; // number of nodes 29 | vectoradj[n+1]; 30 | 31 | for(int i=0;i>v>>u; 33 | --v,--u; 34 | adj[v].emplace_back(u); 35 | adj[u].emplace_back(v); 36 | } 37 | 38 | DFS(0,-1,adj); 39 | cout< 2 | using namespace std; 3 | #define pb push_back 4 | #define ll long long 5 | 6 | vectorgr[100002]; 7 | int vis[100002],par[100002],c[100002]; 8 | 9 | void dfs(int a,int p){ 10 | par[a]=p; 11 | for(int i=0;i>n>>r; 29 | for(int i=1;i>u>>v; 31 | gr[u].pb(v); 32 | gr[v].pb(u); 33 | } 34 | // int c[n+1]; 35 | for(int i=1;i<=n;i++){ 36 | cin>>c[i]; 37 | vis[i]=0; 38 | } 39 | dfs(1,1); 40 | vectorvv; // storing the path 41 | 42 | while(r!=1){ 43 | vv.pb(r); 44 | r=par[r]; 45 | } 46 | 47 | vv.pb(1); 48 | 49 | for(auto x: vv)cout< 2 | using namespace std; 3 | 4 | // start BFS from all rotten oranges initiallly and Cnt time in every level 5 | // until all oranges becomes rottten 6 | int inf = 1e5; 7 | 8 | int orangesRotting(vector>& grid) { 9 | 10 | int r = grid.size(), c = grid[0].size(); 11 | 12 | queue>q; 13 | vector>dis(r+1,vector(c+1,inf)); 14 | int time=0; 15 | 16 | // Multisource BFS 17 | for(int i=0;i=0&&nx=0&&ny 2 | using namespace std; 3 | const int N = 1e6+10; 4 | 5 | int MAX_INF[10]; 6 | bool visited[10]; 7 | 8 | struct node{ 9 | vector> end; 10 | 11 | }; 12 | 13 | struct node adj[10]; 14 | 15 | void BFS(int start){ 16 | MAX_INF[start]=0; 17 | int temp=start; 18 | 19 | queueq; 20 | q.push(start); 21 | visited[start]=0; 22 | 23 | while(!q.empty()){ 24 | 25 | start=q.front(); 26 | q.pop(); 27 | 28 | for(auto i: adj[start].end){ 29 | if(!visited[i.first]){ 30 | if(MAX_INF[start]+i.second>v>>e; 57 | 58 | for(int i=0;i>x>>y>>w; 60 | Dijiktra(x,y,w); 61 | } 62 | 63 | BFS(0); 64 | 65 | 66 | 67 | for(int i=0;i "<< MAX_INF[i]<q; 93 | 94 | // visited[start]=true; 95 | // q.push(start); 96 | 97 | // while(!q.empty()){ 98 | 99 | // start=q.front(); 100 | // q.pop(); 101 | 102 | // for(auto i:adj[start].end){ 103 | 104 | 105 | // } 106 | 107 | // } 108 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Graph/Standard Algos/Disjoint_set.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int parent[1000000]; 5 | int rnk[1000000]={0}; 6 | 7 | int find(int x){ 8 | if(parent[x]!=x) 9 | parent[x]=find(parent[x]); 10 | 11 | return parent[x]; 12 | } 13 | 14 | void Union(int x,int y){ 15 | 16 | int x_rep=find(x); 17 | int y_rep=find(y); 18 | 19 | if(rnk[x_rep]rnk[y_rep]) 22 | parent[y_rep]=x_rep; 23 | else{ 24 | parent[x_rep]=y_rep; 25 | rnk[y_rep]++; 26 | } 27 | } 28 | 29 | int main(){ 30 | int a,b; 31 | int v,e; 32 | cin>>v>>e; 33 | 34 | for(int i=1;i<=v;i++) 35 | parent[i]=i; 36 | 37 | for(int i=0;i>a>>b; 39 | Union(a,b); 40 | } 41 | 42 | if(find(4)==find(1)) 43 | cout<<"They belongs to same group"; 44 | else 45 | cout<<"They are not Connected"; 46 | 47 | 48 | cout<s; 50 | for(int i=1;i<=v;i++){ 51 | if(parent[i]==i){ 52 | s.push_back(i); 53 | ///cout<1) 59 | { 60 | for(int i=1;i 2 | using namespace std; 3 | 4 | int cnt=0; 5 | void DFS(int vertex,int par, int time, unordered_map>&adj,vector &low,vector &disc,vector &AP, vector &vis,vector>&bridges){ 6 | 7 | vis[vertex] = 1; 8 | low[vertex] = disc[vertex] = time++; 9 | // cout< disc[vertex]){ 21 | bridges.emplace_back(min(vertex,i),max(vertex,i)); 22 | } 23 | 24 | if(par == -1 && child>1) // root has more than one child 25 | AP[vertex] = 1,cnt++; 26 | if(par != -1 && low[i]>=disc[vertex]){ 27 | AP[vertex] = 1,cnt++; 28 | // cout<<"("<>V>>E; 42 | unordered_map>adj; 43 | for(int i=0;i>u>>v; 45 | // u--,v--; 46 | adj[u].emplace_back(v); 47 | adj[v].emplace_back(u); 48 | } 49 | vectorlow(V+1),disc(V+1),AP(V+1,0),vis(V+1,0); 50 | vector>bridges; 51 | 52 | for(int i=0;i 2 | using namespace std; 3 | 4 | // It's same like Prim's Alogrithm, each node will be traversed more than once 5 | 6 | // TC = O(VlogV+ELogV) = ElogV 7 | // SC = O(V)+O(V) { O(V) for Queue & O(V) for Indegree array} 8 | vector topoSort(int v, vector adj[]) 9 | { 10 | priority_queue, greater>q; 11 | vectorindegree(v+1,0),res; 12 | 13 | 14 | for(int i=0;i s.erase(s.begin()) // O(1) 32 | 33 | res.push_back(key+1); 34 | 35 | // you will explore all the Adjacent edges for each vetex, 36 | // So TC of this for loop is O(ElogV) 37 | 38 | // for key, We are going through all its vertices not the edge 39 | for(auto nbr: adj[key]){ // O(V) 40 | if(--indegree[nbr]==0) 41 | q.push(nbr); // O(logV) 42 | } 43 | } 44 | 45 | 46 | return res; 47 | } 48 | 49 | int main() { 50 | 51 | int v,e;cin>>v>>e; 52 | vectoradj[v+1]; 53 | for(int i=0;i>u>>v; 55 | 56 | adj[--u].push_back(--v); 57 | 58 | } 59 | 60 | 61 | vectorans = topoSort(v,adj); 62 | for(auto x: ans) 63 | cout< 14 | using namespace std; 15 | 16 | void DFS(int i, vectoradj[], vector&vis){ 17 | 18 | vis[i] = 1; 19 | for(auto x: adj[i]){ // O(E) 20 | if(!vis[x]){ 21 | DFS(x,adj,vis); 22 | } 23 | } 24 | 25 | } 26 | void TopoSort(int i, vectoradj[], vector&vis, stack&st){ 27 | 28 | vis[i] = 1; 29 | for(auto x: adj[i]){ // O(V+E) 30 | if(!vis[x]){ 31 | TopoSort(x,adj,vis,st); 32 | } 33 | } 34 | 35 | st.push(i); 36 | } 37 | 38 | int kosaraju(int V, vector adj[]) 39 | { 40 | vectorvis(V+1,0); 41 | 42 | stackst; 43 | for(int i=0;irevadj[V+1]; 51 | for(int i=0;i>v>>e; 78 | vectoradj[v+1]; 79 | for(int i=0;i>u>>v; 81 | 82 | adj[u].push_back(v); 83 | 84 | } 85 | 86 | cout< 0 ----> 3 94 | // 0 2 ^ | | 95 | // 2 1 \ | | 96 | // 0 3 \ | | 97 | // 3 4 \ | | 98 | // output: \ | | 99 | // 1 2 3 4 5 \ ▼ | 100 | // 2 4 101 | // There are 3 Connected Components in above graph 102 | // {0,1,2}, {3}, {4} 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Graph/Standard Algos/Kruskal_algo.cpp.txt: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // } Driver Code Ends 5 | 6 | 7 | bool comp(tuple a, tupleb){ 8 | 9 | int w1 = get<0>(a); 10 | int w2 = get<0>(b); 11 | 12 | return w1>&edges){ 41 | 42 | int ans=0; 43 | sort(edges.begin(),edges.end(),comp); 44 | int par[n+1]; 45 | memset(par,-1,sizeof par); 46 | 47 | for(tuple tp: edges){ 48 | int wt = get<0>(tp); 49 | int u = get<1>(tp); 50 | int v = get<2>(tp); 51 | 52 | if(findpar(u,par)==findpar(v,par)) // check par[u] == pra[v] so there is cycle 53 | continue; 54 | 55 | merge(u,v,par); 56 | ans += wt; 57 | 58 | } 59 | return ans; 60 | } 61 | int spanningTree(int V, vector> adj[]) 62 | { 63 | 64 | vector>edges; 65 | for(int i=0;i& v: adj[i]){ 67 | int child = v[0], wt = v[1]; 68 | edges.emplace_back(wt,i,child); 69 | } 70 | } 71 | 72 | return kruskal(V,edges); 73 | } 74 | }; 75 | 76 | // { Driver Code Starts. 77 | 78 | 79 | int main() 80 | { 81 | int t; 82 | cin >> t; 83 | while (t--) { 84 | int V, E; 85 | cin >> V >> E; 86 | vector> adj[V]; 87 | int i=0; 88 | while (i++> u >> v >> w; 91 | vector t1,t2; 92 | t1.push_back(v); 93 | t1.push_back(w); 94 | adj[u].push_back(t1); 95 | t2.push_back(u); 96 | t2.push_back(w); 97 | adj[v].push_back(t2); 98 | } 99 | 100 | Solution obj; 101 | cout << obj.spanningTree(V, adj) << "\n"; 102 | } 103 | 104 | return 0; 105 | } 106 | 107 | // } Driver Code Ends -------------------------------------------------------------------------------- /Data Structures and Algorithms/Graph/Standard Algos/Prim's_algo.cpp.txt: -------------------------------------------------------------------------------- 1 | (I) Select any vertex of given graph and add it to MST 2 | (II) Add the edge of minimum weight from a vertex not in MST to the vertex in MST; 3 | (III) It MST is complete the stop, otherwise go to step (II). 4 | 5 | *Worst case is the worst case time complexity of Prim’s algorithm if adjacency matrix is used? 6 | Use of adjacency matrix provides the simple implementation of the Prim’s algorithm. In Prim’s algorithm, we need to search for the edge with a minimum for that vertex. So, worst case time complexity will be O(V2), where V is the number of vertices. -------------------------------------------------------------------------------- /Data Structures and Algorithms/Graph/Standard Algos/floyd_Warshell.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | const int N = 1e6+10; 4 | 5 | int MAX_INF[10]; 6 | bool visited[10]; 7 | 8 | struct node{ 9 | vector> end; 10 | 11 | }; 12 | 13 | struct node adj[10]; 14 | 15 | void BFS(int start){ 16 | MAX_INF[start]=0; 17 | int temp=start; 18 | 19 | queueq; 20 | q.push(start); 21 | visited[start]=0; 22 | 23 | while(!q.empty()){ 24 | 25 | start=q.front(); 26 | q.pop(); 27 | 28 | for(auto i: adj[start].end){ 29 | if(!visited[i.first]){ 30 | if(MAX_INF[start]+i.second>v>>e; 57 | 58 | for(int i=0;i>x>>y>>w; 60 | Dijiktra(x,y,w); 61 | } 62 | 63 | 64 | for(int i=0;i "; 68 | for(int i=0;iq; 101 | 102 | // visited[start]=true; 103 | // q.push(start); 104 | 105 | // while(!q.empty()){ 106 | 107 | // start=q.front(); 108 | // q.pop(); 109 | 110 | // for(auto i:adj[start].end){ 111 | 112 | 113 | // } 114 | 115 | // } 116 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Graph/Topological_sort_DFS.cpp.txt: -------------------------------------------------------------------------------- 1 | void Topological_sort(int i,vectoradj[], vector& vis, stack&st){ 2 | vis[i] = 1; 3 | 4 | for(auto &x : adj[i]){ 5 | if(!vis[x]){ 6 | Topological_sort(x,adj,vis,st); 7 | } 8 | } 9 | 10 | st.push(i); 11 | } 12 | 13 | 14 | vector topoSort(int v, vector adj[]) 15 | { 16 | vectorvis(v+1,0),ans; 17 | stackst; 18 | 19 | for(int i=0;i 2 | #define ll long long int 3 | #define f first 4 | #define s second 5 | #define pii pair 6 | #define pic pair 7 | using namespace std; 8 | 9 | int main(){ 10 | 11 | int n,m;cin>>n>>m; 12 | vector>grid(n+1,vector(m+1)); 13 | vector>vis(n+1,vector(m+1,0)); 14 | 15 | int stx,sty; 16 | for(int i=0;i>grid[i][j]; 19 | if(grid[i][j]=='A') 20 | stx = i, sty = j; 21 | } 22 | } 23 | 24 | int dx[] = {1,-1,0,0}; 25 | int dy[] = {0,0,-1,1}; 26 | vectors = {'D','U','L','R'}; 27 | 28 | unordered_mapmp; 29 | queueq; // int,int 30 | q.push({stx,sty}); 31 | vis[stx][sty] = 1; 32 | int ans = -1,a = stx * m + sty; 33 | while(!q.empty()){ 34 | 35 | int i = q.front().f, j = q.front().s; 36 | q.pop(); 37 | // cout<=0 && nx=0 && ny 2 | #define all(x) x.begin(),x.end() 3 | #define pb push_back 4 | #define IOfast ios_base::sync_with_stdio(false); cin.tie(NULL); 5 | using namespace std; 6 | 7 | int visited[(int)2e5 + 1]; 8 | vector graph[(int)2e5 + 1]; 9 | vector path; // to keep track of paths 10 | 11 | void dfs(int node,int par) 12 | { 13 | visited[node] = 1; 14 | path.pb(node); 15 | for(auto &next:graph[node]) 16 | { 17 | if(par == next) continue; 18 | 19 | if(visited[next]) 20 | { 21 | path.pb(next); 22 | int i = (find(all(path),next) - path.begin()); 23 | cout<>n>>m; 40 | 41 | while(m--) 42 | cin>>u>>v , graph[u].pb(v) , graph[v].pb(u); 43 | 44 | for(int i = 1;i<=n;i++) 45 | if(visited[i] == 0) 46 | dfs(i,0); 47 | 48 | cout<<"IMPOSSIBLE"; 49 | } 50 | 51 | int main() 52 | { 53 | IOfast; 54 | solve(); 55 | 56 | return 0; 57 | } -------------------------------------------------------------------------------- /Data Structures and Algorithms/Graph/sum_from_each_node_to_each_node.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | #define f first 4 | #define s second 5 | #define pii pair 6 | #define pic pair 7 | using namespace std; 8 | 9 | 10 | int BFS(int u, int v,int V, vectoradj[], vector&arr){ 11 | 12 | vectorvis(V+1,0),parent(V+1,-1); 13 | 14 | int ans=0; 15 | queue>q; 16 | 17 | q.push({u,-1}); 18 | 19 | vis[u] = 1; 20 | 21 | while(!q.empty()){ 22 | 23 | int node = q.front().f, par = q.front().s; 24 | 25 | q.pop(); 26 | 27 | if(node==v){ 28 | int ans = 0; 29 | while(v != -1){ 30 | // cout<>V>>e; 53 | vectoradj[V+1]; 54 | 55 | while(e--){ 56 | cin>>a>>b; 57 | adj[a].push_back(b); 58 | adj[b].push_back(a); 59 | } 60 | 61 | vectorarr(V); 62 | for(auto &x: arr) cin>>x; 63 | 64 | int q;cin>>q; 65 | // cout<>u>>v; 68 | vectorvis(V+1,0); 69 | cout< 23 | #include 24 | 25 | /*Declaring heap globally so that we do not need to pass it as an argument every time*/ 26 | /* Heap implemented here is Min Heap */ 27 | 28 | int heap[1000000], heapSize; 29 | /*Initialize Heap*/ 30 | void Init() { 31 | heapSize = 0; 32 | heap[0] = -INT_MAX; 33 | } 34 | 35 | /*Insert an element into the heap */ 36 | void Insert(int element) { 37 | heapSize++; 38 | heap[heapSize] = element; /*Insert in the last place*/ 39 | /*Adjust its position*/ 40 | int now = heapSize; 41 | while (heap[now / 2] > element) { 42 | heap[now] = heap[now / 2]; 43 | now /= 2; 44 | } 45 | heap[now] = element; 46 | } 47 | 48 | int DeleteMin() { 49 | /* heap[1] is the minimum element. So we remove heap[1]. Size of the heap is decreased. 50 | Now heap[1] has to be filled. We put the last element in its place and see if it fits. 51 | If it does not fit, take minimum element among both its children and replaces parent with it. 52 | Again See if the last element fits in that place.*/ 53 | int minElement, lastElement, child, now; 54 | minElement = heap[1]; 55 | lastElement = heap[heapSize--]; 56 | /* now refers to the index at which we are now */ 57 | for (now = 1; now * 2 <= heapSize; now = child) { 58 | /* child is the index of the element which is minimum among both the children */ 59 | /* Indexes of children are i*2 and i*2 + 1*/ 60 | child = now * 2; 61 | /*child!=heapSize beacuse heap[heapSize+1] does not exist, which means it has only one 62 | child */ 63 | if (child != heapSize && heap[child + 1] < heap[child]) { 64 | child++; 65 | } 66 | /* To check if the last element fits ot not it suffices to check if the last element 67 | is less than the minimum element among both the children*/ 68 | if (lastElement > heap[child]) { 69 | heap[now] = heap[child]; 70 | } else /* It fits there */ 71 | { 72 | break; 73 | } 74 | } 75 | heap[now] = lastElement; 76 | return minElement; 77 | } 78 | 79 | int main() { 80 | int number_of_elements; 81 | printf("Program to demonstrate Heap:\nEnter the number of elements: "); 82 | scanf("%d", &number_of_elements); 83 | int iter, element; 84 | Init(); 85 | printf("Enter the elements: "); 86 | for (iter = 0; iter < number_of_elements; iter++) { 87 | scanf("%d", &element); 88 | Insert(element); 89 | } 90 | for (iter = 0; iter < number_of_elements; iter++) { 91 | printf("%d ", DeleteMin()); 92 | } 93 | printf("\n"); 94 | return 0; 95 | } 96 | ~~~ 97 | 98 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Kadens_algorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n;int MaxSumSubarray(int a[], int n); 6 | int maximum_sum; 7 | cout << "enter size of array" << endl; 8 | cin >> n; 9 | int a[n]; 10 | for (int i = 0; i < n; i++) 11 | { 12 | cin >> a[i]; 13 | } 14 | maximum_sum = MaxSumSubarray(a, n); 15 | cout << maximum_sum; 16 | } 17 | int MaxSumSubarray(int a[], int n) 18 | { //example [5,-4,-2,6,-1] 19 | int current_sum = 0; 20 | int max_sum = 0; 21 | for (int i = 0; i < n; i++) 22 | { 23 | current_sum += a[i]; 24 | if (current_sum > max_sum) 25 | { 26 | max_sum = current_sum; 27 | } 28 | if (current_sum < 0) 29 | { 30 | current_sum = 0; 31 | } 32 | } 33 | return max_sum; 34 | } 35 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/LRU_Cache.cpp: -------------------------------------------------------------------------------- 1 | class LRUCache { 2 | public: 3 | 4 | // if I put any key,value then check if its already there in my map, if its there erase from the map and insert new node of given key,value 5 | // if capacity is full then I have to delete Leasat recently used node which exits in the last 6 | 7 | // In case of get, the given key is present in map then erase it from its position and assign the new position position right by making new node(copy of given key) and insert also in to the map with new address 8 | class Node{ 9 | 10 | public: 11 | 12 | Node* next,*prev; 13 | int key,val; 14 | 15 | Node(int _key, int _value){ 16 | key =_key, val = _value; 17 | } 18 | }; 19 | 20 | Node* head = new Node(-1,-1); 21 | Node* tail = new Node(-1,-1); 22 | int cap; 23 | 24 | unordered_map mp; // 25 | 26 | LRUCache(int capacity) { 27 | cap= capacity; 28 | head->next = tail; 29 | tail->prev = head; 30 | } 31 | 32 | 33 | void addNode(Node* newNode){ // Delete from DLL 34 | 35 | Node* tmp = head->next; 36 | 37 | newNode->next = tmp; 38 | newNode->prev = head; 39 | head->next = newNode; 40 | tmp->prev = newNode; 41 | } 42 | 43 | void deleteNode(Node* delNode){ // delete form DLL 44 | 45 | Node* delprev = delNode->prev; 46 | Node* delNext = delNode->next; 47 | delprev->next = delNext; 48 | delNext->prev = delprev; 49 | 50 | } 51 | 52 | int get(int key) { 53 | 54 | 55 | if(mp.count()) 56 | return 57 | if(mp.count(key)){ // if key is present 58 | Node* getNode = mp[key]; 59 | deleteNode(getNode); // delete the node from DLL 60 | mp.erase(key); // delete the node from hashmap 61 | addNode(getNode); // add new node(copy of deleted node) into DLL 62 | mp[key] = getNode; // add node into hashmap 63 | return getNode->val; 64 | } 65 | 66 | 67 | 68 | } 69 | 70 | void put(int key, int value) { 71 | 72 | 73 | 74 | // if key is present in hashmap 75 | if(mp.count(key)){ 76 | Node* existingNode = mp[key]; 77 | mp.erase(key); 78 | deleteNode(existingNode); // or mp[key] 79 | } 80 | 81 | if(mp.size()==cap){ // cap is full then deleting the least recently used node 82 | mp.erase(tail->prev->key); 83 | deleteNode(tail->prev); // tail = tail->prev; 84 | } 85 | 86 | 87 | Node* newNode = new Node(key, value); 88 | mp[key] = newNode; // insert newnode into hashmap 89 | addNode(newNode); // add newNod into DLL 90 | 91 | } 92 | }; 93 | 94 | /** 95 | * Your LRUCache object will be instantiated and called as such: 96 | * LRUCache* obj = new LRUCache(capacity); 97 | * int param_1 = obj->get(key); 98 | * obj->put(key,value); 99 | */ -------------------------------------------------------------------------------- /Data Structures and Algorithms/LinkedList/Intersection of Two Linked List/Approach_1.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode(int x) : val(x), next(NULL) {} 7 | * }; 8 | */ 9 | 10 | // Leetcode 160 : Given the heads of two singly linked-lists headA and headB, 11 | // return the node at which the two lists intersect. 12 | // If the two linked lists have no intersection at all, return null. 13 | 14 | // Note that the linked lists must retain their original structure 15 | // after the function returns. 16 | 17 | class Solution { 18 | public: 19 | 20 | 21 | ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { 22 | ListNode* curr1 = headA, *curr2 = headB; 23 | while(curr1!=curr2){ 24 | curr1 = curr1 ? curr1 = curr1->next : headB; 25 | curr2 = curr2 ? curr2 = curr2->next : headA; 26 | } 27 | return curr1; 28 | } 29 | }; -------------------------------------------------------------------------------- /Data Structures and Algorithms/LinkedList/Intersection of Two Linked List/Approach_2.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode(int x) : val(x), next(NULL) {} 7 | * }; 8 | */ 9 | 10 | // Leetcode 160 : Given the heads of two singly linked-lists headA and headB, 11 | // return the node at which the two lists intersect. 12 | // If the two linked lists have no intersection at all, return null. 13 | 14 | // Note that the linked lists must retain their original structure 15 | // after the function returns. 16 | 17 | class Solution { 18 | public: 19 | 20 | int length(ListNode* head){ 21 | int l=0; ListNode* tmp = head; 22 | while(head){ 23 | l++,head = head->next; 24 | } 25 | return l; 26 | } 27 | ListNode* moveK(ListNode* head, int k){ 28 | while(k--){ 29 | head = head->next; 30 | } 31 | return head; 32 | } 33 | ListNode* findIntersection(ListNode* l1, ListNode* l2){ 34 | while(l1!=l2){ 35 | l1 = l1->next; 36 | l2 = l2->next; 37 | } 38 | return l1; 39 | } 40 | ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { 41 | int x = length(headA); 42 | int y = length(headB); 43 | 44 | if(x==y) return findIntersection(headA, headB); 45 | 46 | return x>y ? findIntersection(moveK(headA,x-y),headB) : findIntersection(headA, moveK(headB,y-x)); 47 | } 48 | }; -------------------------------------------------------------------------------- /Data Structures and Algorithms/LinkedList/Linked List Cycle ll/Approach_1.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode(int x) : val(x), next(NULL) {} 7 | * }; 8 | */ 9 | 10 | 11 | // Leetcode 142 : Given the head of a linked list, return the node where the cycle 12 | // begins. If there is no cycle, return null. 13 | 14 | // There is a cycle in a linked list if there is some node in the list 15 | // that can be reached again by continuously following the next pointer. 16 | // Internally, pos is used to denote the index of the node 17 | // that tail's next pointer is connected to (0-indexed). 18 | // It is -1 if there is no cycle. 19 | // 20 | // Note that pos is not passed as a parameter. 21 | 22 | // Do not modify the linked list. 23 | 24 | 25 | class Solution { 26 | public: 27 | ListNode *detectCycle(ListNode *A) { 28 | 29 | if(!A)return NULL; 30 | 31 | ListNode* dummy = new ListNode(0); 32 | dummy->next = A; 33 | ListNode* slow = dummy->next, *fast = A->next; 34 | 35 | while(fast && fast->next && slow != fast ){ 36 | slow = slow->next; 37 | fast = fast->next->next; 38 | } 39 | 40 | if(!fast) return NULL; 41 | 42 | fast = dummy; 43 | while(slow && slow != fast){ 44 | slow = slow->next; 45 | fast = fast->next; 46 | } 47 | 48 | return slow; 49 | 50 | } 51 | }; -------------------------------------------------------------------------------- /Data Structures and Algorithms/LinkedList/Linked List Cycle ll/Approach_2.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode(int x) : val(x), next(NULL) {} 7 | * }; 8 | */ 9 | 10 | // Leetcode 142 : Given the head of a linked list, return the node where the cycle 11 | // begins. If there is no cycle, return null. 12 | 13 | // There is a cycle in a linked list if there is some node in the list 14 | // that can be reached again by continuously following the next pointer. 15 | // Internally, pos is used to denote the index of the node 16 | // that tail's next pointer is connected to (0-indexed). 17 | // It is -1 if there is no cycle. 18 | // 19 | // Note that pos is not passed as a parameter. 20 | 21 | // Do not modify the linked list. 22 | 23 | class Solution { 24 | public: 25 | ListNode *detectCycle(ListNode *A) { 26 | 27 | 28 | ListNode* slow = A, *fast = A; 29 | 30 | while(fast && slow && fast->next){ 31 | slow = slow->next; 32 | fast = fast->next->next; 33 | 34 | if(slow == fast){ 35 | 36 | fast = fast, slow = A; 37 | 38 | while(slow != fast){ 39 | slow = slow->next; 40 | fast = fast->next; 41 | } 42 | 43 | return slow; 44 | 45 | } 46 | } 47 | 48 | return NULL; 49 | 50 | } 51 | }; -------------------------------------------------------------------------------- /Data Structures and Algorithms/LinkedList/merge_k_sorted_list.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode() : val(0), next(nullptr) {} 7 | * ListNode(int x) : val(x), next(nullptr) {} 8 | * ListNode(int x, ListNode *next) : val(x), next(next) {} 9 | * }; 10 | */ 11 | 12 | 13 | // Leetcde 23 : You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. 14 | // Merge all the linked-lists into one sorted linked-list and return it. 15 | 16 | #define f first 17 | #define s second 18 | 19 | class Solution { 20 | public: 21 | 22 | ListNode* mergeKLists(vector& lists) { 23 | 24 | 25 | priority_queue< pair> , vector>>, greater>> >pq; 26 | 27 | ListNode* head = new ListNode(0); 28 | ListNode* curr = head; 29 | 30 | 31 | int n = lists.size(); 32 | 33 | for(int i=0;ival,{i,lists[i]}}); 36 | 37 | while(!pq.empty()){ 38 | 39 | int i = pq.top().s.f; 40 | ListNode* node = pq.top().s.s; 41 | 42 | pq.pop(); 43 | 44 | // cout<val<<" "; 45 | curr->next = node; 46 | // cout<val<<" "; 47 | curr = curr->next; 48 | 49 | if(node->next) 50 | pq.push({node->next->val,{i,node->next}}); 51 | 52 | 53 | } 54 | return head->next; 55 | } 56 | }; -------------------------------------------------------------------------------- /Data Structures and Algorithms/LinkedList/palindrome_linked_list.cpp: -------------------------------------------------------------------------------- 1 | // Leetcode 234: Given the head of a singly linked list, 2 | // return true if it is a palindrome. 3 | 4 | class Solution { 5 | public: 6 | 7 | void print(ListNode* node){ 8 | 9 | while(node){ 10 | cout<val<<" "; 11 | node = node->next; 12 | } 13 | } 14 | ListNode* reverseList(ListNode* node){ 15 | 16 | ListNode* prev = NULL, *curr = node,*tmp; 17 | 18 | while(curr){ 19 | tmp = curr->next; 20 | curr->next = prev; 21 | prev = curr; 22 | 23 | curr = tmp; 24 | 25 | } 26 | return prev; 27 | 28 | } 29 | 30 | bool isPalindrome(ListNode* head) { 31 | 32 | 33 | ListNode* curr = head, *fast = head; 34 | 35 | while(fast && fast->next ){ 36 | 37 | curr = curr->next; 38 | fast = fast->next->next; 39 | 40 | // cout<val<<" "; 41 | } 42 | 43 | ListNode* head2 = reverseList(curr); 44 | 45 | // if(!head2)return 0; 46 | print(head2); 47 | while(head2){ 48 | // cout<val<<" "<val<val != head->val) 51 | return 0; 52 | 53 | head2 = head2->next; 54 | head = head->next; 55 | 56 | } 57 | 58 | return 1; 59 | } 60 | }; 61 | 62 | 63 | // Recursive soln in O(n) time and O(n) Auxillery space 64 | // class Solution { 65 | // public: 66 | // ListNode* temp; 67 | // bool isPalindrome(ListNode* head) { 68 | // temp = head; 69 | // return check(head); 70 | // } 71 | 72 | // bool check(ListNode* p) { 73 | // if (NULL == p) return true; 74 | // bool isPal = check(p->next) & (temp->val == p->val); 75 | // temp = temp->next; 76 | // return isPal; 77 | // } 78 | // }; -------------------------------------------------------------------------------- /Data Structures and Algorithms/LinkedList/reorder_list.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode() : val(0), next(nullptr) {} 7 | * ListNode(int x) : val(x), next(nullptr) {} 8 | * ListNode(int x, ListNode *next) : val(x), next(next) {} 9 | * }; 10 | */ 11 | 12 | // Leetcode 143: You are given the head of a singly linked-list. The list can be represented as: 13 | 14 | // L0 → L1 → … → Ln - 1 → Ln 15 | // Reorder the list to be on the following form: 16 | 17 | // L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → … 18 | // You may not modify the values in the list's nodes. Only nodes themselves may be changed. 19 | 20 | 21 | 22 | class Solution { 23 | public: 24 | 25 | ListNode* reverse(ListNode* head){ 26 | ListNode* curr = head, *prev = NULL; 27 | while(curr){ 28 | ListNode* currNext = curr->next; 29 | curr->next = prev; 30 | prev = curr; 31 | curr = currNext; 32 | } 33 | return prev; 34 | 35 | } 36 | 37 | ListNode* Merge(ListNode* l1,ListNode* l2){ 38 | 39 | if(!l2)return l1; 40 | if(!l1)return l2; 41 | 42 | ListNode* l2Next = l2->next; 43 | ListNode* l1Next = l1->next; 44 | 45 | l1->next = l2; 46 | l2->next = Merge(l1Next,l2Next); 47 | 48 | return l1; 49 | } 50 | void print(ListNode* head){ 51 | while(head){ 52 | cout<val<<" "; 53 | head = head->next; 54 | } 55 | cout<next)return; 60 | ListNode* slow = head, *fast = head; 61 | while(fast->next && fast->next->next){ 62 | slow = slow->next; 63 | fast = fast->next->next; 64 | } 65 | 66 | ListNode* mid = slow->next; 67 | slow->next = NULL; 68 | fast = reverse(mid); 69 | // print(head); 70 | // print(fast); 71 | 72 | head = Merge(head,fast); 73 | 74 | } 75 | }; -------------------------------------------------------------------------------- /Data Structures and Algorithms/LinkedList/rotate_list.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode() : val(0), next(nullptr) {} 7 | * ListNode(int x) : val(x), next(nullptr) {} 8 | * ListNode(int x, ListNode *next) : val(x), next(next) {} 9 | * }; 10 | */ 11 | 12 | // Leetcode 61: Given the head of a linked list,rotate the list to the 13 | // right by k places. 14 | 15 | class Solution { 16 | public: 17 | 18 | ListNode* rotate(ListNode* start, ListNode* end,int len, int k){ 19 | int x = len-k; 20 | while(x--){ 21 | start = start->next; 22 | end = end->next; 23 | } 24 | end->next = NULL; 25 | return start; 26 | } 27 | 28 | ListNode* rotateRight(ListNode* A, int B){ 29 | 30 | if(!A)return A; 31 | 32 | ListNode* slow = A, *fast = A; 33 | int len=1; 34 | 35 | while(fast->next){ 36 | fast = fast->next; 37 | len++; 38 | } 39 | fast->next = A; 40 | return rotate(A,fast,len,B % len); 41 | 42 | } 43 | }; -------------------------------------------------------------------------------- /Data Structures and Algorithms/LinkedList/sort_list.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode() : val(0), next(nullptr) {} 7 | * ListNode(int x) : val(x), next(nullptr) {} 8 | * ListNode(int x, ListNode *next) : val(x), next(next) {} 9 | * }; 10 | */ 11 | 12 | // Leetcode 148 : Given the head of a linked list, return the list after sorting it in ascending order. 13 | 14 | class Solution { 15 | public: 16 | ListNode* MergeTwoSortedList(ListNode* a, ListNode* b){ 17 | 18 | if(!a)return b; 19 | if(!b)return a; 20 | 21 | ListNode* root; 22 | if(a->val <= b->val){ 23 | root = new ListNode(a->val); 24 | root->next = MergeTwoSortedList(a->next,b); 25 | } 26 | else{ 27 | root = new ListNode(b->val); 28 | root->next = MergeTwoSortedList(a,b->next); 29 | } 30 | 31 | return root; 32 | } 33 | 34 | ListNode* sortList(ListNode* head) { 35 | 36 | if(!head || !head->next)return head; 37 | 38 | ListNode* slow = head, *fast = head,*prev = head; 39 | 40 | while(fast->next && fast->next->next){ 41 | prev = slow; 42 | slow = slow->next; 43 | fast = fast->next->next; 44 | 45 | } 46 | 47 | ListNode* mid = prev->next; 48 | prev->next = NULL; 49 | 50 | // ListNode* root = new ListNode(mid->val); 51 | ListNode* leftPart = sortList(head); 52 | ListNode* RightPart = sortList(mid); 53 | // if(leftPart) 54 | // cout<val<<" "; 55 | // if(RightPart) 56 | // cout<val<<" "; 57 | // cout<next)return new TreeNode(A->val); 36 | 37 | ListNode* slow = A, *fast = A, *prev = A; 38 | while(fast->next && fast->next->next){ 39 | prev = slow; 40 | slow = slow->next; 41 | fast = fast->next->next; 42 | } 43 | 44 | ListNode* mid = prev->next; // mid == slow 45 | prev->next = NULL; 46 | TreeNode* root = new TreeNode(mid->val); 47 | root->left = sortedListToBST(A); 48 | root->right = sortedListToBST(mid->next); 49 | 50 | return root; 51 | 52 | } 53 | }; -------------------------------------------------------------------------------- /Data Structures and Algorithms/Manacher's_Algo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Manacher's Algorithm 5 | string Manachers_algo(string &s){ 6 | 7 | int n = s.size(); 8 | vectorp(n,0); 9 | int R=0,C=0; 10 | vectorres = {0,0,0}; 11 | for(int k=1;k 18 | #include 19 | struct queue 20 | { 21 | int size; 22 | int front; 23 | int rear; 24 | int *Q; 25 | }; 26 | void create(struct queue *q,int size) 27 | { 28 | q->size=size; 29 | q->front=q->rear=-1; 30 | q->Q=(int *)malloc(q->size*sizeof(int)); 31 | } 32 | void enqueue(struct queue *q,int x) 33 | { 34 | if(q->rear==q->size-1) 35 | { 36 | printf("Queue is Full"); 37 | } 38 | else 39 | { 40 | q->rear++; 41 | q->Q[q->rear]=x; 42 | } 43 | } 44 | int dequeue(struct queue *q) 45 | { 46 | int x=-1; 47 | if(q->rear==q->front) 48 | { 49 | printf("Queue is empty"); 50 | } 51 | else 52 | { 53 | q->front++; 54 | x=q->Q[q->front]; 55 | } 56 | return x; 57 | 58 | 59 | } 60 | void display(struct queue q) 61 | { 62 | for(int i=q.front+1;i<=q.rear;i++) 63 | { 64 | printf("%d ",q.Q[i]); 65 | } 66 | printf("\n"); 67 | } 68 | int main() 69 | { 70 | struct queue q; 71 | create(&q,5); 72 | enqueue(&q,10); 73 | enqueue(&q,20); 74 | enqueue(&q,30); 75 | display(q); 76 | printf("%d",dequeue(&q)); 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Segment Tree/Explanation.txt: -------------------------------------------------------------------------------- 1 | 2 | Range Sum Query: 3 | 4 | Let's consider the problem to understand concept of segment tree. 5 | 6 | You have given an array of length n and you've given q queries to 7 | 1. Find the sum of elements from index l to r where 0 <= l <= r < n. 8 | 2. Update the ith value of array to new value x, a[i] = x 9 | 10 | First Method: we can calculate sum for every range l to r, that will take O(n) time and for updating the value that will take O(1). 11 | Second Method: prefixsum, we can calculate sum for every range l to r, that will take O(1) time using prefix[r] - prefic[l-1] and for updating the value that will take O(n) as we've to maintain the prefix sum array. 12 | Third Method: The most efficient method is to use a segment tree, we can use a Segment Tree to do both operations in O(log(N)) time. 13 | 14 | #Build Segment Tree: Time Complexity O(N) 15 | 16 | Using Divide & Conquer Technique, start from the root and recurse on the left and the right child until a leaf node is reached. From the leaves, go back to the root and update all the nodes in the path (like seg_tree[node]=seg_tree[2*node+1]+seg_tree[2*node+2].). Here 'node' represents the current node is being processed, 2*node+1 is left node and 2*node+2 is the right node of the current node. 17 | 18 | for example: 19 | Arr[N] = {2,6,4,5,1} 20 | 21 | 18[0,4] 22 | / \ 23 | / \ 24 | / \ 25 | 8[0,1] 10[2,4] 26 | / \ / \ 27 | / \ / \ 28 | / \ / \ 29 | 2[0,0] 6[1,1] 9[2,3] 1[4,4] 30 | / \ 31 | / \ 32 | 4[2,2] 5[3,3] 33 | 34 | 35 | #Query in a given range: Time Complexity O(logN) 36 | 37 | To query on a given range, check 3 conditions. 38 | 39 | a) Range represented by a node is completely inside the given range 40 | b) Range represented by a node is completely outside the given range 41 | c) Range represented by a node is partially inside and partially outside the given range 42 | 43 | ------------------------------------------------------------------------------------------------------------------ 44 | 45 | Range Minimum Query: 46 | 47 | for example: 48 | Arr[N] = {2,6,4,5,1} 49 | 50 | 1[0,4] 51 | / \ 52 | / \ 53 | / \ 54 | 2[0,1] 1[2,4] 55 | / \ / \ 56 | / \ / \ 57 | / \ / \ 58 | 2[0,0] 6[1,1] 4[2,3] 1[4,4] 59 | / \ 60 | / \ 61 | 4[2,2] 5[3,3] 62 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Segment Tree/Range_minimum_query.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long 4 | 5 | vectorseg_tree; 6 | vectorv; 7 | 8 | void build_tree(int st,int en,int node){ 9 | 10 | if(st==en){ 11 | seg_tree[node]=v[st]; 12 | return; 13 | } 14 | 15 | int mid=(st+en)/2; 16 | 17 | build_tree(st,mid,2*node+1); 18 | build_tree(mid+1,en,2*node+2); 19 | 20 | seg_tree[node]= min(seg_tree[2*node+1],seg_tree[2*node+2]); 21 | 22 | } 23 | 24 | void Update(int value,int index,int st,int en,int node){ 25 | 26 | if(st==en){ 27 | v[index]=value; 28 | seg_tree[node]=v[st]; 29 | return ; 30 | } 31 | 32 | int mid=(st+en)/2; 33 | 34 | Update(value,index,st,mid,2*node+1); 35 | 36 | Update(value,index,mid+1,en,2*node+2); 37 | 38 | seg_tree[node]= min(seg_tree[2*node+1],seg_tree[2*node+2]); 39 | 40 | } 41 | 42 | ll query(ll node,ll st,ll en,ll l,ll r){ 43 | 44 | // l...st....en..r 45 | if(l<=st and en<=r) 46 | return seg_tree[node]; 47 | // r...st...en...l 48 | else if(r>n; 60 | seg_tree.resize(4*n); 61 | v.resize(n); 62 | for(int i=0;i>v[i]; 64 | } 65 | 66 | build_tree(0,v.size()-1,0); 67 | 68 | int q;cin>>q; 69 | for(int i=0;i>l>>r; 71 | cout<<"Minimum from index "< 2 | using namespace std; 3 | #define ll long long 4 | 5 | vectorseg_tree; 6 | vectorv; 7 | 8 | void build_tree(int st,int en,int node){ 9 | 10 | if(st==en){ 11 | seg_tree[node]=v[st]; 12 | return; 13 | } 14 | 15 | int mid=(st+en)/2; 16 | 17 | build_tree(st,mid,2*node+1); 18 | build_tree(mid+1,en,2*node+2); 19 | 20 | seg_tree[node]=seg_tree[2*node+1]+seg_tree[2*node+2]; 21 | 22 | } 23 | 24 | void Update(int value,int index,int st,int en,int node){ 25 | 26 | if(st==en){ 27 | v[index]=value; 28 | seg_tree[node]=v[st]; 29 | return ; 30 | } 31 | 32 | int mid=(st+en)/2; 33 | 34 | Update(value,index,st,mid,2*node+1); 35 | 36 | Update(value,index,mid+1,en,2*node+2); 37 | 38 | seg_tree[node]=seg_tree[2*node+1]+seg_tree[2*node+2]; 39 | 40 | } 41 | 42 | ll query(ll node,ll st,ll en,ll l,ll r){ 43 | 44 | // l...st....en..r 45 | if(l<=st and en<=r) 46 | return seg_tree[node]; 47 | // r...st...en...l 48 | else if(r>n; 60 | seg_tree.resize(4*n); 61 | v.resize(n); 62 | for(int i=0;i>v[i]; 64 | } 65 | 66 | build_tree(0,v.size()-1,0); 67 | 68 | int q;cin>>q; 69 | for(int i=0;i>l>>r; 71 | cout<<"Sum from index "< 2 | using namespace std; 3 | // void swp(int &x,int &y){ 4 | // int *temp = &x; 5 | // x= y; 6 | // y=temp; 7 | // } 8 | 9 | int main(){ 10 | 11 | vector>bucket(10); 12 | 13 | int n,m=0;cin>>n; 14 | int a[n],b[n]; 15 | 16 | for(int i=0;i>a[i]; 18 | cout< "; 41 | // for(auto x:bucket[i]){ 42 | // if(flag==0){ 43 | // flag=1; 44 | // num=x; 45 | // p=&x; 46 | // } 47 | // else 48 | // { 49 | // q=&x; 50 | // if(x "; 61 | for(auto x:bucket[i]){ 62 | cout< 2 | using namespace std; 3 | 4 | void print(vectortmp){ 5 | 6 | for(int i=0;i>mset; 11 | // void subsetsWithDup(vector& v,int index,string s){ 12 | 13 | // mset.insert(s); 14 | // // cout<temp= s; 17 | // s.insert(v[i]); 18 | // subsetsWithDup(v,i+1,s); 19 | // // subsetsWithDup(v,st+1,en,temp); 20 | // // s.pop_back(); 21 | // } 22 | // } 23 | #define N 10 24 | vectora(N,0); 25 | void countsort(vector&v){ 26 | 27 | int n=v.size(); 28 | vectorans; 29 | for(int i=0;i>n; 47 | vectorv(n); 48 | 49 | for(auto &x: v) 50 | cin>>x; 51 | 52 | countsort(v); 53 | 54 | // for(auto &c :tmp ); 55 | // cout<s; 59 | // subsetsWithDup(v,0,s); 60 | 61 | // for(auto &x: mset){ 62 | // for(auto &p:x) 63 | // cout< 2 | using namespace std; 3 | 4 | void Merge(int a[],int s,int m,int e){ 5 | int n1=m-s+1; 6 | int n2=e-m; 7 | int l[n1],r[n2]; 8 | 9 | for(int i=0;i=r[j]) 19 | a[k++]=r[j++]; 20 | else 21 | a[k++]=l[i++]; 22 | // cout<=e) 40 | return ; 41 | int m=(s+e)/2; 42 | 43 | Mergesort(a,s,m); 44 | Mergesort(a,m+1,e); 45 | Merge(a,s,m,e); 46 | 47 | } 48 | int main(){ 49 | int n;cin>>n; 50 | int a[n]; 51 | for(int i=0;i>a[i]; 53 | 54 | Mergesort(a,0,n-1); 55 | 56 | for(int i=0;i 2 | using namespace std; 3 | 4 | int partition(int *a,int s,int e){ 5 | int pivot=a[e]; 6 | int pIndex=s; 7 | 8 | for(int i=s;i 17 | #include 18 | struct Element 19 | { 20 | int i; 21 | int j; 22 | int x; 23 | }; 24 | struct Sparse 25 | { 26 | int m; 27 | int n; 28 | int num; 29 | struct Element *ele; 30 | }; 31 | void create(struct Sparse *s) 32 | { 33 | printf("Enter the dimension\n"); 34 | scanf("%d%d",&s->m,&s->n); 35 | printf("Number of non-zero"); 36 | scanf("%d",&s->num); 37 | s->ele=(struct Element *)malloc(s->num*sizeof(struct Element)); 38 | printf("Enter all non zero elements\n"); 39 | for(int i=0;inum;i++) 40 | { 41 | scanf("%d%d%d",&s->ele[i].i,&s->ele[i].j,&s->ele[i].x); 42 | 43 | } 44 | } 45 | void display(struct Sparse s ) 46 | { 47 | 48 | int i,j,k=0; 49 | for(i=0;iele=(struct Element *)malloc((s1->num+s2->num)*sizeof(struct Element)); 67 | while(inum && jnum) 68 | { 69 | if(s1->ele[i].iele[j].i) 70 | sum->ele[k++]=s1->ele[i++]; 71 | else if(s1->ele[i].i>s2->ele[j].i) 72 | sum->ele[k++]=s2->ele[j++]; 73 | else 74 | { 75 | if(s1->ele[i].jele[j].j) 76 | sum->ele[k++]=s1->ele[i++]; 77 | else if(s1->ele[i].j>s2->ele[j].j) 78 | sum->ele[k++]=s2->ele[j++]; 79 | else 80 | { 81 | sum->ele[k]=s1->ele[i]; 82 | sum->ele[k++]=s1->ele[i++].x+s2->ele[j++].x; 83 | } 84 | } 85 | 86 | 87 | } 88 | for(;inum;i++) 89 | sum->ele[k++]=s1->ele[i]; 90 | for(;jnum;j++) 91 | sum->ele[k++]=s2->ele[j]; 92 | sum->m=s1->m; 93 | sum->n=s1->n; 94 | sum->num=k; 95 | return sum; 96 | }; 97 | int main() 98 | { 99 | struct Sparse s1,s2,*s3; 100 | create(&s1); 101 | create(&s2); 102 | s3=add(&s1,&s2); 103 | print("First Matrix\n"); 104 | 105 | display(s); 106 | return 0; 107 | } 108 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Stack: -------------------------------------------------------------------------------- 1 | Stack 2 | 3 | A real-world stack allows operations at one end only. For example, we can place or remove a card or plate from the top of the stack only. Likewise, Stack ADT allows 4 | all data operations at one end only. At any given time, we can only access the top element of a stack. 5 | 6 | This feature makes it LIFO data structure. LIFO stands for Last-in-first-out. Here, the element which is placed (inserted or added) last, is accessed first. In stack 7 | terminology, insertion operation is called PUSH operation and removal operation is called POP operation. 8 | 9 | Basic Operations 10 | 11 | push() − Pushing (storing) an element on the stack. 12 | pop() − Removing (accessing) an element from the stack. 13 | 14 | When data is Pushed onto stack. 15 | To use a stack efficiently, we need to check the status of stack as well. For the same purpose, the following functionality is added to stacks − 16 | peek() − get the top data element of the stack, without removing it. 17 | isFull() − check if stack is full. 18 | isEmpty() − check if stack is empty. 19 | 20 | Code for stack- 21 | 22 | #include 23 | #include 24 | struct stack 25 | { 26 | int size; 27 | int top; 28 | int *S; 29 | }; 30 | void create(struct stack *st) 31 | { 32 | printf("Enter size "); 33 | scanf("%d",&st->size); 34 | st->top=-1; 35 | st->S=(int *) malloc(st->size*sizeof(int)); 36 | 37 | 38 | } 39 | void display(struct stack st) 40 | { 41 | int i; 42 | for(i=st.top;i>=0;i--) 43 | { 44 | printf("%d\n",st.S[i]); 45 | } 46 | printf("\n"); 47 | } 48 | void push(struct stack *st,int x) 49 | { 50 | if(st->top==st->size-1) 51 | { 52 | printf("Stack overflow\n"); 53 | } 54 | else 55 | { 56 | st->top++; 57 | st->S[st->top]=x; 58 | } 59 | 60 | } 61 | int pop(struct stack *st) 62 | { 63 | int x=-1; 64 | if(st->top==-1) 65 | printf("Stack underflow\n"); 66 | else 67 | { 68 | x=st->S[st->top]; 69 | st->top--; 70 | } 71 | return x; 72 | 73 | } 74 | int peek(struct stack st,int index) 75 | { 76 | int x=-1; 77 | if(st.top-index+1<0) 78 | printf("Invalid index\n"); 79 | x=st.S[st.top-index+1]; 80 | return x; 81 | 82 | 83 | } 84 | int isEmpty(struct stack st) 85 | { 86 | if(st.top==-1) 87 | return 1; 88 | return 0; 89 | } 90 | int isFull(struct stack st) 91 | { 92 | return st.top==st.size-1; 93 | } 94 | int stackTop(struct stack st) 95 | { 96 | if(!isEmpty(st)) 97 | return st.S[st.top]; 98 | return -1; 99 | 100 | } 101 | int main() 102 | { 103 | struct stack st; 104 | create(&st); 105 | push(&st,10); 106 | push(&st,20); 107 | push(&st,30); 108 | push(&st,40); 109 | push(&st,50); 110 | printf("deleted element=%d\n",pop(&st)); 111 | printf("peek element=%d\n",peek(st,2)); 112 | printf("stacktop=%d\n",stackTop(st)); 113 | 114 | 115 | display(st); 116 | 117 | } 118 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/String Maching Algos/Knuth_Morris_Pratt.cpp.txt: -------------------------------------------------------------------------------- 1 | The time complexity of KMP algorithm is O(n) in the worst case. 2 | 3 | bool kmp(string pat, string s){ 4 | // make lps array for pattern 5 | int n = pat.size(), m = s.size(); 6 | vectorlps(n+1,0); 7 | int i=0,j; 8 | for(j=1;j 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | string s; cin >> s; 8 | int n =s.size(); 9 | int l=0,r=0; 10 | vector z(n,0); 11 | 12 | for(int i = 1;i < n; i++){ 13 | 14 | // case i is in range [l,r] 15 | 16 | if(i<=r) 17 | z[i] = min(z[i-l], r-i+1); 18 | 19 | while(z[i]+i < n && s[z[i]]==s[i + z[i]]) 20 | z[i]++; 21 | 22 | if(r < i+z[i]-1) 23 | l = i, r = i+z[i]-1; 24 | 25 | } 26 | 27 | for(auto x: z) 28 | cout< 3 | using namespace std; 4 | const int ALPHA_SIZE = 26; 5 | 6 | struct Trie { 7 | struct Trie *child[ALPHA_SIZE]; 8 | bool endofstring; //It is true if node represents end of word. 9 | }; 10 | struct Trie *createNode(void) //creation of new node { 11 | struct Trie *tNode = new Trie; 12 | tNode->endofstring = false; 13 | for (int i = 0; i < ALPHA_SIZE; i++) 14 | tNode->child[i] = NULL; 15 | return tNode; 16 | } 17 | void insert(struct Trie *root, string key) { 18 | struct Trie *curr = root; 19 | for (int i = 0; i < key.length(); i++) { 20 | int index = key[i] - 'A'; 21 | if (!curr->child[index]) 22 | curr->child[index] = createNode(); 23 | curr = curr->child[index]; 24 | } 25 | curr->endofstring= true; //last node as leaf 26 | } 27 | bool search(struct Trie *root, string key) { //check if key is present in trie. If present returns true 28 | struct Trie *curr = root; 29 | for (int i = 0; i < key.length(); i++) { 30 | int index = key[i] - 'A'; 31 | if (!curr->child[index]) 32 | return false; 33 | curr = curr->child[index]; 34 | } 35 | return (curr != NULL && curr->endofstring); 36 | } 37 | bool isEmpty(Trie* root) //check if root has children or not { 38 | for (int i = 0; i < ALPHA_SIZE; i++) 39 | if (root->child[i]) 40 | return false; 41 | return true; 42 | } 43 | Trie* deletion(Trie* root, string key, int depth = 0) { 44 | //If tree is empty return null. 45 | if (!root) 46 | return NULL; 47 | if (depth == key.size()) { //If last character of key is being processed, 48 | if (root->endofstring) 49 | root->endofstring = false; //then that node will be no more end of string after deleting it. 50 | if (isEmpty(root)) { //If given key is not prefix of any other string, 51 | delete (root); 52 | root = NULL; 53 | } 54 | return root; 55 | } 56 | //If key not last character, 57 | int index = key[depth] - 'A'; 58 | root->child[index] = 59 | deletion(root->child[index], key, depth + 1); //Then recur for the child which will be obtained by using ASCII value. 60 | if (isEmpty(root) && root->endofstring == false) { //If root does not have any child leftand it is not end of another word 61 | delete (root); 62 | root = NULL; 63 | } 64 | return root; 65 | } 66 | int main() { 67 | string inputs[] = {"HELLOWORLD","HI","BYE", "THE","THENA"}; // Input keys ( only A to Z in upper case) 68 | int n = sizeof(inputs)/sizeof(inputs[0]); 69 | struct Trie *root = createNode(); 70 | for (int i = 0; i < n; i++) 71 | insert(root, inputs[i]); 72 | search(root, "HELLOWORLD")? cout << "Key is Found 73 | " : 74 | cout << "Key is not Found 75 | "; 76 | search(root, "HE")? cout << "Key is Found 77 | " : 78 | cout << "Key is not Found 79 | "; 80 | deletion(root, "THEN")? cout << "Key is deleted 81 | " : 82 | cout << "Key is not Deleted 83 | "; 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Trie Data Structure/bhumithakur.md: -------------------------------------------------------------------------------- 1 | Name : Bhoomika singh 2 | email : bhumithakur1218@gmail.com 3 | 4 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Trie Data Structure/explanation of trie with pseudocode: -------------------------------------------------------------------------------- 1 | 2 | 1. It is also known as Prefix tree. 3 | 2.It's also a tree which stores a set of strings. 4 | 3.Each node of trie stores an info of char. 5 | 4. It's a tree such that every traversal from root to any of the leaf is going to represent onw of word from the set of words. 6 | 7 | 8 | 9 | 10 | Begin 11 | function insert() : 12 | If key not present, inserts key into trie. If the key is prefix of trie node, just mark leaf node. 13 | End 14 | Begin 15 | function deleteNode() 16 | If tree is empty then return null. 17 | If last character of the key is being processed, 18 | then that node will be no more end of string after deleting it. 19 | If given key is not prefix of any other string, then delete it and set root = NULL. 20 | If key is not the last character, 21 | Then recur for the child which will be obtained by using ASCII value. 22 | If root does not have any child left and it is not end of another word, 23 | Then delete it and set root = NULL. 24 | End 25 | 26 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/binary-search.md: -------------------------------------------------------------------------------- 1 | binary-search 2 | ============= 3 | 4 | This is a really tiny, stupid, simple binary search library for Node.JS. We wrote it because existing solutions were bloated and incorrect. This version is a straight port of the Java version mentioned by Joshua Bloch in his article, [Nearly All Binary Searches and Merge Sorts are Broken](http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html). 5 | 6 | You pass the function a sorted array, a value, and the sort comparator function. If the value is found in the array, it returns a nonnegative integer representing the index of the value in the array. (Note that if your array contains duplicates, the index within the run of duplicates is arbitrary.) If the value is _not_ in the array, then `-(index + 1)` is returned, where `index` is where the value should be inserted into the array to maintain sorted order. 7 | 8 | You may also pass the search function optional fourth and fifth arguments, representing the minimum and maximum indices of the array to search, in case you wish to limit the section of the array searched. (These default, of course, to `0` and `length-1`, respectively.) 9 | 10 | The sort comparator function should be the same one you use to sort your array. It accepts optional third and fourth arguments, the current index and the overall array: these should not be necessary except in highly unusual circumstances. 11 | 12 | Thanks to [Conrad Irwin](https://github.com/ConradIrwin) and [Michael Marino](https://github.com/mgmarino) for, ironically, pointing out bugs. 13 | 14 | Example 15 | ------- 16 | 17 | ```js 18 | var bs = require("binary-search"); 19 | 20 | bs([1, 2, 3, 4], 3, function(element, needle) { return element - needle; }); 21 | // => 2 22 | 23 | bs([1, 2, 4, 5], 3, function(element, needle) { return element - needle; }); 24 | // => -3 25 | ``` 26 | 27 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/two_pointer_technique.md: -------------------------------------------------------------------------------- 1 | // C++ Program Illustrating Naive Approach to 2 | // Find if There is a Pair in A[0..N-1] with Given Sum 3 | // Using Two-pointers Technique 4 | 5 | // Importing required libraries 6 | #include 7 | 8 | using namespace std; 9 | 10 | // Two pointer technique based solution to find 11 | // if there is a pair in A[0..N-1] with a given sum. 12 | int isPairSum(int A[], int N, int X) 13 | { 14 | // represents first pointer 15 | int i = 0; 16 | 17 | // represents second pointer 18 | int j = N - 1; 19 | 20 | while (i < j) { 21 | 22 | // If we find a pair 23 | if (A[i] + A[j] == X) 24 | return 1; 25 | 26 | // If sum of elements at current 27 | // pointers is less, we move towards 28 | // higher values by doing i++ 29 | else if (A[i] + A[j] < X) 30 | i++; 31 | 32 | // If sum of elements at current 33 | // pointers is more, we move towards 34 | // lower values by doing j-- 35 | else 36 | j--; 37 | } 38 | return 0; 39 | } 40 | 41 | // Driver code 42 | int main() 43 | { 44 | // array declaration 45 | int arr[] = { 2, 3, 5, 8, 9, 10, 11 }; 46 | 47 | // value to search 48 | int val = 17; 49 | 50 | // size of the array 51 | int arrSize = *(&arr + 1) - arr; 52 | 53 | // array should be sorted before using two-pointer technique 54 | sort(arr, arr+7); 55 | 56 | // Function call 57 | if((bool)isPairSum(arr, arrSize, val)==1) 58 | { 59 | cout<<"Valid Pair present"; 60 | } 61 | else 62 | { 63 | cout<<"No Valid Pair found"; 64 | } 65 | 66 | return 0; 67 | } -------------------------------------------------------------------------------- /DevOps/CircleCI.md: -------------------------------------------------------------------------------- 1 | 2 | ## CircleCI ## 3 | 4 | CircleCI is the continuous integration & delivery platform that helps the development teams to release code rapidly and automate the build, test, and deploy. 5 | CircleCI can be configured to run very complex pipelines efficiently with caching, docker layer caching, resource classes and many more. 6 | After repositories on GitHub or Bitbucket are authorized and added as a project to circleci.com, every code triggers CircleCI runs jobs. 7 | CircleCI also sends an email notification of success or failure after the tests complete. 8 | 9 | CircleCI is used for building, testing, and deploying a project, by using automation. 10 | This automation takes place in pipelines with jobs. 11 | 12 | 13 | These jobs include: 14 | 15 | A pipeline is a set of instructions or steps that our CI tool will execute each time our code is updated. 16 | Jobs are a set of specific tasks for the building, testing and deploying stages. Each job is executed in a separate container or virtual machine. 17 | 18 | 19 | As a developer using CircleCI you can: 20 | 21 | SSH into any job to debug your build issues. 22 | Set up parallelism in your .circleci/config.yml file to run jobs faster. 23 | Configure caching with two simple keys to reuse data from previous jobs in your workflow. 24 | Configure self-hosted runners for unique platform support. 25 | Access Arm resources for the machine executor. 26 | Use orbs, reusable packages of configuration, to integrate with third parties. 27 | Use pre-built Docker images in a variety of languages. 28 | Use the API 29 | to retrieve information about jobs and workflows. 30 | Use the CLI to access advanced tools locally. 31 | Get flaky test detection with test insights. 32 | -------------------------------------------------------------------------------- /Euclid_algo/gcd.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to demonstrate 2 | // Basic Euclidean Algorithm 3 | 4 | #include 5 | using namespace std; 6 | 7 | // Function to return 8 | // gcd of a and b 9 | int gcd(int a, int b) 10 | { 11 | if (a == 0) 12 | return b; 13 | return gcd(b % a, a); 14 | } 15 | 16 | // Driver Code 17 | int main() 18 | { 19 | int a = 10, b = 15; 20 | 21 | // Function call 22 | cout << "GCD(" << a << ", " << b << ") = " << gcd(a, b) 23 | << endl; 24 | a = 35, b = 10; 25 | cout << "GCD(" << a << ", " << b << ") = " << gcd(a, b) 26 | << endl; 27 | a = 31, b = 2; 28 | cout << "GCD(" << a << ", " << b << ") = " << gcd(a, b) 29 | << endl; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Euler Totient/code.cpp: -------------------------------------------------------------------------------- 1 | // A simple C++ program to calculate 2 | // Euler's Totient Function 3 | #include 4 | using namespace std; 5 | 6 | // Function to return gcd of a and b 7 | int gcd(int a, int b) 8 | { 9 | if (a == 0) 10 | return b; 11 | return gcd(b % a, a); 12 | } 13 | 14 | // A simple method to evaluate Euler Totient Function 15 | int phi(unsigned int n) 16 | { 17 | unsigned int result = 1; 18 | for (int i = 2; i < n; i++) 19 | if (gcd(i, n) == 1) 20 | result++; 21 | return result; 22 | } 23 | 24 | // Driver program to test above function 25 | int main() 26 | { 27 | int n; 28 | for (n = 1; n <= 10; n++) 29 | cout << "phi("< { 26 | console.log(name); 27 | } 28 | ``` 29 | 30 | ## Arrow function hacks:- 31 | 32 | When having no arguments, you have to use empty parentheses in the function declaration:- 33 | 34 | ``` 35 | const callMe = () => { 36 | console.log('Max!'); 37 | } 38 | ``` 39 | 40 | When having exactly one argument, you may omit the parentheses: 41 | 42 | ``` 43 | const callMe = name => { 44 | console.log(name); 45 | } 46 | ``` 47 | 48 | When just returning a value, you can use the following 49 | shortcut: 50 | 51 | ``` 52 | const returnMe = name => nam 53 | ``` 54 | 55 | That's equal to: 56 | 57 | ``` 58 | const returnMe = name => { 59 | return name; 60 | } 61 | ``` 62 | 63 | -------------------------------------------------------------------------------- /Javascript for react/2. Import export.md: -------------------------------------------------------------------------------- 1 | In React projects (and actually in all modern JavaScript projects), you split your code across multiple JavaScript files - so-called modules. You do this, to keep each file/module focused and manageable. 2 | 3 | To still access functionality in another file, you need export 4 | (to make it available) and import (to get 5 | access) statements. 6 | 7 | You got two different types of 8 | exports: default (unnamed) and namedexports: 9 | 10 | 11 | ``` 12 | default => export default ...; 13 | 14 | named => export const someData = ...; 15 | ``` 16 | 17 | You can import default exports like this:import someNameOfYourChoice from './path/to/file.js'; 18 | 19 | Surprisingly, someNameOfYourChoice is totally up to you.Named exports have to be imported by their name: 20 | ``` 21 | import { someData } from './path/to/file.js'; 22 | ``` 23 | 24 | A file can only contain one default and an unlimited amount of named exports. You can also mix the one default with any amount of named exports in one and the same file.When importing named exports, you can also import all named exports at once with the following syntax: 25 | 26 | ``` 27 | import * as upToYou from './path/to/file.js'; 28 | ``` 29 | 30 | 31 | upToYou is - well - up to you and simply bundles all exported variables/functions in one JavaScript object. For example, if you export const someData = ... (/path/to/file.js ) you can access it on upToYou like 32 | this: upToYou.someData 33 | 34 | 35 | -------------------------------------------------------------------------------- /Javascript for react/3. Classes.md: -------------------------------------------------------------------------------- 1 | Classes are a feature which basically replace constructor functions and prototypes. You can define blueprints for JavaScript objects with them. 2 | 3 | ## Defining classes :- 4 | 5 | ``` 6 | class Person { 7 | constructor () { 8 | this.name = 'Max'; 9 | } 10 | } 11 | 12 | const person = new Person(); 13 | console.log(person.name); // prints 'Max' 14 | ``` 15 | 16 | In the above example, not only the class but also a property of that class (=> name ) is defined. 17 | 18 | ## Defining methods :- 19 | 20 | ``` 21 | class Person { 22 | name = 'Max'; 23 | printMyName () { 24 | console.log(this.name); // this is required to refer 25 | to the class! 26 | } 27 | } 28 | 29 | const person = new Person(); 30 | person.printMyName() 31 | ``` 32 | 33 | ## inheritance when using classes: 34 | 35 | ``` 36 | class Human { 37 | species = 'human'; 38 | } 39 | 40 | class Person extends Human { 41 | name = 'Max'; 42 | printMyName = () => { 43 | console.log(this.name); 44 | } 45 | } 46 | 47 | const person = new Person(); 48 | person.printMyName(); 49 | console.log(person.species); // prints 'human' 50 | ``` -------------------------------------------------------------------------------- /Javascript for react/4. Spread and rest operator.md: -------------------------------------------------------------------------------- 1 | The spread and rest operators actually use the same syntax: ... 2 | 3 | Yes, that is the operator - just three dots. It's usage determines whether you're using it as the spread or rest operator. 4 | 5 | ## Using the Spread Operator on array: 6 | 7 | The spread operator allows you to pull elements out of an array (=> split the array into a list of its elements) or pull the properties out of an object. Here are two examples: 8 | 9 | 10 | ``` 11 | const oldArray = [1, 2, 3]; 12 | const newArray = [...oldArray, 4, 5]; // This now is [1, 2, 13 | 3, 4, 5] 14 | ``` 15 | 16 | ## Using the Spread Operator on object: 17 | 18 | ``` 19 | const oldObject = { 20 | name: 'Max' 21 | }; 22 | const newObject = { 23 | ...oldObject, 24 | age: 28 25 | }; 26 | ``` 27 | 28 | newObject would then be 29 | 30 | ``` 31 | { 32 | name: 'Max', 33 | age: 28 34 | } 35 | ``` -------------------------------------------------------------------------------- /Javascript for react/5. Destructuring.md: -------------------------------------------------------------------------------- 1 | Destructuring allows you to easily access the values of arrays or objects and assign them to variables. 2 | 3 | ## Here's an example for an array: 4 | 5 | 6 | ``` 7 | const array = [1, 2, 3]; 8 | const [a, b] = array; 9 | console.log(a); // prints 1 10 | console.log(b); // prints 2 11 | console.log(array); // prints [1, 2, 3] 12 | ``` 13 | 14 | ## Here's an example for an object: 15 | 16 | ``` 17 | const myObj = { 18 | name: 'Max', 19 | age: 28 20 | } 21 | const {name} = myObj; 22 | console.log(name); // prints 'Max' 23 | console.log(age); // prints undefined 24 | console.log(myObj); // prints {name: 'Max', age: 28} 25 | ``` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Vikash Patel 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 | -------------------------------------------------------------------------------- /Operating System/Scheduling Algorithm (SJF).md: -------------------------------------------------------------------------------- 1 | # Scheduling Algorithm 2 | 3 | There are various algorithms which are used by the Operating System to schedule the processes on the processor in an efficient way. 4 | 5 | # The Purpose of a Scheduling algorithm 6 | 7 | - Maximum CPU utilization 8 | - Fare allocation of CPU 9 | - Maximum throughput 10 | - Minimum turnaround time 11 | - Minimum waiting time 12 | - Minimum response time 13 | 14 | Here we will talk about Shortest Job First Scheduling Algorithm. 15 | 16 | # Shortest Job First 17 | 18 | The job with the shortest burst time will get the CPU first. The lesser the burst time, 19 | the sooner will the process get the CPU. It is the non-preemptive type of scheduling. 20 | 21 | # Algorithm: 22 | 23 | - Sort all the processes according to the arrival time. 24 | - Then select that process that has minimum arrival time and minimum Burst time. 25 | - After completion of the process make a pool of processes that arrives afterward 26 | till the completion of the previous process and select that process among the pool 27 | which is having minimum Burst time. 28 | 29 | ![Alt text](https://media.geeksforgeeks.org/wp-content/cdn-uploads/20200303163658/SJF.jpg) 30 | 31 | # Implementation in CPP 32 | 33 | ```cpp 34 | #include 35 | using namespace std; 36 | 37 | void merge(int a[], int left[], int leftCount, int right[], int rightCount) 38 | { 39 | int i = 0, j = 0, k = 0; 40 | 41 | while (i < leftCount && j < rightCount) 42 | { 43 | if (left[i] < right[j]) 44 | a[k++] = left[i++]; 45 | else 46 | a[k++] = right[j++]; 47 | } 48 | 49 | while (i < leftCount) 50 | a[k++] = left[i++]; 51 | while (j < rightCount) 52 | a[k++] = right[j++]; 53 | 54 | } 55 | 56 | void mergeSort(int a[], int n) 57 | { 58 | 59 | int middle = n / 2; 60 | int *left, *right; 61 | if (n < 2) 62 | return; 63 | left = new int[middle]; 64 | right = new int[n - middle]; 65 | for (int i = 0; i < middle; i++) 66 | left[i] = a[i]; 67 | for (int i = middle; i < n; i++) 68 | right[i - middle] = a[i]; 69 | mergeSort(left, middle); 70 | mergeSort(right, n - middle); 71 | merge(a, left, middle, right, n - middle); 72 | delete left; 73 | delete right; 74 | 75 | } 76 | 77 | int main(int argc, char const \*argv[]) 78 | { 79 | 80 | ios_base::sync_with_stdio(false); 81 | int n; 82 | cout << "Enter the number of processes"; 83 | cin >> n; 84 | int bt[n], wt[n] = {0}, tat[n], total = 0; 85 | float avg_wt, avg_tat; 86 | for (int i = 0; i < n; i++) 87 | { 88 | cout << "Enter the burst time for process " << i + 1 << ":"; 89 | cin >> bt[i]; 90 | } 91 | mergeSort(bt, n); 92 | for (int i = 1; i < n; i++) 93 | { 94 | for (int j = 0; j < i; j++) 95 | { 96 | wt[i] += bt[j]; 97 | } 98 | total += wt[i]; 99 | } 100 | avg_wt = (float)total / n; 101 | total = 0; 102 | for (int i = 0; i < n; i++) 103 | { 104 | tat[i] = wt[i] + bt[i]; 105 | total += tat[i]; 106 | } 107 | avg_tat = (float)total / n; 108 | cout << "Average waiting time is " << avg_wt << "\n"; 109 | cout << "Average turnaround time is " << avg_tat << "\n"; 110 | return 0; 111 | 112 | } 113 | ``` 114 | -------------------------------------------------------------------------------- /Operating System/backbone_os.md: -------------------------------------------------------------------------------- 1 | ## Chapter 4: Backbone of the OS and C++ runtime 2 | 3 | #### C++ kernel run-time 4 | 5 | A kernel can be written in C++ just as it can be in C, with the exception of a few pitfalls that come with using C++ (runtime support, constructors, etc). 6 | 7 | The compiler will assume that all the necessary C++ runtime support is available by default, but as we are not linking libsupc++ into your C++ kernel, we need to add some basic functions that can be found in the [cxx.cc](https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System/blob/master/src/kernel/runtime/cxx.cc) file. 8 | 9 | **Caution:** The operators `new` and `delete` cannot be used before virtual memory and pagination have been initialized. 10 | 11 | #### Basic C/C++ functions 12 | 13 | The kernel code can't use functions from the standard libraries so we need to add some basic functions for managing memory and strings: 14 | 15 | ```cpp 16 | void itoa(char *buf, unsigned long int n, int base); 17 | 18 | void * memset(char *dst,char src, int n); 19 | void * memcpy(char *dst, char *src, int n); 20 | 21 | int strlen(char *s); 22 | int strcmp(const char *dst, char *src); 23 | int strcpy(char *dst,const char *src); 24 | void strcat(void *dest,const void *src); 25 | char * strncpy(char *destString, const char *sourceString,int maxLength); 26 | int strncmp( const char* s1, const char* s2, int c ); 27 | ``` 28 | 29 | These functions are defined in [string.cc](https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System/blob/master/src/kernel/runtime/string.cc), [memory.cc](https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System/blob/master/src/kernel/runtime/memory.cc), [itoa.cc](https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System/blob/master/src/kernel/runtime/itoa.cc) 30 | 31 | #### C types 32 | 33 | In the next step, we're going to define different types we're going to use in our code. Most of our variable types are going to be unsigned. This means that all the bits are used to store the integer. Signed variables use their first bit to indicate their sign. 34 | 35 | ```cpp 36 | typedef unsigned char u8; 37 | typedef unsigned short u16; 38 | typedef unsigned int u32; 39 | typedef unsigned long long u64; 40 | 41 | typedef signed char s8; 42 | typedef signed short s16; 43 | typedef signed int s32; 44 | typedef signed long long s64; 45 | ``` 46 | 47 | #### Compile our kernel 48 | 49 | Compiling a kernel is not the same thing as compiling a linux executable, we can't use a standard library and should have no dependencies to the system. 50 | 51 | Our [Makefile](https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System/blob/master/src/kernel/Makefile) will define the process to compile and link our kernel. 52 | 53 | For x86 architecture, the followings arguments will be used for gcc/g++/ld: 54 | 55 | ``` 56 | # Linker 57 | LD=ld 58 | LDFLAG= -melf_i386 -static -L ./ -T ./arch/$(ARCH)/linker.ld 59 | 60 | # C++ compiler 61 | SC=g++ 62 | FLAG= $(INCDIR) -g -O2 -w -trigraphs -fno-builtin -fno-exceptions -fno-stack-protector -O0 -m32 -fno-rtti -nostdlib -nodefaultlibs 63 | 64 | # Assembly compiler 65 | ASM=nasm 66 | ASMFLAG=-f elf -o 67 | ``` 68 | -------------------------------------------------------------------------------- /Operating System/memory_management.md: -------------------------------------------------------------------------------- 1 | # Memory management: physical and virtual 2 | 3 | The kernel knows the size of the physical memory available thanks to [GRUB](../Chapter-3/README.md). 4 | 5 | In our implementation, the first 8 megabytes of physical memory will be reserved for use by the kernel and will contain: 6 | 7 | - The kernel 8 | - GDT, IDT et TSS 9 | - Kernel Stack 10 | - Some space reserved to hardware (video memory, ...) 11 | - Page directory and pages table for the kernel 12 | 13 | The rest of the physical memory is freely available to the kernel and applications. 14 | 15 | ![Physical Memory](physicalmemory.png) 16 | 17 | 18 | ### Virtual Memory Mapping 19 | 20 | The address space between the beginning of memory and `0x40000000` address is the kernel space, while the space between the address `0x40000000` and the end of the memory corresponds to user space: 21 | 22 | ![Virtual Memory](virtualmemory.png) 23 | 24 | The kernel space in virtual memory, which is using 1Gb of virtual memory, is common to all tasks (kernel and user). 25 | 26 | This is implemented by pointing the first 256 entries of the task page directory to the kernel page directory (In [vmm.cc](https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System/blob/master/src/kernel/arch/x86/vmm.cc#L204)): 27 | 28 | ```cpp 29 | /* 30 | * Kernel Space. v_addr < USER_OFFSET are addressed by the kernel pages table 31 | */ 32 | for (i=0; i<256; i++) 33 | pdir[i] = pd0[i]; 34 | ``` 35 | -------------------------------------------------------------------------------- /Operating System/virtual_os.md: -------------------------------------------------------------------------------- 1 | ## Chapter 2: Setup the development environment 2 | 3 | The first step is to setup a good and viable development environment. Using Vagrant and Virtualbox, you'll be able to compile and test your OS from all the OSs (Linux, Windows or Mac). 4 | 5 | ### Install Vagrant 6 | 7 | > Vagrant is free and open-source software for creating and configuring virtual development environments. It can be considered a wrapper around VirtualBox. 8 | 9 | Vagrant will help us create a clean virtual development environment on whatever system you are using. 10 | The first step is to download and install Vagrant for your system at http://www.vagrantup.com/. 11 | 12 | ### Install Virtualbox 13 | 14 | > Oracle VM VirtualBox is a virtualization software package for x86 and AMD64/Intel64-based computers. 15 | 16 | Vagrant needs Virtualbox to work, Download and install for your system at https://www.virtualbox.org/wiki/Downloads. 17 | 18 | ### Start and test your development environment 19 | 20 | Once Vagrant and Virtualbox are installed, you need to download the ubuntu lucid32 image for Vagrant: 21 | 22 | ``` 23 | vagrant box add lucid32 http://files.vagrantup.com/lucid32.box 24 | ``` 25 | 26 | Once the lucid32 image is ready, we need to define our development environment using a *Vagrantfile*, [create a file named *Vagrantfile*](https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System/blob/master/src/Vagrantfile). This file defines what prerequisites our environment needs: nasm, make, build-essential, grub and qemu. 27 | 28 | Start your box using: 29 | 30 | ``` 31 | vagrant up 32 | ``` 33 | 34 | You can now access your box by using ssh to connect to the virtual box using: 35 | 36 | ``` 37 | vagrant ssh 38 | ``` 39 | 40 | The directory containing the *Vagrantfile* will be mounted by default in the */vagrant* directory of the guest VM (in this case, Ubuntu Lucid32): 41 | 42 | ``` 43 | cd /vagrant 44 | ``` 45 | 46 | #### Build and test our operating system 47 | 48 | The file [**Makefile**](https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System/blob/master/src/Makefile) defines some basics rules for building the kernel, the user libc and some userland programs. 49 | 50 | Build: 51 | 52 | ``` 53 | make all 54 | ``` 55 | 56 | Test our operating system with qemu: 57 | 58 | ``` 59 | make run 60 | ``` 61 | 62 | The documentation for qemu is available at [QEMU Emulator Documentation](http://wiki.qemu.org/download/qemu-doc.html). 63 | 64 | You can exit the emulator using: Ctrl-a. 65 | -------------------------------------------------------------------------------- /Operating System/x86_os.md: -------------------------------------------------------------------------------- 1 | ## Chapter 1: Introduction to the x86 architecture and about our OS 2 | 3 | ### What is the x86 architecture? 4 | 5 | > The term x86 denotes a family of backward compatible instruction set architectures based on the Intel 8086 CPU. 6 | 7 | The x86 architecture is the most common instruction set architecture since its introduction in 1981 for the IBM PC. A large amount of software, including operating systems (OS's) such as DOS, Windows, Linux, BSD, Solaris and Mac OS X, function with x86-based hardware. 8 | 9 | In this course we are not going to design an operating system for the x86-64 architecture but for x86-32, thanks to backward compatibility, our OS will be compatible with our newer PCs (but take caution if you want to test it on your real machine). 10 | 11 | ### Our Operating System 12 | 13 | The goal is to build a very simple UNIX-based operating system in C++, but the goal is not to just build a "proof-of-concept". The OS should be able to boot, start a userland shell and be extensible. 14 | 15 | The OS will be built for the x86 architecture, running on 32 bits, and compatible with IBM PCs. 16 | 17 | **Specifications:** 18 | 19 | * Code in C++ 20 | * x86, 32 bit architecture 21 | * Boot with Grub 22 | * Kind of modular system for drivers 23 | * Kind of UNIX style 24 | * Multitasking 25 | * ELF executable in userland 26 | * Modules (accessible in userland using /dev/...) : 27 | * IDE disks 28 | * DOS partitions 29 | * Clock 30 | * EXT2 (read only) 31 | * Boch VBE 32 | * Userland : 33 | * API Posix 34 | * LibC 35 | * "Can" run a shell or some executables (e.g., lua) 36 | -------------------------------------------------------------------------------- /Programming Languages/introduction.md: -------------------------------------------------------------------------------- 1 | ## What is a Programming Language 2 | A programming language is a set of instructions that can be used to interact with and control a computer. These languages are used to design websites, create apps, develop operating systems, control spacecraft, and analyze data. Programming languages are necessary because computers can't understand Engish. Programming languages bridge this gap by helping programmers translate their commands into something that the computer can understand and execute. 3 | 4 | ## Computer languages vs programming languages 5 | The term computer language is sometimes used interchangeably with programming language. However, the usage of both terms varies among authors, including the exact scope of each. One usage describes programming languages as a subset of computer languages. Similarly, languages used in computing that have a different goal than expressing computer programs are generically designated computer languages. For instance, markup languages are sometimes referred to as computer languages to emphasize that they are not meant to be used for programming. One way of classifying computer languages is by the computations they are capable of expressing, as described by the theory of computation. The majority of practical programming languages are Turing complete, and all Turing complete languages can implement the same set of algorithms. ANSI/ISO SQL-92 and Charity are examples of languages that are not Turing complete, yet are often called programming languages. However, some authors restrict the term "programming language" to Turing complete languages -------------------------------------------------------------------------------- /Python/[feature] PasswordManager: -------------------------------------------------------------------------------- 1 | import argparse 2 | from getpass import getpass 3 | import hashlib 4 | import pyperclip 5 | 6 | from rich import print as printc 7 | 8 | import utils.add 9 | import utils.retrieve 10 | import utils.generate 11 | from utils.dbconfig import dbconfig 12 | 13 | parser = argparse.ArgumentParser(description='Description') 14 | 15 | parser.add_argument('option', help='(a)dd / (e)xtract / (g)enerate') 16 | parser.add_argument("-s", "--name", help="Site name") 17 | parser.add_argument("-u", "--url", help="Site URL") 18 | parser.add_argument("-e", "--email", help="Email") 19 | parser.add_argument("-l", "--login", help="Username") 20 | parser.add_argument("--length", help="Length of the password to generate",type=int) 21 | parser.add_argument("-c", "--copy", action='store_true', help='Copy password to clipboard') 22 | 23 | 24 | args = parser.parse_args() 25 | 26 | 27 | def inputAndValidateMasterPassword(): 28 | mp = getpass("MASTER PASSWORD: ") 29 | hashed_mp = hashlib.sha256(mp.encode()).hexdigest() 30 | 31 | db = dbconfig() 32 | cursor = db.cursor() 33 | query = "SELECT * FROM pm.secrets" 34 | cursor.execute(query) 35 | result = cursor.fetchall()[0] 36 | if hashed_mp != result[0]: 37 | printc("[red][!] WRONG! [/red]") 38 | return None 39 | 40 | return [mp,result[1]] 41 | 42 | 43 | def main(): 44 | if args.option in ["add","a"]: 45 | if args.name == None or args.url == None or args.login == None: 46 | if args.name == None: 47 | printc("[red][!][/red] Site Name (-s) required ") 48 | if args.url == None: 49 | printc("[red][!][/red] Site URL (-u) required ") 50 | if args.login == None: 51 | printc("[red][!][/red] Site Login (-l) required ") 52 | return 53 | 54 | if args.email == None: 55 | args.email = "" 56 | 57 | res = inputAndValidateMasterPassword() 58 | if res is not None: 59 | utils.add.addEntry(res[0],res[1],args.name,args.url,args.email,args.login) 60 | 61 | 62 | if args.option in ["extract","e"]: 63 | # if args.name == None and args.url == None and args.email == None and args.login == None: 64 | # # retrieve all 65 | # printc("[red][!][/red] Please enter at least one search field (sitename/url/email/username)") 66 | # return 67 | res = inputAndValidateMasterPassword() 68 | 69 | search = {} 70 | if args.name is not None: 71 | search["sitename"] = args.name 72 | if args.url is not None: 73 | search["siteurl"] = args.url 74 | if args.email is not None: 75 | search["email"] = args.email 76 | if args.login is not None: 77 | search["username"] = args.login 78 | 79 | if res is not None: 80 | utils.retrieve.retrieveEntries(res[0],res[1],search,decryptPassword = args.copy) 81 | 82 | 83 | if args.option in ["generate","g"]: 84 | if args.length == None: 85 | printc("[red][+][/red] Specify length of the password to generate (--length)") 86 | return 87 | password = utils.generate.generatePassword(args.length) 88 | pyperclip.copy(password) 89 | printc("[green][+][/green] Password generated and copied to clipboard") 90 | 91 | 92 | 93 | main() 94 | -------------------------------------------------------------------------------- /Python/contact_list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import tkinter as tk 4 | from tkinter import ttk 5 | 6 | class AddressBookApp(tk.Frame): 7 | def __init__(self, master=None): 8 | super().__init__(master) 9 | self.master.title('Address Book') 10 | self.pack() 11 | self._create_widgets() 12 | 13 | def _create_widgets(self): 14 | tree_view_entries = ["Entry 1", "Entry 2", 15 | "Entry 3", "Entry 4"] 16 | treeview_widget = ttk.Treeview(self.master) 17 | index = 1 18 | for entry in tree_view_entries: 19 | treeview_widget.insert('', 'end', index, text = entry) 20 | index += 1 21 | treeview_widget.pack() 22 | self._create_menus() 23 | 24 | 25 | def _create_menus(self): 26 | menu_widget = tk.Menu(self.master) 27 | file_menu = tk.Menu(menu_widget) 28 | contact_menu = tk.Menu(menu_widget) 29 | file_menu.add_command(label="New", command=self._new_addressbook) 30 | file_menu.add_command(label="Open...", command=self._open_addressbook) 31 | file_menu.add_separator() 32 | file_menu.add_command(label="Exit", command=root.quit) 33 | contact_menu.add_command(label="Add Contact", command=self._add_contact) 34 | 35 | contact_menu.add_command(label="Remove Contact", command=self._remove_contact) 36 | menu_widget.add_cascade(label="File", menu=file_menu) 37 | menu_widget.add_cascade(label="Contact", menu=contact_menu) 38 | 39 | self.master.config(menu=menu_widget) 40 | 41 | def _new_addressbook(self): 42 | pass 43 | 44 | def _open_addressbook(self): 45 | pass 46 | 47 | def _add_contact(self): 48 | pass 49 | 50 | def _remove_contact(self): 51 | pass 52 | 53 | 54 | # Main entry point 55 | root = tk.Tk() 56 | app = AddressBookApp(master=root) 57 | app.mainloop() 58 | -------------------------------------------------------------------------------- /Python/email_slicer.py: -------------------------------------------------------------------------------- 1 | email = input("Enter Your Email: ").strip() 2 | username = email[:email.index("@")] 3 | domain_name = email[email.index("@")+1:] 4 | format_ = (f"Your user name is '{username}' and your domain is '{domain_name}'") 5 | print(format_) 6 | -------------------------------------------------------------------------------- /Python/img_to_sketch.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | image = cv2.imread('Image.jpg') # loads an image from the specified file 3 | # convert an image from one color space to another 4 | grey_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 5 | invert = cv2.bitwise_not(grey_img) # helps in masking of the image 6 | # sharp edges in images are smoothed while minimizing too much blurring 7 | blur = cv2.GaussianBlur(invert, (21, 21), 0) 8 | invertedblur = cv2.bitwise_not(blur) 9 | sketch = cv2.divide(grey_img, invertedblur, scale=256.0) 10 | cv2.imwrite("sketch.png", sketch) # converted image is saved as mentioned name 11 | -------------------------------------------------------------------------------- /Python/person_correlation.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | movies = pd.read_csv("MoviesOnStreamingPlatforms_updated.csv") 3 | movies['Rotten Tomatoes'] = movies["Rotten Tomatoes"].str.replace("%", "").astype(float) 4 | movies.drop("Type", inplace=True, axis=1) 5 | correlations = movies.corr(method='pearson') 6 | # Correlation Between All The Features 7 | print(correlations) 8 | 9 | # Correlation Between A Particular column "Year" 10 | print(correlations["Year"]) 11 | 12 | # Visualizing Correlation 13 | import seaborn as sns 14 | 15 | import matplotlib.pyplot as plt 16 | sns.heatmap(correlations) 17 | plt.show() 18 | -------------------------------------------------------------------------------- /Python/qr_generator.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import messagebox 3 | import pyqrcode 4 | 5 | ws = Tk() 6 | ws.title("QR CODE GENERATOR") 7 | ws.config(bg = '#D2F2F2') 8 | 9 | def generate_QR(): 10 | if len(user_input.get()) != 0: 11 | global qr, img 12 | qr = pyqrcode.create(user_input.get()) 13 | img = BitmapImage(data = qr.xbm(scale = 10)) 14 | else: 15 | messagebox.showwarning('warning', 'All Fields are Required!') 16 | try: 17 | display_code() 18 | except: 19 | pass 20 | 21 | def display_code(): 22 | img_lbl.config(image = img) 23 | output.config(text = "SUCCESSFULLY GENERATED the QR code of: " + user_input.get()) 24 | 25 | 26 | lbl = Label( 27 | ws, 28 | text = "Enter Any String To generate Unique QR: ", 29 | bg = '#D2F2F2' 30 | ) 31 | lbl.pack() 32 | 33 | user_input = StringVar() 34 | entry = Entry( 35 | ws, 36 | textvariable = user_input 37 | ) 38 | entry.pack(padx=20) 39 | 40 | button = Button( 41 | ws, 42 | text = "CLICK TO GENERATE", 43 | width = 25, 44 | command = generate_QR 45 | ) 46 | button.pack(pady = 30) 47 | 48 | img_lbl = Label( 49 | ws, 50 | bg = '#D2F2F2') 51 | img_lbl.pack() 52 | output = Label( 53 | ws, 54 | text = "", 55 | bg = '#D2F2F2' 56 | ) 57 | output.pack() 58 | 59 | ws.mainloop() 60 | -------------------------------------------------------------------------------- /Python/rock_pape_scissors.py: -------------------------------------------------------------------------------- 1 | # import random module 2 | import random 3 | 4 | # Print multiline instruction 5 | # performstring concatenation of string 6 | print("Winning Rules of the Rock paper scissor game as follows: \n" 7 | +"Rock vs paper->paper wins \n" 8 | + "Rock vs scissor->Rock wins \n" 9 | +"paper vs scissor->scissor wins \n") 10 | 11 | while True: 12 | print("Enter choice \n 1 for Rock, \n 2 for paper, and \n 3 for scissor \n") 13 | 14 | # take the input from user 15 | choice = int(input("User turn: ")) 16 | 17 | # OR is the short-circuit operator 18 | # if any one of the condition is true 19 | # then it return True value 20 | 21 | # looping until user enter invalid input 22 | while choice > 3 or choice < 1: 23 | choice = int(input("enter valid input: ")) 24 | 25 | 26 | # initialize value of choice_name variable 27 | # corresponding to the choice value 28 | if choice == 1: 29 | choice_name = 'Rock' 30 | elif choice == 2: 31 | choice_name = 'paper' 32 | else: 33 | choice_name = 'scissor' 34 | 35 | # print user choice 36 | print("user choice is: " + choice_name) 37 | print("\nNow its computer turn.......") 38 | 39 | # Computer chooses randomly any number 40 | # among 1 , 2 and 3. Using randint method 41 | # of random module 42 | comp_choice = random.randint(1, 3) 43 | 44 | # looping until comp_choice value 45 | # is equal to the choice value 46 | while comp_choice == choice: 47 | comp_choice = random.randint(1, 3) 48 | 49 | # initialize value of comp_choice_name 50 | # variable corresponding to the choice value 51 | if comp_choice == 1: 52 | comp_choice_name = 'Rock' 53 | elif comp_choice == 2: 54 | comp_choice_name = 'paper' 55 | else: 56 | comp_choice_name = 'scissor' 57 | 58 | print("Computer choice is: " + comp_choice_name) 59 | 60 | print(choice_name + " V/s " + comp_choice_name) 61 | #we need to check of a draw 62 | if choice == comp_choice: 63 | print("Draw=> ", end = "") 64 | result = Draw 65 | 66 | # condition for winning 67 | if((choice == 1 and comp_choice == 2) or 68 | (choice == 2 and comp_choice ==1 )): 69 | print("paper wins => ", end = "") 70 | result = "paper" 71 | 72 | elif((choice == 1 and comp_choice == 3) or 73 | (choice == 3 and comp_choice == 1)): 74 | print("Rock wins =>", end = "") 75 | result = "Rock" 76 | else: 77 | print("scissor wins =>", end = "") 78 | result = "scissor" 79 | 80 | # Printing either user or computer wins or draw 81 | if result == Draw: 82 | print("<== Its a tie ==>") 83 | if result == choice_name: 84 | print("<== User wins ==>") 85 | else: 86 | print("<== Computer wins ==>") 87 | 88 | print("Do you want to play again? (Y/N)") 89 | ans = input().lower 90 | 91 | 92 | # if user input n or N then condition is True 93 | if ans == 'n': 94 | break 95 | 96 | # after coming out of the while loop 97 | # we print thanks for playing 98 | print("\nThanks for playing") 99 | -------------------------------------------------------------------------------- /React/1. Intro.md: -------------------------------------------------------------------------------- 1 | # Introduction to React.Js 2 | 3 | - React is a free and open-source front-end JavaScript library for building user interfaces based on UI components. 4 | - It is maintained by Meta and a community of individual developers and companies. 5 | 6 | # How does React work ? 7 | 8 | - React creates a VIRTUAL DOM in memory. 9 | 10 | - Instead of manipulating the browser's DOM directly, React creates a virtual DOM in memory, where it does all the necessary manipulating, before making the changes in the browser DOM. 11 | 12 | - React only changes what needs to be changed! React finds out what changes have been made, and changes only what needs to be changed. 13 | 14 | To get an overview of what React is, you can write React code directly in HTML. 15 | 16 | # React Directly in HTML 17 | Start by including three scripts, the first two let us write React code in our JavaScripts, and the third, Babel, allows us to write JSX syntax and ES6 in older browsers. 18 | 19 | ## Example 20 | Include three CDN's in your HTML file: 21 | ``` 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
32 | 33 | 40 | 41 | 42 | 43 | ``` 44 | This way of using React can be OK for testing purposes, but for production you will need to set up a React environment. -------------------------------------------------------------------------------- /React/2. Setting Up React.md: -------------------------------------------------------------------------------- 1 | # Setting up a React Environment 2 | 3 | If you have npx and Node.js installed, you can create a React application by using `create-react-app` 4 | 5 | ## Example 6 | Run this command to create a React application named my-react-app:

7 | `npx create-react-app my-react-app` 8 | 9 | # Run the React Application 10 | 11 | Run this command to move to the my-react-app directory:

12 | `cd my-react-app` 13 | 14 | Run this command to run the React application my-react-app:

15 | `npm start` 16 | 17 | A new browser window will pop up with your newly created React App! 18 | 19 | ![React App](https://www.freecodecamp.org/news/content/images/2021/03/Screen-Shot-2021-02-03-at-8.56.40-PM.png) 20 | -------------------------------------------------------------------------------- /React/3. Modifying React Application.md: -------------------------------------------------------------------------------- 1 | # Modify the React Application 2 | 3 | How do you change the content according to your requirements? 4 | 5 | Look in the my-react-app directory, and you will find a src folder. Inside the src folder there is a file called App.js, open it and it will look like this:

6 | ``` 7 | import logo from './logo.svg'; 8 | import './App.css'; 9 | 10 | function App() { 11 | return ( 12 |
13 |
14 | logo 15 |

16 | Edit src/App.js and save to reload. 17 |

18 | 24 | Learn React 25 | 26 |
27 |
28 | ); 29 | } 30 | 31 | export default App; 32 | ``` 33 | Now change the HTML content and save the file. Notice that the changes are visible immediately after you save the file, you do not have to reload the browser! 34 | 35 | ## Example 36 | Replace all the content inside the `
` with a `

` element. 37 | 38 | ``` 39 | function App() { 40 | return ( 41 |
42 |

Hello World!

43 |
44 | ); 45 | } 46 | 47 | export default App; 48 | ``` 49 | Also remove the imports we do not need (logo.svg and App.css).
50 | This will give us a Hello World React Application 51 | 52 | ![Hello World](https://uploads.sitepoint.com/wp-content/uploads/2017/09/150479219402-Hello-World.png) 53 | 54 | Now, for further steps, remove all the files in the folder `src` except `index.js`. Also remove any unnecessary lines of code inside the index.js file to make them look like : 55 | ``` 56 | import React from 'react'; 57 | import ReactDOM from 'react-dom/client'; 58 | 59 | const myFirstElement =

Hello React!

60 | 61 | const root = ReactDOM.createRoot(document.getElementById('root')); 62 | root.render(myFirstElement); 63 | ``` 64 | 65 | To use React, we need to have in-depth knowledge of latest version of JavaScript i.e `ES6` or the 6th version of JavaScript. In our next module, we will learn more about what ES6 features are ? -------------------------------------------------------------------------------- /React/5. React Render.md: -------------------------------------------------------------------------------- 1 | # React Render 2 | 3 | React's goal is in many ways to render HTML in a web page. 4 | 5 | React renders HTML to the web page by using a function called `ReactDOM.render()`. 6 | 7 | ## Render Function 8 | 9 | `ReactDOM.render()` function takes two arguments, HTML code and an HTML element. 10 | The purpose of the function is to display the specified HTML code inside the specified HTML element. 11 | But render where? 12 | 13 | There is another folder in the root directory of your React project, named `public`. In this folder, there is an `index.html` file. 14 | ``` 15 | 16 |
17 | 18 | ``` 19 | We can notice a single `
` in the body of this file. This is where our React application will be rendered. 20 | ``` 21 | ReactDOM.render(

Hello

, document.getElementById('root')); 22 | ``` 23 | 24 | Now if the above code intrigues you as we have written write HTML tags inside the JavaScript code, then move to the next module to learn about JSX or JavaScript XML files. 25 | -------------------------------------------------------------------------------- /React/6. React JSX.md: -------------------------------------------------------------------------------- 1 | # React JSX 2 | 3 | - JSX stands for JavaScript XML. 4 | 5 | - JSX allows us to write HTML elements in JavaScript and place them in the DOM without any createElement() and/or appendChild() methods. 6 | 7 | - JSX converts HTML tags into react elements. 8 | 9 | ## Without JSX 10 | ``` 11 | const myElement = React.createElement('h1', {}, 'I do not use JSX!'); 12 | 13 | const root = ReactDOM.createRoot(document.getElementById('root')); 14 | root.render(myElement); 15 | ``` 16 | 17 | ## With JSX 18 | ``` 19 | const myElement =

I Love JSX!

; 20 | 21 | const root = ReactDOM.createRoot(document.getElementById('root')); 22 | root.render(myElement); 23 | ``` 24 | As you can see in the example, JSX allows us to write HTML directly within the JavaScript code. 25 | 26 | JSX is an extension of the JavaScript language based on ES6, and is translated into regular JavaScript at runtime using `babel` package 27 | 28 | # Expressions in JSX 29 | 30 | With JSX you can write expressions inside curly braces { }. 31 | 32 | The expression can be a React variable, or property, or any other valid JavaScript expression. JSX will execute the expression and return the result: 33 | 34 | ``` 35 | const myElement =

React is {5 + 5} times better with JSX

; 36 | ``` 37 | 38 | The above code basically translates to 39 | ``` 40 | const myElement =

React is 10 times better with JSX

; 41 | ``` 42 | 43 | # Inserting a Large Block of HTML 44 | 45 | To write HTML on multiple lines, put the HTML inside parentheses: 46 | 47 | ``` 48 | const myElement = ( 49 |
    50 |
  • Apples
  • 51 |
  • Bananas
  • 52 |
  • Cherries
  • 53 |
54 | ); 55 | ``` 56 | # One Top Level Element 57 | 58 | The HTML code must be wrapped in ONE top level element. 59 | 60 | So if we write two paragraphs, we must put them inside a parent element, like a div element. 61 | ``` 62 | const myElement = ( 63 |
64 |

I am a paragraph.

65 |

I am a paragraph too.

66 |
67 | ); 68 | ``` 69 | Alternatively, you can use a "fragment" to wrap multiple lines. A fragment looks like an empty HTML tag: <>. 70 | ``` 71 | const myElement = ( 72 | <> 73 |

I am a paragraph.

74 |

I am a paragraph too.

75 | 76 | ); 77 | ``` 78 | JSX follows XML rules, and therefore HTML elements must be properly closed. 79 | ``` 80 | const myElement = ; 81 | ``` 82 | 83 | # Attribute class = className 84 | 85 | The `class` attribute is a much used attribute in HTML, but since JSX is rendered as JavaScript, and the `class` keyword is a reserved word in JavaScript, you are not allowed to use it in JSX. 86 | Use attribute `className` instead. 87 | 88 | ``` 89 | const myElement =

Hello World

; 90 | ``` 91 | We use attribute `className` instead of `class` in JSX. 92 | 93 | # Conditions - if statements 94 | 95 | React supports if statements, but not inside JSX. 96 | 97 | ## Option 1: Write if statements outside of the JSX code: 98 | ``` 99 | const x = 5; 100 | let text = "Goodbye"; 101 | if (x < 10) { 102 | text = "Hello"; 103 | } 104 | 105 | const myElement =

{text}

; 106 | ``` 107 | 108 | ## Option 2: Use ternary expressions instead from previous module: 109 | ``` 110 | const x = 5; 111 | 112 | const myElement =

{(x) < 10 ? "Hello" : "Goodbye"}

; 113 | ``` -------------------------------------------------------------------------------- /React/7. React Components.md: -------------------------------------------------------------------------------- 1 | # React Components 2 | 3 | - Components are independent and reusable bits of code. They serve the same purpose as JavaScript functions, but work in isolation and return HTML. 4 | 5 | - Components come in two types, Class components and Function components, in this tutorial we will concentrate on Function components. 6 | 7 | When creating a React component, the component's name MUST start with an upper case letter. 8 | 9 | ## Class Component 10 | 11 | A class component must include the extends React.Component statement. This statement creates an inheritance to React.Component, and gives your component access to React.Component's functions. 12 | 13 | The component also requires a render() method, this method returns HTML. 14 | ``` 15 | class Car extends React.Component { 16 | render() { 17 | return

Hi, I am a Car!

; 18 | } 19 | } 20 | ``` 21 | 22 | ## Function Component 23 | 24 | A Function component also returns HTML, and behaves much the same way as a Class component, but Function components can be written using much less code, are easier to understand, and will be preferred in this tutorial. 25 | ``` 26 | function Car() { 27 | return

Hi, I am a Car!

; 28 | } 29 | ``` 30 | 31 | 32 | # Rendering a Component 33 | 34 | Now your React application has a component called Car, which returns an `

` element 35 | 36 | To use this component in your application, use similar syntax as normal HTML: `` 37 | 38 | Display the `Car` component in the `root` element: 39 | ``` 40 | const root = ReactDOM.createRoot(document.getElementById('root')); 41 | root.render(); 42 | ``` 43 | 44 | # Props 45 | 46 | Components can be passed as props, which stands for properties. 47 | 48 | Props are like function arguments, and you send them into the component as attributes. 49 | 50 | Let's use an attribute to pass a color to the `Car` component, and use it in the `render()` function: 51 | ``` 52 | function Car(props) { 53 | return

I am a {props.color} Car!

; 54 | } 55 | 56 | const root = ReactDOM.createRoot(document.getElementById('root')); 57 | root.render(); 58 | ``` 59 | We will learn more about props in the next module. 60 | 61 | # Components in Components 62 | 63 | We can refer to components inside other components: 64 | 65 | Let's use the `Car` component inside the `Garage` component: 66 | ``` 67 | function Car() { 68 | return

I am a Car!

; 69 | } 70 | 71 | function Garage() { 72 | return ( 73 | <> 74 |

Who lives in my Garage?

75 | 76 | 77 | ); 78 | } 79 | 80 | const root = ReactDOM.createRoot(document.getElementById('root')); 81 | root.render(); 82 | ``` 83 | 84 | # Components in Files 85 | 86 | React is all about re-using code, and it is recommended to split the components into separate files. 87 | 88 | To do that, we create a new file with a .js file extension and put the code inside it: 89 | 90 | ### This is the new file, we named it `Car.js`: 91 | ``` 92 | function Car() { 93 | return

Hi, I am a Car!

; 94 | } 95 | 96 | export default Car; 97 | ``` 98 | To be able to use the `Car` component, you have to import the file in your application. 99 | 100 | ### Import the `Car.js` file in the application, and we can use the `Car` component: 101 | ``` 102 | import React from 'react'; 103 | import ReactDOM from 'react-dom/client'; 104 | import Car from './Car.js'; 105 | 106 | const root = ReactDOM.createRoot(document.getElementById('root')); 107 | root.render(); 108 | ``` -------------------------------------------------------------------------------- /SQL/Introduction.md: -------------------------------------------------------------------------------- 1 | # Introduction to SQL 2 | 3 | - SQL stands for Structured Query Language 4 | - It is used for accessing and manipulating databases. 5 | 6 | # What can SQL do? 7 | 8 | SQL is widely used in data science and analytics. Following are the reasons which explain why it is widely used: 9 | 10 | - Execute queries against a database 11 | - Retrieve data from a database 12 | - Insert records in a database 13 | - Update records in a database 14 | - Delete records from a database 15 | - Create new databases, tables, stored procedures, views 16 | - Set permissions on tables, procedures, and views 17 | 18 | # Process of SQL 19 | 20 | Structured Query Language contains the following four components in its process: 21 | 22 | - Query Dispatcher 23 | - Optimization Engines 24 | - Classic Query Engine 25 | - SQL Query Engine, etc. 26 | 27 | # Advantages of SQL 28 | 29 | - No programming needed 30 | - High-Speed Query Processing 31 | - Standardized Language 32 | - Portability 33 | - Interactive language 34 | - More than one Data View 35 | 36 | # Disadvantages of SQL 37 | 38 | - Cost 39 | - Interface is Complex 40 | - Partial Database control 41 | -------------------------------------------------------------------------------- /Theory of Computation and Compiler Design/Aspose.Words.0622bb25-4a63-4e23-9ca4-4aede3188d90.001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/Theory of Computation and Compiler Design/Aspose.Words.0622bb25-4a63-4e23-9ca4-4aede3188d90.001.png -------------------------------------------------------------------------------- /Theory of Computation and Compiler Design/Aspose.Words.0622bb25-4a63-4e23-9ca4-4aede3188d90.002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/Theory of Computation and Compiler Design/Aspose.Words.0622bb25-4a63-4e23-9ca4-4aede3188d90.002.png -------------------------------------------------------------------------------- /Theory of Computation and Compiler Design/Aspose.Words.0622bb25-4a63-4e23-9ca4-4aede3188d90.003.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/Theory of Computation and Compiler Design/Aspose.Words.0622bb25-4a63-4e23-9ca4-4aede3188d90.003.jpeg -------------------------------------------------------------------------------- /Theory of Computation and Compiler Design/Aspose.Words.64b0950e-2857-417e-92b9-18dbe7754dd6.001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/Theory of Computation and Compiler Design/Aspose.Words.64b0950e-2857-417e-92b9-18dbe7754dd6.001.png -------------------------------------------------------------------------------- /Theory of Computation and Compiler Design/Aspose.Words.64b0950e-2857-417e-92b9-18dbe7754dd6.002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/Theory of Computation and Compiler Design/Aspose.Words.64b0950e-2857-417e-92b9-18dbe7754dd6.002.png -------------------------------------------------------------------------------- /Theory of Computation and Compiler Design/Theory-of-Computation notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/Theory of Computation and Compiler Design/Theory-of-Computation notes.pdf -------------------------------------------------------------------------------- /Web Technology/Backend-design-roadmap.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/Web Technology/Backend-design-roadmap.jpeg -------------------------------------------------------------------------------- /Web Technology/Email-Checker/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Example 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | -------------------------------------------------------------------------------- /Web Technology/Email-Checker/index.php: -------------------------------------------------------------------------------- 1 | "https://mailcheck.p.rapidapi.com/?domain=$email", 8 | CURLOPT_RETURNTRANSFER => true, 9 | CURLOPT_FOLLOWLOCATION => true, 10 | CURLOPT_ENCODING => "", 11 | CURLOPT_MAXREDIRS => 10, 12 | CURLOPT_TIMEOUT => 30, 13 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 14 | CURLOPT_CUSTOMREQUEST => "GET", 15 | CURLOPT_HTTPHEADER => [ 16 | "X-RapidAPI-Host: mailcheck.p.rapidapi.com", 17 | "X-RapidAPI-Key: e5d6a92e28msh704f95d143e01cap1c7bc6jsnf1e45176b22f" 18 | ], 19 | ]); 20 | 21 | $response = curl_exec($curl); 22 | $err = curl_error($curl); 23 | 24 | curl_close($curl); 25 | 26 | if ($err) { 27 | echo "cURL Error #:" . $err; 28 | } else { 29 | echo $response; 30 | } 31 | ?> 32 | 33 | -------------------------------------------------------------------------------- /Web Technology/Front-End-Frameworks-and-Libraries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikashpatel24/Computer-Science-Engineering/cabc20841c7b7fb8f0880a5400b617cf70f94423/Web Technology/Front-End-Frameworks-and-Libraries.png --------------------------------------------------------------------------------