
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 26504 Articles for Server Side Programming

894 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

388 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

276 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

601 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

195 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

1K+ Views
The activity selection problem selects the maximum number of non-overlapping activities from a given set. Each activity has a start and finish time, and a single person can perform only one activity at a time. Problem Statement You are given n activities, each defined by a start time and a finish time. The goal is to choose the maximum number of activities that a single person can perform without any overlap between the selected activities. Variable Notations Below are the variables used in the problem definition: N: Total number of activities S: ... Read More

5K+ Views
Knapsack is a classic problem that involves decision-making based on constraints. Suppose we have a knapsack with fixed capacity, and items with fixed values and sizes (it might be volume of the item or weight). We need to add items into the knapsack such that we pack the maximum value items. From the available combinations, we need to provide an optimized solution. There are three types of knapsack problems 0-1 Knapsack: We can either pick an item or not (0 or 1). Fractional Knapsack: We can pick a part of an ... Read More

671 Views
Now we will see how to get the second last element in the linked list. Suppose there are few elements like [10, 52, 41, 32, 69, 58, 41], second last element is 58.To solve this problem, we will use two pointers one will point to current node, and another will point to previous node of the current position, then we will move until the next of current is null, then simply return the previous node.Example Live Demo#include using namespace std; class Node { public: int data; Node *next; }; void prepend(Node** start, int new_data) ... Read More

476 Views
Here we will see the second largest element in the linked list. Suppose there are n different nodes with numerical values. So if the list is like [12, 35, 1, 10, 34, 1], then second largest element will be 34.This process is similar to the finding of second largest element in an array, we will traverse through the list and find second largest element by comparing.Example#include using namespace std; class Node { public: int data; Node *next; }; void prepend(Node** start, int new_data) { Node* new_node = new Node; new_node->data = ... Read More