C++ Program to Perform Dictionary Operations in a Binary Search Tree

Farhan Muhamed
Updated on 15-May-2025 19:35:26

2K+ Views

A dictionary is a collection of key-value pairs where, keys are unique and used to identify corresponding values in the dictionary. In this article, we will learn how to perform dictionary operations such as insertion, search, and traversal using a binary search tree (BST) in C++. What is BST? A binary search tree (BST) is a tree data structure, where each node has at most two children and follows two rules: the left subtree contains keys less than the node’s key, and the right subtree contains keys greater than the node’s key. This structure is same as how a ... Read More

How to print size of array parameter in a function in C++?

Ravi Ranjan
Updated on 15-May-2025 19:34:00

319 Views

To print the size of an array parameter in a function in C++, we will use the typeOf() operator. In this article, we have passed an array as an argument to the function. Our task is to print the size of this array in C++. Printing Size of Static Array Parameter When we pass an array as an argument of function in C++, it is considered as a pointer. The sizeOf() operator returns the size of the pointer, depending on the system(64-bit or 32-bit) rather than returning the size of the array. Here is a code example explaining this. ... Read More

What is the lifetime of a static variable in a C++ function?

Ravi Ranjan
Updated on 15-May-2025 19:33:43

17K+ Views

The lifetime of a static variable in a C++ function exists till the program executes. We can say the lifetime of a static variable is the lifetime of the program. The static variable is a variable that is declared using the static keyword. The space for the static variable is allocated only one time, and this is used for the entirety of the program. In this article, we will understand the lifetime of the static variable and the reason behind its lifetime. Why do Static Variable Exists until program execution? A static variable is initialized ... Read More

How to convert timestamp string to datetime object in Python?

SaiKrishna Tavva
Updated on 15-May-2025 18:49:39

23K+ Views

In many real-world applications, timestamps are used to represent dates and times, but they are not human-readable. To make them understandable or use them in various datetime manipulations, it’s essential to convert them into Python’s datetime object. Python’s datetime module provides multiple functions to convert timestamps to datetime objects. Below are the various methods to accomplish this task - Using datetime.fromtimestamp() Function Using datetime.fromtimestamp() & strftime() Using datetime.strptime() Function Parsing Mixed Text Using strptime() Function Using datetime.fromtimestamp() Function To obtain a date ... Read More

C++ Program to find Median of Elements where Elements are stored in 2 different arrays

Aman Kumar
Updated on 15-May-2025 18:47:19

208 Views

The median is defined as the middle value of a sorted list of numbers, and the middle value is found by ordering the numbers in ascending order. Once the numbers are ordered, the middle value is called the median of the given data set. Here, in this article, we have two different sorted arrays and need to find the median of the array that is formed after merging of two given arrays. Median depends on the sorted merged array. So, the following cases may occur: If the length of the merged array is odd, then ... Read More

How to open new pseudo-terminal pair using Python?

Niharikaa Aitam
Updated on 15-May-2025 18:38:47

1K+ Views

Pseudo-terminals (pty) are an advanced and powerful technique in Python when we are dealing with terminal-based processes or simulating interactive sessions programmatically. A pseudo-terminal allows a process to connect to a real terminal. Python provides a built-in pty module that helps in creating and managing these terminal pairs. In this article, we will learn how to open a new pseudo-terminal pair using Python. Using pty.openpty() The pty module in Python provides the openpty() function that returns a tuple containing file descriptors for the master and slave ends of a new pseudo-terminal pair. Example Following is an example, which shows ... Read More

How do we specify the buffer size when opening a file in Python?

Niharikaa Aitam
Updated on 15-May-2025 18:37:46

9K+ Views

When we open a file using the Python's built-in function open(), then the data temporarily stored in memory can be managed by setting the buffering parameter in the function. Buffering helps to improve the performance of opening a file by reducing the number of interactions with the disk during file input/output operations. Understanding the Buffering Parameter The buffering parameter in Python's open() function allows us to define how much data is stored in memory before being written to or read from the file. This buffering parameter is used to handle file operations with large data or frequent writes. Syntax Here ... Read More

What does the \\'U\\' modifier do when a file is opened using Python?

Niharikaa Aitam
Updated on 15-May-2025 18:35:11

1K+ Views

When the U modifier is used while opening a file then Python opens the file in Universal Newline mode. This mode enables Python to automatically detect and handle all common newline characters including , \r and \r during file reading. It is particularly useful when working with text files generated on various operating systems such as Windows, macOS or Linux which use different newline conventions. The U mode was used in Python 2 and early Python 3 versions to enable newline normalization. It allowed consistent handling of line endings regardless of the platform on which the file was created. However, ... Read More

How to find difference between 2 files in Python?

Niharikaa Aitam
Updated on 15-May-2025 18:32:09

11K+ Views

In most of the applications, especially in data processing, software development or testing, it is required to compare two files to detect changes, validate outputs or find discrepancies. Python offers several ways to compare files which ranges from basic line-by-line comparisons to more advanced diff utilities. Following are the key methods which are used to compare two files in python - Line-by-line comparison: This is a straightforward approach to textual differences. difflib module: This module is used to produce human-readable diffs similar to Unix’s diff command. filecmp module: This module is used for quick binary or shallow comparisons. ... Read More

How to scan through a directory recursively in Python?

Alekhya Nagulavancha
Updated on 15-May-2025 18:30:14

15K+ Views

A directory is simply defined as a collection of subdirectories and single files or either one of them. A directory hierarchy is constructed by organizing all the files and subdirectories within a main directory and this is also known as root directory. These subdirectories are separated using a / operator in a directory hierarchy. In python, we have different methods to scan through a directory recursively. In this article we are going to see about each method. Using os.walk() method Using glob.glob() method Using os.listdir() method ... Read More

Advertisements