
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

509 Views
Dictionary in python is one of the most frequently used collection data type. It is represented by hey value pairs. Keys are indexed but values may not be. There are many python-built in functions that make using the dictionary very easy in various python programs. In this topic we will see the three in-built methods namely update(), has_key() and fromkeys().update()The method update adds new items to a given dictionary by merging the items from the secondary with first.Syntaxdict1.update(dict2) Where dict1 and dict2 are the two input dictionaries.In the below example we see pairs of dictionaries. The second dictionary gets added ... Read More

1K+ Views
In this article, we will learn about the solution to the problem statement given below.Problem statement− We are given an array, we need to sort it using the concept of recursive insertion sort.Insertion sort works on creating a parallel array in which we manually insert the elements in the specified order.Now let’s observe the solution in the implementation below −Example Live Demo# recursive way def insertionSortRecursive(arr, n): # base case if n=0 and arr[j]>last): arr[j+1] = arr[j] j = j-1 arr[j+1]=last # main arr = [1, 5, 3, 4, 8, 6, 3, ... Read More

6K+ Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given an array, we need to sort it using the concept of quicksortHere we first partition the array and sort the separate partition to get the sorted array.Now let’s observe the solution in the implementation below −Example Live Demo# divide function def partition(arr,low,high): i = ( low-1 ) pivot = arr[high] # pivot element for j in range(low , high): # If current element is smaller if arr[j]

1K+ Views
A cycle occurs when a path starts and ends at the same vertex, following the direction of the edges. In directed graphs, cycles can cause problems like infinite loops or dependency errors, so detecting them is important in areas like task scheduling and deadlock detection. We can use Depth-First Search (DFS) with a recursion stack to detect whether a cycle exists in a directed graph or not. Problem Statement You are given a directed graph represented using an adjacency list. Your task is to write a Python program to check whether the graph contains a cycle or not. DFS-Based Cycle ... Read More

892 Views
Rod Cutting ProblemThe Rod Cutting problem is a classic example of dynamic programming. The goal is to cut a rod into pieces to maximize the total value. Each piece has a specific length and value, and we must choose the cuts in such a way that the total value is as high as possible. This problem is similar to the 0-1 Knapsack problem and can be solved using recursion and dynamic programming techniques. It is useful in resource allocation and pricing strategies. Rod Cutting Problem Statement You are given a rod of length n and an array price[] where price[i] ... Read More

384 Views
What is Cocktail Sort? Cocktail sort is a variation of bubble sort that sorts the array in both directions on each pass. It is also known as Bidirectional Bubble Sort or Shaker Sort. The algorithm works by traversing the list forward and backward, alternatively, pushing the largest and smallest elements to their respective ends. This approach helps in reducing the number of iterations compared to Bubble Sort, especially when smaller elements are at the end of the list. Problem Statement You are given an unsorted list of elements. The goal is to sort the list using Cocktail Sort, which moves ... Read More

275 Views
BogoSort, also known as Permutation Sort or Stupid Sort, is a sorting algorithm based on generating random permutations of the list until it gets sorted. BogoSort continues to shuffle the array randomly until the list becomes sorted. The expected time complexity is unbounded, and its average performance is extremely poor. Problem Statement You are given a list of unsorted elements. Your task is to sort the list using BogoSort by repeatedly generating random permutations until the list is sorted. Random Permutation-based Sorting This sorting method checks if the list is sorted. If not, it randomly shuffles the elements and checks ... Read More

1K+ Views
Binary Insertion SortBinary insertion sort is an improved version of the regular Insertion Sort algorithm. In a normal insertion sort, each element is compared linearly with the sorted portion of the list to find its correct position. This takes O(n) comparisons for each element. In Binary Insertion Sort, we use Binary Search to find the correct position of the current element in the sorted part of the list. This reduces the number of comparisons from O(n) to O(log n) per insertion. However, shifting elements still takes O(n) time in the worst case. Problem Statement You are given a list of ... Read More

594 Views
Euclidean AlgorithmThe Euclidean Algorithm is used to find the Greatest Common Divisor (GCD) of two numbers. The GCD of two integers is the largest number that divides both of them without leaving a remainder. This algorithm is based on the principle that the GCD of two numbers also divides their difference. The method repeatedly replaces the larger number by the remainder of dividing the larger number by the smaller one, until one of the numbers becomes zero. Problem Statement You are given two positive integers a and b. You need to find the greatest common divisor (GCD) of these two ... Read More

194 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − Given a text and a pattern, we need to print all occurrences of pattern and its permutations (or anagrams) in text.Now let’s observe the solution in the implementation below −Example Live Demo# maximum value MAX = 300 # compare def compare(arr1, arr2): for i in range(MAX): if arr1[i] != arr2[i]: return False return True # search def search(pat, txt): M = len(pat) N = len(txt) # countP pattern account # countTW ... Read More