In this problem, there is a given set with some integer elements. And another some value is also provided, we have to find a subset of the given set whose sum is the same as the given sum value.Here backtracking approach is used for trying to select a valid subset when an item is not valid, we will backtrack to get the previous subset and add another element to get the solution.Input and OutputInput: This algorithm takes a set of numbers, and a sum value. The Set: {10, 7, 5, 18, 12, 20, 15} The sum Value: 35 Output: All ... Read More
In this section, we will try to solve the famous number maze problem called Sudoku. Sudoku is a 9 x 9 number grid, and the whole grid are also divided into 3 x 3 boxes There are some rules to solve the Sudoku.We have to use digits 1 to 9 for solving this problem.One digit cannot be repeated in one row, one column or in one 3 x 3 box.Using the backtracking algorithm, we will try to solve the Sudoku problem. When some cell is filled with a digit, it checks whether it is valid or not. When it is ... Read More
The for each...in loop iterates a variable overall value of the properties of objects. Note − The “for…each..in” is now deprecated. Do not use. SyntaxHere’s the syntax −for each (variablename in object) { statement or block to execute }ExampleHere’s an example, which will not run on any of the web browsers, since “for each..in” is now deprecated − var myObj = {myProp1:30, myProp2: 40}; var sum = 0; for each (var value in myObj) { sum += value; } document.write(sum);
To add a video in an HTML page, use the element. It specifies a standard way to embed a video in HTML. Just keep in mind to add height and width to the video. Use the source element to add the source of the video, with the src attribute and the type of video with the type attribute.The HTML tag also supports the following additional attributes −AttributeValueDescriptionheightpixelsSpecifies the height.srcURLSpecifies the address of the source file.typeMIME_typeSpecifies the MIME type.widthpixelsSpecifies the width.
Java provides two types of branching/control statements namely, break and continue.The break statementThis statement terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.ExampleFollowing is the example of the break statement. Here we are trying to print elements up to 10 and, using break statement we are terminating the loop when the value in the loop reaches 8.Live Demopublic class BreakExample { public static void main(String args[]){ for(int i=0; i
Multiple inheritances lead to ambiguity.For example, if there is a class named Sub and there are two classes Super1 and Super2 and if both contains a method named sample(). And if the class sub inherits both classes Super1 and Super2 then there will be two copies of the sampling method one from each superclass and it is ambiguous to decide which method to be executed.
Generator Functions allows execution of code in between when a function is exited and resumed later. So, generators can be used to manage flow control in a code. Cancel asynchronous operations easily since execution can be paused anytime.Here’s the syntax; do not forget to add an asterisk after the “function” keyword. You can add an asterisk using any of the following −function *myFunction() {} // or function* myFunction() {} // or function*myFunction() {}ExampleLet’s see how to use a generator functionLive Demo function* display() { ... Read More
The default parameter came to handle function parameters with ease. Default parameters allow you to initialize formal parameters with default values. This is possible only if no value or undefined is passed. With ES6, you can easily set default parameters. Let’s see an exampleExampleLive Demo // default is set to 1 function inc(val1, inc = 1) { return val1 + inc; } document.write(inc(10, 10)); document.write(""); ... Read More
To implement basic Animation in JavaScript, use the DOM object properties and JavaScript. The following list contains different DOM methods.We are using the JavaScript function getElementById() to get a DOM object and then assigning it to a global variable imgObj.We have defined an initialization function init() to an initialize imgObj where we have to set its position and left attributes.We are calling an initialization function at the time of window load.Finally, we are calling moveRight() function to increase the left distance by 10 pixels. You could additionally set it to a negative value to move it to the left side. ... Read More
To find whether the browser supports JavaScript or not, use the tag. The HTML tag is used to handle the browsers, which do recognize tag but do not support scripting. This tag is used to display an alternate text message.ExampleLive Demo HTML noscript Tag Your browser does not support JavaScript!
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP