Found 1862 Articles for Data Structure

Smallest set vertices to visit all nodes of the given Graph

Pranavnath
Updated on 25-Aug-2023 11:09:42

69 Views

Introduction Finding the smallest set of vertices to visit all nodes in a graph could be a crucial issue in graph hypothesis. It has practical applications in different areas, counting network optimization, directing algorithms, and task planning. In this article, we are going investigate three diverse approaches to illuminate this problem: Depth-First Search (DFS), Breadth-First Search (BFS), and Depth-First Traversal with Backtracking. We are going give point by point clarifications, code usage within the C language, and algorithmic steps for each approach. Also, we'll illustrate the utilization of these approaches with a test graph to guarantee that all three strategies ... Read More

Number of ways to reach at starting node after travelling through exactly K edges in a complete graph

Pranavnath
Updated on 25-Aug-2023 11:08:40

69 Views

Introduction The number of ways to reach the beginning hub after traveling through precisely K edges in a total chart can be calculated utilizing different approaches within the C dialect. One approach is to utilize brute constrain recursion, where we investigate all conceivable ways. Another approach includes energetic programming, where we store and reuse halfway comes about to dodge excess computations. Moreover, a numerical equation exists to specifically compute the number of ways based on the number of hubs and edges. These strategies give effective arrangements to decide the check of ways driving back to the beginning hub in a ... Read More

Find first undeleted integer from K to N in given unconnected Graph after Performing Q queries

Pranavnath
Updated on 25-Aug-2023 11:06:44

38 Views

Introduction Finding the primary undeleted integer from a given extend in a detached graph after performing multiple queries may be a challenging issue in graph theory. In this article, we investigate the errand of distinguishing the primary undeleted numbers and give two approaches to fathom it utilizing C++. Each approach offers a diverse point of view and utilizes distinctive calculations and data structures. The problem includes developing a graph, checking certain nodes as deleted, and after that deciding the primary undeleted numbers inside an indicated extend. The graph represents associations between nodes, and the deleted nodes are those that have ... Read More

Calculate server loads using Round Robin Scheduling

Prabhdeep Singh
Updated on 24-Aug-2023 15:57:59

467 Views

Round robins scheduling is used in CPU scheduling, we are given some M number of servers and N number of requests. Each request has some arrival time and processing time. We have to find the load on each server using the Round-Robin Scheduling for which we are going to implement a program in C++ programming language using the priority queue and sets. Example Let's understand the problem with the help of an input-output example − Input int arrival_time[] = { 1, 2, 4, 6 }; int process_time[] = { 6, 1, 2, 2 }; int servers = 2; Output ... Read More

Generate Linked List consisting of maximum difference of squares of pairs of nodes from given Linked List

Prabhdeep Singh
Updated on 24-Aug-2023 15:56:44

37 Views

A linked list is a linear data structure that consists of nodes and each node is not present in the contiguous form in the main memory, instead, each node contains the address of the next node. We are given a linked list of even length, we have to create a new linked list that contains half number of nodes as the given node, and the value of each node contains the difference between the square of the nodes of the given linked list in decreasing order. Example Let's understand the problem with the help of an input-output example − ... Read More

K-th Smallest Element in an Unsorted Array using Priority Queue

Prabhdeep Singh
Updated on 24-Aug-2023 15:53:20

254 Views

A priority queue is a heap-based data structure, stores elements in such a way that the greatest or smallest element always be present on the top. We are given an array that is unsorted and we have to find the Kth smallest element from it using the Priority Queue. Here, the element k will be given and it must be in the range from 1 to the size of the given array. Example Let's understand the problem with the help of an input-output example − Input int arr[] = {1, 5, 6, 2, 3, 6, 7, 9, 12, 15, 0, ... Read More

Find the winner of game of repeatedly removing the first character to empty given string

Prabhdeep Singh
Updated on 24-Aug-2023 15:51:29

56 Views

In this game, we are given an array of strings of length N. Each string consists of the digits 1 to N only. The game starts with the first person and removes the first character of the 0th index, then the removed character from the string digit number player will go for the next move. Each player with index y will remove the digit from the string from index y-1 and then the remove digit number player will move next. When any player is not able to remove the character will win the game. Example Let's understand the problem with ... Read More

Java Program for Queries for rotation and Kth character of the given string in constant time

Shubham Vora
Updated on 24-Aug-2023 16:53:07

50 Views

In this problem, programmers require to execute the queries on the string. Also, need to rotate the string and print the characters of the updated string. The best approach to solve the problem is that keep updating the index value and access string characters when we need to print the character. Problem statement – We have given the string alpha and the array containing the pair of numbers named ‘que’. The task is that perform the queries given in the array onto the string alpha. Follow the below query operation rules. (1, a) – Make total left rotations of ... Read More

Java Program for Check if a string can be formed from another string by at most X circular clockwise shifts

Shubham Vora
Updated on 24-Aug-2023 16:45:26

53 Views

In this problem, we need to convert one string to another by performing at most x circular shift operations on each character of the first string. The naïve approach to solving the problem is to rotate each character of the alpha1 string for x times, and we check if it matches the character of the alpha2 string, which is at the same index. The second approach is to solve the problem by finding the circular difference between characters at the same index. Problem statement – We have given a positive integer X. Also, we have given a string alpha1 ... Read More

Encode given String by inserting in Matrix column-wise and printing it row-wise

Shubham Vora
Updated on 24-Aug-2023 16:42:49

85 Views

In this problem, we will encode the string by inserting it in the matrix in a column-wise manner and printing the string in a row-wise manner. The naïve approach to solve the problem is to create a matrix, fill the matrix top-bottom manner, and print the string row-wise. The second solution is to use the vector to store the string and print each vector value individually. Here, we will learn both approaches to solve the problem. Problem statement – We have given string str of length N. Also, we have given the positive integer rows. The task is to encode ... Read More

Advertisements