Binary Indexed Tree or Fenwick Tree in C++

Arnab Chakraborty
Updated on 29-Jan-2020 11:11:23

480 Views

In case of comparing with a flat array of numbers, the Fenwick tree results a much better balance between two operations: element update and prefix sum computation. In case of a flat array of m numbers, we can either store the elements, or the prefix sums. In case of first instance, calculating prefix sums needs linear time; in case of second instance, modifying or updating the array elements needs linear time (in both instances, the other operation can be accomplished in constant time). Fenwick trees permit both operations to be accomplished in O(log m) time. This is obtained by representing ... Read More

Calling a Function in Python

Mohd Mohtashim
Updated on 29-Jan-2020 11:10:26

546 Views

Defining a function only gives it a name, specifies the parameters that are to be included in the function and structures the blocks of code.Once the basic structure of a function is finalized, you can execute it by calling it from another function or directly from the Python prompt. Following is the example to call printme() function − Live Demo#!/usr/bin/python # Function definition is here def printme( str ): "This prints a passed string into this function" print str return; # Now you can call printme function printme("I'm first call to user defined function!") printme("Again second call to the same function")OutputWhen ... Read More

The Calendar Module in Python

Mohd Mohtashim
Updated on 29-Jan-2020 11:09:25

652 Views

The calendar module supplies calendar-related functions, including functions to print a text calendar for a given month or year.By default, calendar takes Monday as the first day of the week and Sunday as the last one. To change this, call calendar.setfirstweekday() function.Here is a list of functions available with the calendar module −Sr.NoFunction with Description1calendar.calendar(year, w=2, l=1, c=6)Returns a multiline string with a calendar for year year formatted into three columns separated by c spaces. w is the width in characters of each date; each line has length 21*w+18+2*c. l is the number of lines for each week.2calendar.firstweekday( )Returns the current setting ... Read More

The Time Module in Python

Mohd Mohtashim
Updated on 29-Jan-2020 11:08:47

513 Views

There is a popular time module available in Python which provides functions for working with times and for converting between representations. Here is the list of all available methods −Sr.NoFunction with Description1time.altzoneThe offset of the local DST timezone, in seconds west of UTC, if one is defined. This is negative if the local DST timezone is east of UTC (as in Western Europe, including the UK). Only use this if daylight is nonzero.2time.asctime([tupletime])Accepts a time-tuple and returns a readable 24-character string such as 'Tue Dec 11 18:07:14 2008'.3time.clock( )Returns the current CPU time as a floating-point number of seconds. To measure computational ... Read More

Minimize Number of Used Bins in C++ for Bin Packing Problem

Arnab Chakraborty
Updated on 29-Jan-2020 11:08:42

4K+ Views

In case of given m elements of different weights and bins each of capacity C, assign each element to a bin so that number of total implemented bins is minimized. Assumption should be that all elements have weights less than bin capacity.ApplicationsPlacing data on multiple disks.Loading of containers like trucks.Packing advertisements in fixed length radio/TV station breaks.Job scheduling.ExampleInput: weight[] = {4, 1, 8, 1, 4, 2} Bin Capacity c = 10 Output: 2 We require at least 2 bins to accommodate all elements First bin consists {4, 4, 2} and second bin {8, 2}Lower BoundWe can always calculate a lower ... Read More

Barabasi-Albert Graph for Scale-Free Models in C++

Arnab Chakraborty
Updated on 29-Jan-2020 11:00:00

332 Views

The Barabási-Albert model is treated as one of several proposed models that produce scale-free networks. It combines two important general concepts: growth and preferential attachment. Both concepts i.e. growth and preferential attachment have wide existence in real networks. The meaning of growth is that the number of nodes in the network increases over time.The meaning of preferential attachment is that the more connected a node is, the more chance it is to receive new links.Higher degree nodes have stronger ability to catch or grab links added to the network. Basically, the preferential attachment can be well understood if we think ... Read More

Balanced Expressions with Opening Brackets in C++

Arnab Chakraborty
Updated on 29-Jan-2020 10:57:50

240 Views

In case of a given integer m and an array of positions ‘position[]’ (1

Client-side Validation with HTML and without JavaScript

Krantik Chavan
Updated on 29-Jan-2020 10:53:36

309 Views

To display HTML5 client-side validation error bubbles, use the required attribute.You do not need to have javascript for client side validations like empty text box would never be submitted because HTML5 introduced a new attribute called required which would be used as follows and would insist to have a value:                    Enter email :          Try to submit using Submit button                    

Create Text Inside Circles in HTML5 Canvas

Nishtha Thakur
Updated on 29-Jan-2020 10:52:50

1K+ Views

To create a text inside circles in canvas, use the:context.beginPath();The following is the canvas:$("#demo").on("click", "#canvas1", function(event) {    var canvas = document.getElementById('canvas1');    if (canvas.getContext) {       var context = canvas.getContext("2d");       var w = 25;       var x = event.pageX;       var y = Math.floor(event.pageY-$(this).offset().top);       context.beginPath();       context.fillStyle = "blue";       context.arc(x, y, w/2, 0, 2 * Math.PI, false);       context.fill();       context = canvas.getContext("2d");       context.font = '9pt';       context.fillStyle = 'white';       context.textAlign = 'center';       context.fillText('amit', x, y+4);    } });HTML    

Completely Fill Web Page with HTML Canvas

V Jyothi
Updated on 29-Jan-2020 10:51:22

401 Views

To make canvas fill the whole page, you need to be 100% in width and height of the page.* {    margin: 0;    padding: 0; } body, html {    height:100%; } #canvas {    position:absolute;    height:100%; width:100%; }

Advertisements