Add hours to current time using Calendar.add() method in Java

Aishwarya Naglot
Updated on 17-Jul-2025 18:12:08

2K+ Views

What is the Calendar.add() method in Java? The add() method belongs to the java.util.Calendar class. This method is used to add or subtract a specified amount of time to any field of the calendar. For example, we can add months, years, days, hours, minutes, etc., to the current date or current time using this method. Syntax Following is the syntax of the calendar.add() method: calendar.add(Calendar.HOUR, amount); Here, Calendar.HOUR is a constant that represents the hour field in the calendar, and amount is the number of hours you want to add to the current date. Adding Hours to Current Time ... Read More

Add elements to a Vector in Java

Aishwarya Naglot
Updated on 17-Jul-2025 17:54:23

1K+ Views

The java.util.Vector class is a part of the Java Collections Framework. It implements the List interface and is used for storing the elements in a dynamic array. It is similar to an ArrayList but is synchronized (thread-safe). The size of a vector grows dynamically as we add more elements to it and shrinks when we remove elements. It can also contain duplicate elements and null values. We can add elements to a vector in the following ways: Using add() Method Using add(int index, E element) Method Using addElement() Method ... Read More

C++ Program to Find Number of Articulation points in a Graph

Farhan Muhamed
Updated on 17-Jul-2025 17:17:46

602 Views

An articulation point is a vertex of the graph, which when removed, will break the graph into two or more components. You are given a connected undirected graph with V vertices and E edges. Your task is to find number of articulation points in the graph. To understand this better, consider the following example: Graph: 0 / \ 1 - 2 | 3 - 4 Output: 2 Articulation Points Explanation: Removing vertex 1 or 3 will split the graph into two components. Methods to Find Articulation Points To ... Read More

C++ Program to Check whether Graph is a Bipartite using BFS

Farhan Muhamed
Updated on 17-Jul-2025 17:17:06

811 Views

The Breadth First Search (BFS) algorithm can be used to check whether a graph is bipartite by coloring the graph using two colors. This section will discuss how the BFS traversal can be used to check if a graph is bipartite. First of all, let's understand what a bipartite graph is. What is Bipartite Graph? Bipartite graph is special graph where you can divide the vertices into two sets, such that no two vertices of the same set are connected. This is why, it's possible to color a bipartite graph by using just two colors. Technically a graph is ... Read More

C++ Program to Find Chromatic Index of Cyclic Graphs

Farhan Muhamed
Updated on 16-Jul-2025 18:20:22

651 Views

The chromatic index of a graph is the maximum number of color needed for the edge coloring of the graph, such that no two adjacent edges have the same color. It is also known as the edge chromatic number. A cyclic graph is a graph that contains at least one cycle or a closed path. For example, a triangle is a cyclic graph and we can color its edges with 3 colors. // Graph: 0 -> 1 1 -> 2, 3 2 -> 0 Chromatic Index: 3 To find the chromatic index of cyclic graphs, we ... Read More

Sum of the series 1 + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n) in C++

Ravi Ranjan
Updated on 16-Jul-2025 18:15:22

855 Views

In this article, we are given a number n. Our task is to write a program to calculate the sum of the series 1 + (1+2) + (1+2+3) + (1+2+3+4) + … + (1+2+3+4+...+n). This series can be represented mathematically as: $$ \displaystyle\sum\limits_{k=1}^n \displaystyle\sum\limits_{j=1}^k j $$ The above series is also known as tetrahedral number or triangular pyramidal number. A tetrahedral number is the number of points required to form a pyramid with a triangular base. Below is an example of the tetrahedral number series up to n. Scenario Consider the following example ... Read More

C++ Program to Find Inverse of a Graph Matrix

Farhan Muhamed
Updated on 16-Jul-2025 16:24:13

9K+ Views

Every graph can be represented by a matrix called the adjacency matrix, in which each element indicates whether pairs of vertices have an edge between them. In this article, we will learn to find the inverse of a adjacency matrix of a graph using C++. First of all, let's understand what the inverse of a matrix means. Inverse of a Matrix The inverse of a matrix A is another matrix, denoted as A-1, such that the result of matrix multiplication A.A-1 will be an identity matrix I. The identity matrix is a square matrix with ones on the diagonal ... Read More

How to initialize a dynamic array in C++?

Farhan Muhamed
Updated on 16-Jul-2025 16:01:28

3K+ Views

Dynamic arrays are a type of array that can grow or shrink their size as elements are added or removed. They are created using pointers and memory management functions such as new and delete. In this article, we will learn different ways to initialize a dynamic arrays in C++. Here is the list of approaches to initialize a dynamic array in C++: Using new and () Using new and {} Using Loop for Custom Initialization Initializing Dynamic Arrays Using new and () This ... Read More

C++ Program to Implement Kadane’s Algorithm

Farhan Muhamed
Updated on 16-Jul-2025 16:00:26

2K+ Views

The Kadane's algorithm is used to find the maximum subarray sum in a given array of integers. This section will explain the Kadane's algorithm with example and C++ implementation. Given an array of integers, our task is to find the maximum possible sum for a subarray using Kadane's algorithm. For example:ScenarioConsider the following example with input/output scenario: Input: [-2, 1, -3, 4, -1, 2, 1, -5, 4] Output: 6 Explanation: The subarray [4, -1, 2, 1] has the largest sum = 6. What is Kadane's Algorithm? Kadane's algorithm is an optimized method to find the maximum ... Read More

Adding Tuple to List and vice versa in Python

Farhan Muhamed
Updated on 15-Jul-2025 18:33:43

2K+ Views

In Python, both tuples and lists are used to store data in sequence. Python provides built-in functions and operators that allow us to easily add elements of a tuple into a list and elements of a list into a tuple. In this article, we will explain various methods to perform these conversions, along with example codes. Scenario 1 You are given a list and a tuple as input, your task is to add tuple into the list and print the list as output. For example: # Input List and Tuple my_list = [3, 6, 9, 45, 66] my_tup = ... Read More

Advertisements