Find Median of Two Sorted Arrays Using Binary Search in C++

Aman Kumar
Updated on 20-May-2025 18:47:53

245 Views

The median is defined as the middle value of a sorted list of numbers, and the middle value is found by ordering the numbers in ascending order. Once the numbers are ordered, the middle value is called the median of the given data set. Here, in this article, we have two different sorted arrays and need to find the median of these two array using binary search. Median depends on the sorted combined array. So, the following cases may occur: If the length of the combined array is odd, then the median should be the ... Read More

Find Maximum Subarray Sum using Naive Method in C++

Aman Kumar
Updated on 20-May-2025 18:47:14

366 Views

A subarray is a contiguous slice of an array, and maintains the order of elements naturally. (i.e., the elements of the subarray occupy consecutive positions). For example, the subarrays of an array {1, 2, 3} are {1}, {1, 2}, {1, 2, 3}, {2}, {2, 3}, and {3}. Input / Output Scenario Let's see the following input/output scenario: Input: arr[] = {1, 4, 5, 3, -1} Output: 13 Explanation: Subarray {1, 4, 5, 3} has the maximum sum 13. Input: arr[] = {1, 2, -3, 4, 5, -1} Output: 9 Explanation: Subarray {1, 2, -3, 4, 5} has the ... Read More

Differences Between Tight Coupling and Loose Coupling in Java

Shriansh Kumar
Updated on 20-May-2025 18:33:46

16K+ Views

In object-oriented programming, coupling is a term used to describe the level of dependency each class or component of an application has on another. Tight coupling in Java means features of different classes and objects have high dependence on one another, whereas Loose coupling means components have very low or no dependency on one another. This article explains how tight coupling is different from loose coupling in Java. Tight Coupling in Java In tight coupling, if the implementation of one class changes, the dependent class might also need to be changed. It makes Java code less flexible and more difficult ... Read More

Differences Between Import and Static Import Statements in Java

Shriansh Kumar
Updated on 20-May-2025 18:22:18

5K+ Views

The import statement is used to bring certain classes and interfaces from other packages into our Java program, so we can access them without using their fully qualified names. We can use the short name instead. Java also supports static import statements, which were introduced in Java 5. It helps in accessing static members such as methods and constants. In this article, we are going to learn the difference between import and static import statements in Java. The import Statement in Java To access a class or method from another package, we need to either use the fully qualified ... Read More

Differences Between Widening Casting (Implicit) and Narrowing Casting (Explicit) in Java

Shriansh Kumar
Updated on 20-May-2025 18:19:49

4K+ Views

A Type casting in Java is used to convert objects or variables from one data type to another. When we are converting or assigning one data type to another, automatic conversion will take place (if the types are compatible and the conversion is safe). However, if there is a risk of data loss, the conversion must be done explicitly by the programmer. Let's understand the types of Java type casting and the difference between them in this article. Types of Type Casting in Java Java Type Casting is classified into two types, which are: ... Read More

Resolve NullPointerException in Java

Shriansh Kumar
Updated on 20-May-2025 17:25:10

2K+ Views

The NullPointerException is a subclass of the RuntimeException class. It is defined in java.lang package of Java. In this article, we are going to understand the reasons for NullPointerException and how to resolve them. Reason for NullPointerException in Java A NullPointerException is a runtime exception thrown by the JVM when our application code, another referenced API, or the middleware encounters the following conditions: Attempting to invoke an instance method of a null object. ... Read More

Remove Element from ArrayList in Java

Vivek Verma
Updated on 20-May-2025 16:16:58

579 Views

The article will discuss different ways to remove elements from an ArrayList. Below is a list of methods that can help in removing elements from an ArrayList: Using the remove() Method of List Interface Using the remove(object) Method Using the clear() Method Using the removeAll() Method Removing a Single Element using the remove() Method The remove() method of the List interface accepts an integer value representing an index as a parameter and removes an element at the specified index. Following is the ... Read More

Create Python Dictionary from Object's Fields

Disha Verma
Updated on 20-May-2025 16:12:44

392 Views

In Python, objects are instances of classes containing attributes and methods, while dictionaries are collections of key-value pairs. We can obtain a dictionary from an object's fields - Using __dict__ Using vars() Using __dict__ You can access an object's attributes as a dictionary using its _dict_ attribute. In Python, every object has a _dict_ attribute that stores the object's attributes and their values as a dictionary (key-value pairs). Example In this example, we have defined a class Company with attributes Companyname and Location, and created ... Read More

Calculate Absolute Value in Python

Disha Verma
Updated on 20-May-2025 15:54:39

9K+ Views

The absolute value of a number is its non-negative representation. It specifies the distance of that number from zero on a number line, irrespective of its direction.For example, the absolute value of -2 is 2, and 2 is simply 2. In this article, we will explore how to calculate the absolute value of a number in Python. Calculating Absolute Value in Python The following methods can be efficiently used to calculate the absolute value of a number. Using User-Defined Function (Brute Method) Using abs() function ... Read More

Map Two Lists into a Dictionary in Python

Disha Verma
Updated on 20-May-2025 15:27:23

423 Views

In Python, dictionaries are used to store data as key-value pairs, and lists store a collection of items separated by commas. To map two lists into a dictionary, we have various methods in Python that we will explore in this article. Mapping two lists into a Dictionary Mapping two lists into a dictionary can be done using the following methods - Using a Loop Using a Zip and Dict Method Using Dictionary Comprehension Using a Loop For loops are used to iterate ... Read More

Advertisements