![]() |
Venice Technique is a strategy where we create a new data structure called Venice Set that mainly helps to answer range queries which involves updating all elements by a common value in constant time. In this article, we will discuss about Venice Technique, the idea behind Venice Technique, its structure, implementation, etc. What is Venice Set?Venice Set is a user defined data structure that contains different types of data(usually numbers) and these three different types of operations-
Syntax :
This syntax outlines the core methods of the Venice Set for adding, removing and updating elements. Apart from that, we can also add a method for finding the Venice set’s size. We can add other methods as well in the venice sets according to our need. We mainly take unordered sets, sets or multisets to implement venice sets. We already know how to add or remove any element in constant time, but the main reason of bringing venice set into the picture is to update all element into a constant time. Idea behind Venice Technique:In a city, the government decided to build some towers such that it could tell workers anytime to add any tower, remove any tower, or to reduce the height of all towers by a common value. Now adding and removing any tower can be done in constant time but to reduce the height of all towers by a common value, workers have to go to every tower to reduce the height. So, to reduce the height of all towers in constant time, what workers can do is to put water in the whole city so that the bottom part of the tower can be submerged in water by the same amount with which we needed to reduce the height. For example, if the Government instructs to reduce every tower’s height by 1 unit, then workers can put water in the city so that the bottom most 1 unit of towers get submerged in water. We will do the same thing in Venice set to update all elements by a common value in constant time. Now since Venice is a city in Italy in which there is water between houses and in this set like data structure we are updating all elements by water or some value. So to easily identify this data structure we called that Venice set. Structure of Venice Set:Below is the structure of Venice Set:
Step-by-step algorithm:Now algorithm for implementation of these methods depends on use cases. So here we will implement these methods for the problem that we saw earlier where the Government wants to add, remove, or reduce the height of all the towers in constant time. Here, we should take care of the following points-
Implementation of Venice TechniqueBelow is the implementation of Venice Technique:
Output Size of the set: 3 Element 40 not found for removal. Size of the set: 2 Complexity Analysis:
|
Reffered: https://www.geeksforgeeks.org
Competitive Programming |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 20 |