Programming Articles - Page 2162 of 3363

Maximum equlibrium sum in an array in C++

Narendra Kumar
Updated on 10-Jan-2020 07:10:53

483 Views

Problem statementGiven an array arr[]. Find maximum value of prefix sum which is also suffix sum for index i in arr[].ExampleIf input array is −Arr[] = {1, 2, 3, 5, 3, 2, 1} then output is 11 as −Prefix sum = arr[0..3] = 1 + 2 + 3 + 5 = 11 andSuffix sum = arr[3..6] = 5 + 3 + 2 + 1 = 11AlgorithmTraverse the array and store prefix sum for each index in array presum[], in which presum[i] stores sum of subarray arr[0..i]Traverse array again and store suffix sum in another array suffsum[], in which suffsum[i] stores ... Read More

Maximum element in a very large array using pthreads in C++

Narendra Kumar
Updated on 10-Jan-2020 07:07:59

529 Views

Problem statementGiven a very large array of integers, find maximum within the array using multithreadingExampleIf input array is {10, 14, -10, 8, 25, 46, 85, 1673, 63, 65, 93, 101, 125, 50, 73, 548} thenmaximum element in this array is 1673AlgorithmLet us call array size as total_elementsCreate N threadsEach thread will process (total_elementes/N) array elements and will find maximum element from it.Finally compute the maximum from the maximum value reported by each thread.Example#include #include #include #include #define MAX 10 #define SIZE(arr) (sizeof(arr) / sizeof(arr[0])) typedef struct struct_max {    int start;    int end;    int ... Read More

Maximum element in a sorted and rotated array in C++

Ravi Ranjan
Updated on 09-Jun-2025 19:15:30

628 Views

A sorted and rotated array is an array that is sorted in ascending or descending order and then rotated either left or right by a specific number of elements. There should exist exactly one pivot point around which the array is rotated. In this article, our task is to find the maximum element in the given sorted and rotated array. We will use the following two approaches mentioned below: Using Linear Search Using Binary Search Example Here is an example of ... Read More

Difference between Abstract Class and Interface in C# Program

Mahesh Parahar
Updated on 24-Feb-2020 11:51:10

3K+ Views

As we all know that C# is an object oriented programming just like Java and provides full support for object-oriented concepts that are Encapsulation, Abstraction, Inheritance, and Polymorphism. In contrast to Abstraction both Abstract class and Interface are coming out in picture as both of these provides abstraction in C# program.In an abstract class, we can create the functionality and that needs to be implemented by the derived class. The interface allows us to define the functionality or functions but cannot implement that. The derived class extend the interface and implement those functions.Following are the important differences between Abstract Class ... Read More

Differences between Procedural and Object Oriented Programming

Kiran Kumar Panigrahi
Updated on 15-Sep-2023 02:20:07

41K+ Views

Both Procedural Programming and Object Oriented Programming are high-level languages in programming world and are widely used in the development of applications. On the basis of nature of developing the code, both languages have different approaches on basis of which both are differentiate from each other. In this article, we will discuss the important differences between procedural oriented programming and object oriented programming. But before going into the differences, let's start with some basics. What is Procedural Programming? Procedural Programming is a programming language that follows a step-by-step approach to break down a task into a collection of variables ... Read More

How to implement DoubleBinaryOperator using lambda and method reference in Java?

raja
Updated on 13-Jul-2020 12:28:40

421 Views

DoubleBinaryOperator is a functional interface defined in java.util.function package. It accepts two parameters of type double as input and produces another double value as a result. DoubleBinaryOperator interface can be used as an assignment target for a lambda expression or method reference and has only one abstract method applyAsDouble().Syntax@FunctionalInterface public interface DoubleBinaryOperator {  double applyAsDouble(double left, double right); }Example-1import java.util.function.DoubleBinaryOperator; public class DoubleBinaryOperatorTest {    public static void main(String args[]) {       // using lambda expression       DoubleBinaryOperator sum = (d1, d2) -> d1 + d2;       DoubleBinaryOperator mul = (d1, d2) -> d1 * d2;       DoubleBinaryOperator div = ... Read More

Difference between var and dynamic in C#

Mahesh Parahar
Updated on 24-Feb-2020 11:25:58

6K+ Views

As we know that programming in any language get starts with declaration a variable after which its definition and logic implementation take place. So it is one of the most important factors to know that how to declare variable in any programming language before starts coding in it.Now if we take an instance of C# language there is change in declaration in variable with the advancement in the language. As in former version of C# all the code written was validated at the compile time itself which made it as Static typed language where variables are getting declared using var ... Read More

Difference between Traditional Collections and Concurrent Collections in java

Mahesh Parahar
Updated on 17-Jun-2025 16:29:14

1K+ Views

In Java, as we know, Collections are one of the most important concepts that make Java a powerful language in itself. It's the support of collections in Java that makes it support any type of data in a convenient and efficient way, along with possible CRUD operations over them. But on the same phase, when collections get exposed to a multi-threading its performance gets somewhat degraded because somewhere collections lack the support for a multi-threading environment. To overcome this limitation, Java introduces Concurrent Collections, which not only overcome the multi-threading environment limitation but also enhance Java to perform with multiple ... Read More

Difference between Static and Shared libraries

Mahesh Parahar
Updated on 24-Feb-2020 11:03:30

3K+ Views

In programming context library is something which has some sort of that code which is pre compiled and could get reused in any program for some specific functionality or feature.Now on the basis of execution and storage of this code library is classified in two types i.e Static library and Shared library.Following are the important differences between Static library and Shared library.Sr. No.KeyStatic libraryShared library1DefinitionStatic library is the library in which all the code to execute the file is in one executable file and this file get copied into a target application by a compiler, linker, or binder, producing an ... Read More

How to implement ActionEvent using method reference in JavaFX?

raja
Updated on 13-Jul-2020 12:16:32

2K+ Views

The javafx.event package provides a framework for Java FX events. The Event class serves as the base class for JavaFX events and associated with each event is an event source, an event target, and an event type. An ActionEvent widely used when a button is pressed.In the below program, we can implement an ActionEvent for a button by using method reference.Exampleimport javafx.application.*; import javafx.beans.property.*; import javafx.event.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; import javafx.scene.effect.*; public class MethodReferenceJavaFXTest extends Application {    private Label label;    public static void main(String[] args) {       launch(args);    }    @Override    public void start(Stage primaryStage) {   ... Read More

Advertisements