Every class is an object. It's an instance of something called a metaclass. The default metaclass is typed. You can check this using the is instance function. For example,class Foo: pass foo = Foo() isinstance(foo, Foo) isinstance(Foo, type)This will give the output:True TrueA metaclass is not part of an object's class hierarchy whereas base classes are. These classes are used to initialize the class and not its objects.You can read much more in-depth about Metaclasses and inheritance on https://blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/
The Reservoir sampling is a randomized algorithm. In this algorithm, k items are chosen from a list with n different items.We can solve it by creating an array as a reservoir of size k. Then randomly pick one element from the main list and placed that item in the reservoir list. When one item is selected once, it will not be selected for next time. But his approach is not effective, we can increase the complexity by this method.In the reservoir list, copy first k items from the list, now one by one from the (k+1)th number in the list, ... Read More
One sales-person is in a city, he has to visit all other cities those are listed, the cost of traveling from one city to another city is also provided. Find the route where the cost is minimum to visit all of the cities once and return back to his starting city.The graph must be complete for this case, so the sales-person can go from any city to any city directly.Here we have to find minimum weighted Hamiltonian Cycle.Input and OutputInput: Cost matrix of the matrix. 0 20 42 25 30 20 0 30 34 15 42 30 0 10 10 ... Read More
A list of given strings is sorted in alphanumeric order or Dictionary Order. Like for these words: Apple, Book, Aim, they will be sorted as Aim, Apple, Book.If there are some numbers, they can be placed before the alphabetic strings.Input and OutputInput: A list of strings: Ball Apple Data Area 517 April Man 506 Output: Strings after sort: 506 517 Apple April Area Ball Data ManAlgorithmsortStr(strArr, n)Input: The list of all strings, number of elements.Output − Strings in alphanumeric sorted order.Begin for round := 1 to n-1, do for i := 0 to n-round, do ... Read More
Zeller’s Algorithm is used to find the weekday from a given date. The formula to find weekday using Zeller’s Algorithm is here:The formula is containing some variables; They are −d − The day of the date.m: It is the month code. From March to December it is 3 to 12, for January it is 13, and for February it is 14. When we consider January or February, then given year will be decreased by 1.y − Last two digits of the yearc − first two digits of the yearw − The weekday. When it is 0, it is Saturday, when ... Read More
Let two line-segments are given. The points p1, p2 from the first line segment and q1, q2 from the second line segment. We have to check whether both line segments are intersecting or not.We can say that both line segments are intersecting when these cases are satisfied:When (p1, p2, q1) and (p1, p2, q2) have a different orientation and(q1, q2, p1) and (q1, q2, p2) have a different orientation.There is another condition is when (p1, p2, q1), (p1, p2, q2), (q1, q2, p1), (q1, q2, p2) are collinear.Input and OutputInput: Points of two line-segments Line-segment 1: (0, 0) to (5, ... Read More
Roman numbers are non-positional numbers. Some numerals are placed together to form a number in roman numbers. For an example the number 75 can be expressed as 75 = 50 + 10 + 10 + 5, so the roman numerals are LXXV.In this problem one number is provided in a decimal format, our task is to convert it into the Roman numeral strings.There are different symbols and their value, like this.IIVVIXXXLLXCCCDDCMMMMMMV’145910405090100400500900100040005000Using this table, we can easily find the roman numerals of a given number.Input and OutputInput: Decimal number: 3569 Output: The Roman equivalent of 3569 is: MMMDLXIXAlgorithmdecToRoman(nuList, num)Input: The numeral list ... Read More
There are N ropes of given lengths. We have to connect with them. The cost of connecting one rope with other is the sum of their lengths. Our goal is to connect the N ropes with minimum cost.This problem can be solved using a heap tree. We will create min heap to insert all different lengths first, then remove minimum and second minimum item from min heap, connect them and again insert into the heap tree. When the heap will hold only one element, we can stop the process and get the connected rope with minimum costs.Input and OutputInput: The ... Read More
A directed graph is given. Another two vertices u and v are also given, u is the starting vertex, and v is the ending vertex. Our task is to find a number of walks from vertex u to v with exactly k edges. The value of k is also provided in the algorithm.By using dynamic programming, we need to create a 3D table, Where the row will point the values of u, columns will point the values v and depth will be used to track the number of edges from start to end.Input and OutputInput: The adjacency matrix of the ... Read More
Two numbers are given as a binary string, our task is to find the result of multiplication for those numbers in a faster and efficient way.Using the Divide and Conquer strategy, we can solve the problem, in a very efficient manner. We will split the numbers into two halves.let Xleft and Xright are two parts of first number X, and Yleft, Yright are two parts of second number Y. So the product;To make it simple, we can perform this operationInput and OutputInput: Two binary numbers: 1101 and 0111 Output: The result is: 91AlgorithmaddBitString(num1, num2)Input: Two numbers to add.Output: The result after ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP