The Euler path is a path by which we visit every edge exactly once while using the same vertices multiple times. When the starting and ending vertex of the Euler path is the same node (i.e., if a path starts from node 'A' and ends on node 'A'), it is also known as the Eulerian cycle. In this article, our task is to check if the Eulerian cycle exists in the given undirected graph or not. Example of Eulerian Cycle The figure below displays an undirected graph and its respective adjacency matrix. As we can see there exists ... Read More
A dynamic 2D array is an 2D array in which the size of array is determined during runtime and stored using pointers. In this article, we will learn how to create a dynamic 2D array inside a class in C++. First of all, let's understand the problem statement. In this problem, you need to create a class that contains a dynamic 2D array as its data member. The memory allocation and deallocation must be handled using constructor and destructor. For example: // Create a class with dynamic 2D array ClassMatrix m(3, 4); // Output Matrix of size ... Read More
A multidimensional array is an array with more than one dimension. It means that the array can grow in multiple directions, such as length, width, and height. In this article, we will learn how to print the dimensions of given multidimensional array in C++. First of all, let's understand the problem statement. You are given a multidimensional array as input, and you need to print its dimensions such as the number of rows, number of columns, and so on. For example: // Input multidimensional array int arr[3][4] = { {1, 2, 3, 4}, ... Read More
A TAR file is abbreviated as Tape Archive, which is an archive format used mainly in Unix and Linux environments. The Tar file is used to collect more number of files into a single file, which makes it easier to share or backup together. In Python, when we want to work with TAR files, we can use the tarfile module, which allows us to create, read and extract TAR archives programmatically. In this article, we will explore how to extract the files from tar file by using Python. Extracting all files from a"tar" file The extractall() method in Python is ... Read More
Hash Table A hash table is a data structure which is used to store key-value pairs and uses hash function to compute an index into an array of buckets or slots in which an element will be inserted or searched in average-case constant time. Why are Collision a Problem? A collision is a problem because even a perfect hash function can generate the same index for multiple keys, causing a collision. To resolve these, we use techniques like − Chaining Linear Probing Quadratic Probing Quadratic Probing ... Read More
Sometimes, you may come across a scenario where you want to have a function that can take a variable number of arguments, i.e., parameters, instead of a predefined number of parameters. The C/C++ programming language provides a solution for this scenario, and you are allowed to define a function that can accept a variable number of parameters based on your requirement. Following are the ways to use variable number of arguments − C-style Variadic Functions (with stdarg.h) C-style variadic functions in C++ use stdarg.h macros like va_start, va_arg, and va_end to handle a variable number of arguments at runtime. int ... Read More
In Python, a list is a built-in data structure that is used to store a sequence of items. Lists are mutable, i.e., the elements can be changed after the list is created. Syntax to create a Python List The correct syntax to create a Python List is using square brackets "[ ]". We need to specify the elements in the list by separating them with commas. Here is the basic syntax to create a list in Python - my_list = [item1, item2, item3, ...] Example: List of Integers A list of integers in Python is a sequence of whole numbers ... Read More
C++ Pure Virtual FunctionsA pure virtual function in C++ is a virtual function that has no definition in the base class and must be overridden in derived classes. It is declared by assigning = 0 in its declaration. Syntax Following is the syntax of the pure virtual function: class Shape { public: virtual double area() = 0; }; C++ Abstract Class A class that contains at least one pure virtual function is called an abstract class. Abstract classes cannot instantiated directly; instead, they work as a blueprint of the derived class. Any class inheriting from an ... Read More
A queue is a linear data structure that contains a collection of elements. Queue implements the FIFO mechanism i.e., the element that is inserted first is also deleted first. In other words, the least recently added element is removed first in a queue. Implementation Steps Based on the below implementation. Here are the steps to implement queue using array: Initialize Queue: Create an array queue[100] and set front and rear to -1 to indicate an empty queue. Predefine Input Values: Store input elements in input_values[] for insertion. ... Read More
What is an Interval Tree? An interval tree is a tree data structure that stores intervals. It helps us to efficiently find all intervals that overlap with a specific interval or point. The purpose is to enhance a self-balancing Binary Search Tree (BST) known as Interval Tree, which is similar to Red Black Tree, AVL Tree, and so on, with a set of intervals so that all operations can be performed in O(log n) time. Every node of interval trees stores the following details: i: An interval which is represented as a pair [start, end]. ... Read More