Get File Creation and Modification Dates in Python

Nikitasha Shrivastava
Updated on 16-Jun-2025 12:17:24

16K+ Views

There are various ways to get the file creation and modification datetime in Python. We will use different methods from the OS and pathlib module to get the file creation and modification datetime in Python. Using OS Module: File Creation Time On Windows Using OS Module: File Modification Time On Windows ... Read More

Convert Python Date String to Date Object

Nikitasha Shrivastava
Updated on 16-Jun-2025 12:02:41

9K+ Views

In this article, we convert a date string to a date object. We will use the strptime() method to convert a date string to a date object, and we will also use the dateutil module for flexible date parsing. A date string is a date written in text form, like "09 May 2025" or "2025-05-09". To work with dates in Python, we will have to convert these strings into date objects. To achieve this, we can use Python's datetime and dateutil modules. Using the strptime() Function The strptime() method takes the date as input and converts it into a ... Read More

Calling a Member Function on a Null Object Pointer in C++

Ravi Ranjan
Updated on 13-Jun-2025 18:53:46

1K+ Views

You can call a class member function using a NULL object pointer in C++. This is an undefined behavior and there is no guarantee about the execution of the program. The actual results depend on the compiler used. Class Member Function A class member function is a function that is defined either inside a class or outside a class using a scope resolution operator. Example Here is an example of class member functions in C++ where the print() function is an example of the Inside class function and the print2() function is ... Read More

Tokenizing a String in C++

Farhan Muhamed
Updated on 13-Jun-2025 18:51:05

7K+ Views

Tokenization refer to the process of breaking a string based on certain delimiters such as spaces, commas, semicolons, or any other character. Mostly white spaces are used as delimiters to tokenize strings. In this article, we will discuss all the ways tokenize a string in C++. For example, if we have a string like "Hello, World! Welcome to Tutorialspoint.", we can tokenize it like this: string str = "Hello, World! Welcome to Tutorialspoint."; tokens = {"Hello", "World", "Welcome", "to", "Tutorialspoint"}; Tokenizing a String in C++ In C++, we can tokenize a string using various methods. Here are ... Read More

Check Topological Sorting in a Graph using C++

Farhan Muhamed
Updated on 13-Jun-2025 18:50:30

669 Views

In this article, we will learn what is topological sorting, how to use it to detect cycles in a directed graph, and how to implement it in C++. What is Topological Sort? Topological sorting is an operation used to detect cycle in a graph. In this operation we order the vertices in such a way that for every directed edge u -> v, vertex u comes before vertex v in the ordering. If we are able to perform a topological sort in a graph, it means that the graph is a directed acyclic graph (DAG). The image below show ... Read More

Detect Cycle in a Directed Graph using Python

Sarika Singh
Updated on 13-Jun-2025 18:45:15

1K+ Views

A cycle occurs when a path starts and ends at the same vertex, following the direction of the edges. In directed graphs, cycles can cause problems like infinite loops or dependency errors, so detecting them is important in areas like task scheduling and deadlock detection. We can use Depth-First Search (DFS) with a recursion stack to detect whether a cycle exists in a directed graph or not. Problem Statement You are given a directed graph represented using an adjacency list. Your task is to write a Python program to check whether the graph contains a cycle or not. DFS-Based Cycle ... Read More

Python Program for Cutting a Rod

Sarika Singh
Updated on 13-Jun-2025 18:44:18

891 Views

Rod Cutting ProblemThe Rod Cutting problem is a classic example of dynamic programming. The goal is to cut a rod into pieces to maximize the total value. Each piece has a specific length and value, and we must choose the cuts in such a way that the total value is as high as possible. This problem is similar to the 0-1 Knapsack problem and can be solved using recursion and dynamic programming techniques. It is useful in resource allocation and pricing strategies. Rod Cutting Problem Statement You are given a rod of length n and an array price[] where price[i] ... Read More

Python Program for Cocktail Sort

Sarika Singh
Updated on 13-Jun-2025 18:41:55

383 Views

What is Cocktail Sort? Cocktail sort is a variation of bubble sort that sorts the array in both directions on each pass. It is also known as Bidirectional Bubble Sort or Shaker Sort. The algorithm works by traversing the list forward and backward, alternatively, pushing the largest and smallest elements to their respective ends. This approach helps in reducing the number of iterations compared to Bubble Sort, especially when smaller elements are at the end of the list. Problem Statement You are given an unsorted list of elements. The goal is to sort the list using Cocktail Sort, which moves ... Read More

Python Program for Bogosort (Permutation Sort)

Sarika Singh
Updated on 13-Jun-2025 18:19:26

272 Views

BogoSort, also known as Permutation Sort or Stupid Sort, is a sorting algorithm based on generating random permutations of the list until it gets sorted. BogoSort continues to shuffle the array randomly until the list becomes sorted. The expected time complexity is unbounded, and its average performance is extremely poor. Problem Statement You are given a list of unsorted elements. Your task is to sort the list using BogoSort by repeatedly generating random permutations until the list is sorted. Random Permutation-based Sorting This sorting method checks if the list is sorted. If not, it randomly shuffles the elements and checks ... Read More

Python Program for Binary Insertion Sort

Sarika Singh
Updated on 13-Jun-2025 18:17:34

1K+ Views

Binary Insertion SortBinary insertion sort is an improved version of the regular Insertion Sort algorithm. In a normal insertion sort, each element is compared linearly with the sorted portion of the list to find its correct position. This takes O(n) comparisons for each element. In Binary Insertion Sort, we use Binary Search to find the correct position of the current element in the sorted part of the list. This reduces the number of comparisons from O(n) to O(log n) per insertion. However, shifting elements still takes O(n) time in the worst case. Problem Statement You are given a list of ... Read More

Advertisements