C++ Program to Represent Graph Using 2D Arrays

Ravi Ranjan
Updated on 26-May-2025 18:32:31

2K+ Views

The graph can be represented using various ways. One of the technique is to use a 2D array, also known as adjacency matrix. The adjacency matrix is a square matrix of size V x V to represent a finite graph data structure using a 2D array, where V is the number of nodes/vertex of the graph. In an undirected non-weighted graph, if there is an edge between vertex i and vertex j, the value at matrix[i][j] is 1 and if no edge exists, the value is 0. In this article, our task is to represent the graph using 2D arrays. ... Read More

C++ Program to Generate a Random Directed Acyclic Graph (DAG) for a Given Number of Edges

Ravi Ranjan
Updated on 26-May-2025 18:29:29

690 Views

A Directed Acyclic Graph or DAG is a directed graph (a graph where each edge has a direction) that has no cycles present i.e. if we traverse along the direction of the edges then no closed loops are formed along any path. A DAG is always topologically ordered, i.e. for each edge in the graph, the start vertex of the edge(u) occurs earlier in the sequence than the ending vertex(v) of the edge i.e.(u {B C} B -> {Isolated Vertex} C -> {Isolated Vertex} D -> {B E} E -> {C} Steps to Generate Random Directed Acyclic Graph The ... Read More

How to compare regular expressions in Perl and Python?

Nikitasha Shrivastava
Updated on 26-May-2025 18:21:40

381 Views

This article will discuss how to compare regular expressions in Perl and Python. Regular expressions, or regex, are patterns used to match strings. Both Perl and Python support regex, but they have some differences in syntax and usage. For example, you write a regular expression like this in Perl - $text =~ /pattern/ But you write it like this in Python - re.search('pattern', text) So in the below section of this article will show the similarities and differences between Perl and Python regex with simple examples - ... Read More

Difference between 'struct' and 'typedef struct' in C++ program?

Farhan Muhamed
Updated on 26-May-2025 18:20:27

5K+ Views

In C++ program, struct is a keyword used to define a structure, while typedef is a keyword that is used to create an alias for a data type. In this article, we will discuss the difference between struct and typedef struct in C++. Struct in C++ Struct is a keyword used to define a structure in C++. A structure is a user-defined data type that groups related variables of different data types into a single unit. Struct is same as a class, but the members of a struct are public by default. The syntax for defining a struct is ... Read More

Difference between string and char[] types in C++

Farhan Muhamed
Updated on 26-May-2025 18:18:53

839 Views

In C++, char[] represents a character array, while string is a class in STL to manage text data. Both string and char[] can be used to store and process text data. But, they are different in terms of structure, usage, memory management, and capabilities. In this article, we will discuss the difference between string and char[] types in C++. char[] in C++ char[] is an array of characters that is used to store a string. It is a C-style string representation. The size of char array will be fixed. At the end of the array, a null character '\0' ... Read More

Differences between C++ string == and compare()?

Farhan Muhamed
Updated on 26-May-2025 18:17:37

4K+ Views

In C++ we can compare two strings using compare() function and the == operator. Then the question is why there are two different methods? Is there any difference or not? Yes, there are some basic differences between compare() and == operator. In C++ the == operator is overloaded for the string to check whether both strings are same or not. If they are the same this will return 1, otherwise 0. So it is like Boolean type function. The compare() function returns two different things. If both are equal, it will return 0, If the mismatch is ... Read More

Why is it faster to process a sorted array than an unsorted array in C++ program?

Farhan Muhamed
Updated on 26-May-2025 18:16:59

203 Views

In C++, it is faster to process a sorted array than an unsorted array due to some reasons related to algorithm efficiency and data access patterns. In this article, we see why this is the case and how sorting can improve performance of array processing. First of all, let see an example of processing time of a sorted and unsorted array. Processing Time: Sorted vs Unsorted Array In the example code below, we have used library of C++ STL to measure the time taken to process an unsorted array and a sorted array. The code counts how many ... Read More

How to capture an exception raised by a Python Regular expression?

Nikitasha Shrivastava
Updated on 26-May-2025 18:15:13

1K+ Views

This article gives a guide on how to capture an exception raised by a regular expression in Python. We will also see simple example programs that show how to do this. Regular expressions are useful for matching patterns in text, but they may result in errors like incorrect syntax or mismatches. Python uses exception handling (try-except) to handle these errors to avoid errors. For example, if the given pattern is "[a-z", which is an incorrect pattern that can lead to an error showing that the character set is invalid, because the closing bracket ] is missing. Python Regex Exception ... Read More

How do I clear the regular expression cache in Python?

Nikitasha Shrivastava
Updated on 26-May-2025 18:11:32

783 Views

This article talks about how you can clear the regular expression cache in Python. Regular expressions in Python are used to find patterns in text, but they also use an internal cache to store frequently used expressions for faster execution. We may sometimes need to clear this cache to free up memory or reset stored patterns. You can do this using Python's re.purge() method. Why Clear Regex Cache? You need to clear the regex cache for the following reasons - Too many stored patterns may consume your system's memory. If you are dynamically updating regex patterns, deleting the cache ... Read More

How to use Python Regular expression to extract URL from an HTML link?

Nikitasha Shrivastava
Updated on 26-May-2025 18:04:33

3K+ Views

In this article, we are going to learn how to extract a URL from an HTML link using Python regular expressions. URL is an acronym for Uniform Resource Locator; it is used to identify the location resource on the Internet. URL consists of a domain name, path, port number, etc. The URL can be parsed and processed by using a Regular Expression. Therefore, if we want to use a Regular Expression, we have to use the "re" library in Python. Following is an example of a URL - URL: https://www.tutorialspoint.com/courses If we parse the above URL we can find ... Read More

Advertisements