The formula for the sum of n terms of AP: How do we check whether a series is an arithmetic progression or not? 1. We also add end to previous sum. Given a binary tree. The idea is similar to linear time solution for shortest path in a directed acyclic graph. Example 2: Input : n = 4 arr = [1,2,4,8] Output: [1,2,4,8] Your Task: You don't have to read input or print anything. The task is to check if the linked list has a loop. Example 1: Input: E = [[0,1,9]] S = 0 Output: 0 9 Explanation : Shortest distance of all nodes from source is printed. Example 1: Input: N = 4, Level up your coding skills and quickly land a job. Given adjacency list adj as input parameters . Menu. Mark the current element as next. Kth largest sum contiguous subarray using Prefix Sum and Sorting approach: The basic idea behind the Prefix Sum and Sorting approach is to create a prefix sum. Return -1 if it is not possible. We fix the left and right columns one by one and find the largest sub-array with 0 sum contiguous rows. You have to find the K-th largest sum of contiguous subarray within the array elements. Example 1: Input: N = 3 K = 2 Arr = {3,2,1} Output: 5 Explanation: The different subarray sums we c. Exclusively for Freshers! Participate for Free on 21st November & Fast-Track Your Resume to Top Tech Companies. Example 1: Input: n = 6 arr[] = {0,0,5,5,0,0} Output: 6. The task is to find the largest sum of a cycle in the maze(Sum of a cycle is the sum of the cell indexes of all cells present in that cycle). {1}, max = 1 2. 594 views 1 month ago GFG POTD series. The approach is to find the minimum subarray size whose sum is greater than integer k. If their sum is smaller than X then we shift the left pointer to right or if their sum is. Find the first non-repeating element in a given array of integers. Step 1: Pick edge 7-6. Given the graph, Print out the maximum weight Cycle of the graph. The idea is to convert given problem to a simpler problem where we have to just check if there is cycle of odd length or not. Cracking Any Coding Interviews. Output: -270. If an a. Solve one problem based on Data Structures and Algorithms every day and win exciting prizes. If max_ending_here < 0 then update. Example 1: Input: N = 5 Arr[]. Input: 10 / \ 2 5 \ -2 Output: 17 Explanation: Path in the given tree goes like 2 , 10 , 5. We get maximum sum by adding subarray {4, 2, 10, 23} of size 4. The task is to find the sum of weights of the edges of the Minimum Spanning Tree. n-1] containing n positive integers, a subsequence of arr [] is called Bitonic if it is first increasing, then decreasing. Since we want to minimize the sum of two numbers to be formed, we must divide all digits in two halves and assign half-half digits to them. Floyd Warshall. Given an array A[] of size N, return length of the longest subarray of non- negative integers. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. The task is to return a linked list that represents the sum of these two numbers. If no such row exists, return -1. The problem is to find the shortest distances between every pair of vertices in a given edge-weighted directed graph. For example, in the following 2D array, the maximum sum submatrix is highlighted with blue rectangle and sum of all elements in this submatrix is 29. 0 Not attempted (1) AttemptedInput: a [] = {10, -10, 20, -40} k = 6 Output: -10 Explanation: The 6th largest sum among sum of all contiguous subarrays is -10. We know that the path should turn clockwise whenever it would go out of bounds or into a cell that was previously visited. The questions will be featured from a pool of public problems from the GFG Practice Portal. Hence, maximum circular subarray sum is 22. The assertion is clearly true for a graph with at most one edge. To add x to sum, -x can be subtracted from it because sum- (-x) = sum + x. If no cycle exists, return -1. Assume any vertex (let’s say ‘0’) as source and assign dist = 0. The task is to find subtree with maximum sum in the tree and return its sum. Initialize a variable sum with value 0 to store the final answer. The Greedy Choice is to pick the smallest weight edge that doesn’t cause a cycle in the MST constructed so farWelcome to our daily problem solving session where Siddharth will be tackling the Problem of The Day. It was developed by W. We have given numbers in form of a triangle, by starting at the top of the triangle and moving to adjacent numbers on the row below, find the maximum total from top to bottom. Given adjacency list adj as input parameters . And we have to count all such cycles that exist. Each cell may have multiple entry points but not more than one exit (ie. Calculate the sum of X and Y. Maximum path sum from top left to bottom right of a matrix passing through one of the given cells. For example, the number 190 will be represented by the linked list, 1->9-. Examples : Input : 313551 Output : 531135 Explanations : 531135 is the largest number which is a palindrome, 135531, 315513 and other numbers can also be formed but we need the highest of all of the palindromes. Streak count. Example 1: Input: N = 3 K = 2 Arr = {3,2,1} Output: 5 Explanation: The different subarray sums we can get from the array are = {6,5,3,2,1}. Hey guys, In this video, we'll be solving Largest Sum Contiguous Subarray Problem using Kadane's Algorithm. 0 You are given a maze with N cells. Level up your coding skills and quickly land a job. Example. Length of the longest common span with same sum is 6. But in the case of the number of elements being large, the array in which we store the contiguous. e. The function “largestSum” takes array “arr” and it size is “n”. Examples: Input : 12345 Output : 15 Input : 45632 Output :20. As in this problem we have to choose one element which is the maximum in the subarray. Example 1: Input: n = 5 A [] = {1, 8, 7, 56, 90} Output: 90 Explanation: The largest element of given array is 90. For a given number of the form ‘nr/dr’ where dr > nr, first find the greatest possible unit fraction, then recur for the remaining part. Level up your coding skills and quickly land a job. Clearing the DSA round for the Interviews, as these are the questions generally asked in the companies like Amazon, Microsoft,. To solve the problem, we will do the post-order traversal. If there are more than one such pairs with maximum sum then print any of such pair. Menu. Beginner's DSA Sheet; Love Babbar Sheet; Top 50 Array Problems; Top 50 String Problems; Top 50 DP Problems; Top 50 Graph Problems; Top 50 Tree Problems; Contests. There is a cycle in a graph only if there is a back edge present in the graph. Personalised Dashboard. Given a binary tree. Given a binary tree with a value associated with each node, we need to choose a subset of these nodes such that sum of chosen nodes is maximum under a constraint that no two chosen node in subset should be directly connected that is, if we have taken. If the array consists of only positive numbers the problem can be efficiently solved using only the sliding window technique as discussed here. If there is no cycle in the graph then return -1. Your task is to complete the function largest () which. Instructions. Initialize a variable sum to 0. Explanation: This diagram clearly shows no cycle. Example 1: Input: n = 3 arr = [1,2,3] Output: [1,2] Explanation: Largest Divisble Subset is [1,2]. If “n==1” ,then return arr [0]th element. Jones and published in 1963. Suppose we have x as 6, then the numbers which are less than 6 and have remainders which add up to 6 gives sum as 6 when added. Maximize product of array by replacing array elements with its sum or product with element from another array. . 2nd case : If sum becomes greater than or equal to k, this means we need to subtract starting element from sum so that the sum. The solution is based on Maximum sum rectangle in a 2D matrix. However, the longest path problem has a linear time solution for directed acyclic graphs. 0 You are given a maze with N cells. Monotonic Stack 55. You have to find the K-th largest sum of contiguous subarray within the array elements. org or mail your article to review-team@geeksforgeeks. Run two nested loops to find all subarrays. Your Task: You don't need to read input or print anything. Return -1 if there are no cycles. Based on the above idea, for the new array, median of any subarray to be greater than or equal to X, its sum of elements. The currently found number can not occur again so it is. Function Description: The sum of the largest sum cycle in the maze. Output : 7 Explanation : 3rd smallest element in the given array is 7. The basic idea behind cycle sort is to divide the input array into cycles, where each cycle consists of elements that belong to the same. Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Platform to practice programming problems. . Pick the rest of the elements one by one and follow the following steps in the loop. Calculate the sum of X and Y. Example 1: Input: N = 7 a [] = {2,6,1,9,4,5,3} Output:Given an array arr[] of size N and an integer K. This is the best place to expand your knowledge and get prepared for your next interview. So there are total 2n + 1 possible. Follow the steps below to solve the problem: Initialize a variable, say maxm, to store the largest element of the given array. Tutorials. Output. An efficient solution is based on Largest rectangular sub-matrix whose sum is 0 which reduces the time complexity to O (n^3). Input: arr[] = {3, 2, 7, 10} Output: 13 Explanation: The subsequence is {3, 10}. Explanation: The product of the subarray {1, 5, -6, 9} is -270 which is the minimum possible. 25 or 1. Example 1: Input: N = 4 A [] = {0,1,0,1} Output: 4 Explanation: The array from index [0. Auxiliary Space: O (V+E) If you like GeeksforGeeks and would like to contribute, you can also write an article using write. Now let’s see how the two-pointer technique works. " GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 330 million projects. Input: a [] = {10, -10, 20, -40} k = 6 Output: -10 Explanation: The 6th largest sum among sum of all contiguous subarrays is -10. Given a weighted, undirected and connected graph of V vertices and an adjacency list adj where adj [i] is a list of lists containing two integers where the first integer of each list j denotes there is edge between i and j , second inte. Sum of all odd nodes in the path connecting two given nodes. After partitioning, each subarray has their values changed to become the maximum value of that subarray. The sum of right-subtree is 1 The sum of tree is 13. The result is going to be very large, hence return the result in the form of a string. create an empty vector 'edge' of. Assume that every graph with no odd cycles and at most q edges is bipartite and let G be a graph with q + 1 edges and with no odd cycles. We can easily solve this problem in linear time using Kadane’s algorithm. To compute sum of current window, remove first element of previous window and add. The Sum of a cycle is the sum of node numbers of all nodes in that cycle. The cells are named with an integer value from 0 to N−1. The two sub-arrays are [1, 2, 5] [2, 3]. , it can be colored with two colors “. Each cell may have multiple entry points but not more than one exit (ie. Submit. First of all consider every ‘0’ in the matrix as ‘-1’. Input: arr [] = {10, 12, 12, 10, 10, 11, 10}; Output: Length of the longest contiguous subarray is 2. . GFG Weekly Coding Contest; Job-A-Thon: Hiring Challenge; All Contests and Events; Change. Follow the steps below to solve the problem: Calculate the maximum prefix sum of array A[] and store it in a. In the previous post, we checked whether the maximum value minus the minimum value is equal to the ending index minus starting index or not. Detailed solution for Split Array – Largest Sum - Problem Statement: Given an integer array ‘A’ of size ‘N’ and an integer ‘K'. 3) While current is not NULL : 3. the used approach of using sum at each node until the node is again repeated in the cycle. Use an array to store the maximum path sum starting from a node. For example, if input is {1, 101, 2, 3, 100, 4, 5}, then output should be 106 (1 + 2 + 3 + 100), if the input array is {3, 4, 5, 10}, then output should be 22 (3 + 4 + 5 + 10) and if the input. Static data structure: Static data structure has a fixed. If current_sum is greater than max_sum, update max_sum, end to the current index, and max_start and max_end to start and end respectively. A cycle of length n simply means that the cycle contains n vertices and n edges. Maximum size of subset of given array such that a triangle can be formed by any three integers as the sides of the triangle. The maximum sum path may or may not go through the root. Algorithm for solving this problem: Find the sum of all elements of in individual stacks. Follow the steps below to solve the given. Back to Explore Page. In the above step, the row sum from starting to ending column can be calculated in constant time by creating an auxiliary matrix of size N*M containing the prefix sum of each row. If a loop is found, initialize a slow pointer to head, let fast pointer be at its position. The task is to find subtree with maximum sum in the tree and return its sum. Follow the given steps to solve the problem: Create a Hashmap ( hm) to store a key-value pair, i. There is no subarray of size 3 as size of whole array is 2. It may be assumed that size of array is more than m*k. e. Input: arr [] = {1, 4, 2, 10, 2, 3, 1, 0, 20} k = 4, sum = 18 Output: YES Subarray = {4, 2. The subarray with a given sum can be found using this method. The difference between two sums varies from -n to n. e. The task is to find the connected chain with the maximum sum of values among all the connected components in the graph. Return the sum of all subarray ranges of arr. Back to Explore Page. Your task: You dont need to read input or print anything. 138 subscribers. An empty tree is also a S. Else remove the top element of the stack. Split the given array into K subarrays such that the maximum subarray sum achievable out of K subarrays formed is minimum. You are given an array Edge [] of N integers, where Edge [i]The task is to find the largest sum of a cycle in the maze (Sum of a cycle is the sum of the cell indexes of all cells present in that cycle). Rearrange the array in alternating positive and negative items. ; Sort the array in descending order. Given a matrix of size NxM and a list of queries containing (a,b) pairs. The element should occur more than once and the index of its first occurrence should be the smallest. By iterating over the array in reverse order. Level up your coding skills and quickly land a job. All DSA Problems; Problem of the Day; GFG SDE Sheet; Curated DSA Lists. The idea is simple, we find all divisors of a number one by one. Traverse through all pairs again and search for X – (current pair sum) in the hash table. Example 2: The above graph has two cycles of length 4 and 3, the product of cycle lengths is 12. Method 1 There can be two cases for the maximum sum: Case 1: The elements that contribute to the maximum sum are arranged such that no wrapping is there. Return max_end – max_start + 1 as the size of the subarray with maximum sum. A sheet that covers almost every concept of Data Structures and Algorithms. Sum of upper triangle and lower triangle. If the size of the max heap exceeds K, pop (remove) the smallest element from the min heap. . A brute force approach is to store all the contiguous sums in another array and sort it and print the k-th largest. A sequence, sorted in increasing order is. Example 1: Input: 1 / \ 2 3 / \ / \ 4 5 6 7 Output: 28 Explanation Your task is to complete the function isNegativeWeightCycle () which takes n and edges as input paramater and returns 1 if graph contains negative weight cycle otherwise returns 0. Solution. Back to Explore Page. Input : arr [] = {10, 1, 3, 15, 30, 40, 4, 50, 2, 1} K = 3 Output : 3 15 30 40 4 50. So the first position of the kth sequence will be occupied by the number present at index = k / (n-1)! (according to 1-based indexing). tli : Row number of top left of. The sum of nodes considering -4 as the root of subtree is -4 = -4. Given an array A of size N. Follow the below steps to solve the problem: Initialize a min heap (priority queue) pq. Given an integer N, find its factorial. Solve one problem based on Data Structures and Algorithms every day and win exciting prizes. You need to find the the length of the largest cycle in the maze. Given a binary tree, the task is to find the maximum path sum. Given a binary tree, the task is to find the maximum path sum. We take two pointers, one representing the first element and other representing the last element of the array, and then we add the values kept at both the pointers. For the root node, sum of elements in left subtree is 40. Subtract each element of the subarray with the maximum. In this approach, we can traverse the tree in a Depth First Search (DFS) manner, and maintain a level count. . Below is the dry run of the above approach: Follow the given steps to solve the problem: Create a deque to store K elements. Given a Directed Graph with V vertices (Numbered from 0 to V-1) and E edges, check whether it contains any cycle or not. Solve. . This gives sum = 13. NOTE: If there is a tie, then compare with segment's length and return segment which has maximum length. Explanation: Sum of both the pairs {7, 9} and {9, 8} are greater. We would like to show you a description here but the site won’t allow us. Note: Here Size is equal to the number of nodes in the subtree. Given an array of integers. The idea is to convert given problem to a simpler problem where we have to just check if there is cycle of odd length or not. The path may start and end at any node in the tree. Time Complexity: O (N) Below is the implementation of the above approach: C++. a) If the current element is greater than the first max element, then update second max to the first. All the above paths are of length 3, which is the shortest distance between 0 and 5. 4) Return result. You don't to print answer or take inputs. The task is to check if there exists any subarray with K elements whose sum is equal to the given sum. Largest number with given sum | Practice | GeeksforGeeks. 2. Solve. Practice. e. After that check a condition that if max value is less then head value is assigned to max or min value is greater then head value is assigned to min otherwise head point to next node. GfG Weekly + You = Perfect Sunday Evenings! Given a weighted, undirected and connected graph of V vertices and E edges. Minimum and maximum node that lies in the path connecting two nodes in a Binary Tree. b) Remove all edges from E which are either incident on u or v. You don't need to read input or print. Find the Length of the largest cycle. Find Complete Code at GeeksforGeeks Article: Like, Comment and Share the Video among you. We need to find the max sum of sums of M subarrays of size K (non-overlapping) in the array. After partitioning, each subarray has their values changed to become the maximum value of that subarray. Input: L = -3, R = 3, K = 1. max and update the first max to the current element. Example: Given an array of integers of size ‘n’, Our aim is to calculate the maximum sum of ‘k’ consecutive elements in the array. The graph is represented as an adjacency. entry/exit points are. For a Euler Circuit to exist in the graph we require that every node should have even degree because then there exists an edge that. ( Cycle which has maximum sum weight ). Maximize the minimum difference between any element pair by selecting K elements from given Array. Approach: Depth First Traversal can be used to detect cycle in a Graph. Your task is to complete the function maxSubMatrixSumQueries () which takes the 2D array of integers mat, n, m, queries and q as input parameters and returns an array of integers denoting the maximum sum for each query. Find largest subtree having identical left and right subtrees; Sum of all the parent nodes having child node x; Maximum sum from a tree with adjacent levels not allowed; Iterative function to check if two trees are identical; Check if there is a root to leaf path with given sequence; Sum of nodes at maximum depth of a Binary TreeThe longest of them will be the answer. Given two numbers 'N' and 'S' , find the largest number that can be formed with 'N' digits and whose sum of digits should be equals to 'S'. Find the length of each subarray. Given head, the head of a singly linked list, find if the linked list is circular or not. e 5 only. Given a binary tree. For example below graph have 2 triangles in it. Convert all even weight edges into two. Print the longest of all subsequences with maximum sum. 138 subscribers. Let e = uv be an edge of G and consider the graph H = G – uv. Approach: The given problem can be solved using mathematics. Maximum subsequence sum such that no three are consecutive in O (1) space. 0 You are given a maze with N cells. You are given an array Arr of size N. Example 1: Input: N = 3 value [] = {1,2,1. Approach: The idea is to use the Kadane algorithm to solve this problem. Tree. Example 2: Given a weighted, undirected and connected graph of V vertices and E edges. The two sub-arrays are [1, 2, 5] [2, 3]. Given an array containing N integers and a positive integer K, find the length of the longest sub array with sum of the elements divisible by the given value K. Output 45. To convert, we do following. Approach: The given problem can be solved by finding all the paths from a given source to a destination and using a Priority Queue to find the K th largest weight. In the case of multiple pairs with the largest sum, print any one of them. Negative weights are found in various applications of graphs. geeksforgeeks. Let the number be 12345. Contests. So, this DSA sheet by Love Babbar contains 450 coding questions which will help in: Understanding each and every concept of DSA. Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. Time Complexity: O (N * 2N) Auxiliary Space: O (N) Efficient Approach: The problem can be solved using Greedy technique. The cells are named with an integer value from 0 to N−1. We add an edge back before we process the next edge. After that we will initialize our two subarray from (N – 2K) and (N – K) indices, where. Maximum sum path in a matrix from top-left to bottom-right. next is the next greater element for the popped element. Given an array Arr, with indexes running from 0 to N, select any two indexes, i and j such that i<=j-1. The task is to find the largest sum of a cycle in the maze (Sum of a cycle is the sum of the cell indexes of all cells present in that cycle). We can use hashmap to store the prefix sum, and if we reach any index for which there is already a prefix with same sum, we will find a subarray with sum as 0. We one by one remove every edge from the graph, then we find the shortest path between two corner vertices of it. Return the length of the longest cycle in the graph. Create Largest Sum Cycle. Now, the idea is to reduce the problem to 1-D array. If max_so_far is less than max_ending_here then update max_so_far to max_ending_here. Example 2: Input: nums = [1] Output: 1 Explanation: The subarray [1] has the largest sum 1. In the end, the min heap contains the K largest elements of the array. The task is to find subtree with maximum sum in the tree and return its sum. Free, Self-Paced with Lifetime Access using Strivers A2Z DSA Course. We can generate Egyptian Fractions using Greedy Algorithm. For example, consider 6/14, we first find ceiling of 14/6, i. Whenever we reach a node at the kth level, we add its value to a sum. . Send feedback. Allocate Minimum Spanning Tree. Courses. Examples: {-10, 2, -1, 5}, {-2, 4, -1, 4, -1}. Pre-requisite: BS-18. Each cell may have multiple entry points but not more than one exit (ie. 0 <= m <= n* (n-1), where m is the total number of Edges in the. Input: n = 7 k = 3 arr = [1,15,7,9,2,5,10] Output: 84 Explanation: arr becomes [15. . Let A [] [] be the adjacency matrix representation of the graph. Back to. i] having length i + 1. Steps to implement: Declare a variable “ans” with value 0 because if no such subarray exists then 0 will be the answer. Find the middle index (say mid ). Find the length of the largest subarray with equal number of 0s and 1s. Nodes are labeled from 0 to n-1, the task is to check if it contains a negative weight cycle or not. Prefix Sum 136. GfG Weekly + You = Perfect Sunday Evenings! Given a number N, the task is to find the largest prime factor of that number. Follow the steps below to solve the problem: If the given array is sorted in ascending order, then print “-1” as it is not possible to find lexicographically the largest permutation. Practice here: maximum result for that node will be equal to the sum of those two paths with the node. Longest Increasing Subsequence having sum value atmost K. Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime. Time Complexity: O(n 2) Auxiliary Space: O(1) Using Queue: We can use queue structure to calculate max or min sum of a subarray of size k. To convert, we do following. Find the length of the longest subarray with atmost K occurrences of the integer X. If we calculate A 3, then the number of triangles in Undirected Graph is equal to trace (A 3) / 6. If the size of the max heap exceeds K, remove the. Note: The above code assumes that there is at least one positive element in the array. Given two numbers 'N' and 'S' , find the largest number that can be formed with 'N' digits and whose sum of digits should be equals to 'S'. 594 views 1 month ago GFG POTD series. Run. In every topic, you can start from questions according to your comfort level. Once the graph traversal is completed, push all the similar marked numbers to an adjacency list and print the adjacency list accordingly. 6% Submissions: 239K+ Points: 1. Basic Accuracy: 69. Explore; Problems;. In case of multiple subarrays, return the subarray indexes which come first on moving from left to right. Generate an N-length array with sum equal to twice the sum of its absolute difference. The task is to find the largest sum of a cycle in the maze (Sum of a cycle is the sum of the cell indexes of all cells present in that cycle). Your Task: You don't need to read or print anything. Analysis of Graph Coloring Using Greedy Algorithm: The above algorithm doesn’t always use minimum number of colors. Write a program to find the sum of maximum sum subsequence of the given array such that the integers in the subsequence are sorted in increasing order. Cycles of length n in an undirected and connected graph. Example 1: Input: N = 4 Edge[] = {1, 2, 0, -1} Output: 3. Now we will use Kadane’s Algorithm to find the maximum subarray sum and minimum subarray sum. Where 5 is the 2nd largest. Example 2: Input: 10 / 20 30 / 10 10 Output: 0 Explanation: The given tree is not a sum tree. From subarray Arr [i. Lexicographically largest permutation possible by a swap that is smaller than a given array; Lexicographical smallest and largest Permutation from Array whose elements are max of Prefix; Non-Divisible Subarray sum permutation; Count of permutations of an Array having maximum MEXs sum of prefix arraysMethod 2: Two Pointers Technique. The questions will be featured from a pool of public problems from the GFG Practice Portal. Note: The cells are named with an integer value from 0 to N-1. Explanation: Subsequence { 11, 7 } and { 9, 2, 7 } has sum equal to 18. For each node from leaf to root find the maximum sum. Explanation: The subarray having maximum sum with distinct element is {2, 3, 1, 5}. org. Hence, maximum circular subarray sum is 22. The task is to find the largest sum of a cycle in the maze(Sum of a cycle is the sum of the cell indexes of all cells present in that cycle). Calculate the sum of X and Y. Input: 10 / 2 5 -2 Output: 17 Explanation: Path in the given tree goes like 2 , 10 , 5. Sub-array A is greater than sub-array B if sum (A) > sum (B). . Follow the steps below to solve the problem: Store all the edges corresponding to all the unique weight in a map M. Longest Bitonic Subsequence in O (n log n) Given an array arr [0. Output: No. Find the maximum for each and every contiguous subarray of size K. Steps to implement-. Output: 11. NOTE: The adjacency list denotes the edges of the graph where edges [i] stores. Approximate Algorithm for Vertex Cover: 1) Initialize the result as {} 2) Consider a set of all edges in given graph.