An adjacency list of graph is a collection of unordered lists, that represents a finite graph data structure using linked lists. Each list in the collection represents one of the vertex of the graph and it will store the adjacent vertices of that vertex. In this article we will learn how to implement adjacency list for a graph using C++ program. First of all, let's see an example of adjacency list. Example of Adjacency List To understand what is an adjacency list is, first we need to take a graph data structure for reference. The image below represent a ... Read More
The adjacency matrix of a graph is a square matrix of size V x V, that represent a finite graph data structure using a 2D array, where V is number of edges of the graph. The each non zero elements in the matrix represent an edges of the graph. For example, if the graph has some edges from i to j vertices, then in the adjacency matrix at i th row and j th column it will be 1 (or some non-zero value for weighted graph), otherwise that value will be 0. In this article, we will learn how to ... Read More
The quick sort technique is based on partitioning of array of data into smaller arrays. Initially, a pivot element is chosen by the partitioning algorithm. The left part of the pivot holds smaller values than the pivot, and the right part holds the larger value. In this case, we are choosing the pivot element randomly. After choosing the pivot, we do the partitioning and then sort the array recursively. In this article, we have an array having 100 elements. Our task is to implement quick sort on this array using randomization in C++. Here is an example of a quick ... Read More
The calculation of the angle between the hour and minute hands of a clock is a common problem in Logical Reasoning and programming. This calculation is used in various applications, such as analog clock simulations, scheduling software, and time-based animations In this article, we are going to discuss how we can calculate the angle between the hour and minute hands of a clock in C# using different approaches: What is the Angle Between the Hour and Minute Hands? The angle between the hour and minute hands is determined based on the positions of both hands on the clock ... Read More
In this article, we have a positive integer 'n'. Our task is to generate all possible unique ways to represent 'n' as the sum of positive integers in C++. Each partition should give a sum equal to the given 'n'. Here is an example: Input: n = 4 Output: 4 3 1 2 2 2 1 1 1 1 1 1 Steps to Perform Unique Partition of Integer We start with the current partition i.e. with an initial value of n. Then we print the current partition. ... Read More
In C/C++, an input buffer is a temporary storage area where the program processes the input. Suppose, you are an user and you type some characters using a keyboard but those characters are not passed to the program directly because it involves several layers of handling such as keyboard firmware, OS input queues, and event processing. So, they first proceed with the collection of an input buffer. Next, when the program is ready, it reads from the buffer. How Input Buffer Affects a Program? The input buffer affected to the program when we are using the functions like scanf() or ... Read More
Organizing Python modules efficiently is important to maintain scalability and collaboration. Following best practices can make your project easier to understand and use. In this article, we will discuss about an structure approach to organize Python modules with a sample project and some of the best practices to organize. Sample Project Structure Samplemod is an example of a well-structured project that focuses on creating sample module. Below is the directory structure of this project - README.rst LICENSE setup.py requirements.txt sample/__init__.py sample/core.py sample/helpers.py docs/conf.py docs/index.rst tests/test_basic.py tests/test_advanced.py Let's look at these one by one - ... Read More
Regular expressions are a very crucial part of Python's built-in 're' module. It is used to work with text data. One of the advantages of regex is the ability to use alternatives, which allows you to match one pattern out of multiple options. Alternatives in the regular expressions function are just like "or" statements. They help you to define many patterns to match against a given string. The vertical bar | denotes the "or" operator in regex. For example, the regex pattern PHP|Python will match either "PHP" or "Python" in a given string. The following are the 4 different ways ... Read More
The Fibonacci numbers, commonly denoted as F(n) forms a sequence, called the Fibonacci sequence. In Fibonacci series, each number is the sum of the two previous two numbers, starting from 0 and 1. It is represented as F(n) = F(n-1) + F(n-2). The matrix exponentiation method is used to calculate the powers of matrix efficiently with better time complexity. In this article, we provide a value of n. This n is the value up to which we want to find the Fibonacci numbers using the matrix exponentiation method in C++. Here is an example of the Fibonacci series up to ... Read More
We are given an array of integers, and we need to find the maximum sum of a contiguous subarray using Kadane’s Algorithm. Kadane’s Algorithm is an efficient way to find the maximum subarray sum in O(n) time complexity. For example, in the array {-2, 1, -3, 4, -1, 2, 1, -5, 4}, the subarray [4, -1, 2, 1] has the maximum sum 6. In this article, we are going to implement Kadane's algorithm using C. What Is Kadane's Algorithm? Kadane's algorithm is a popular and optimal algorithm used to find the maximum sum of a contiguous subarray in a given ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP