what case would you use the following templates for? Give an example of each <ma
ID: 3800234 • Letter: W
Question
what case would you use the following templates for? Give an example of each <map> <array> <vector> <sets> <trees> <stacks> <queues> what case would you use the following templates for? Give an example of each <map> <array> <vector> <sets> <trees> <stacks> <queues> what case would you use the following templates for? Give an example of each <map> <array> <vector> <sets> <trees> <stacks> <queues>Explanation / Answer
<map> : maps are used when we want a key value pair. For eg : maps are useful in dictionary like situation where every key or word has a corresponding value or meaning where keys are distinct.
<array> : array are linear sequential data structure and can be used if we want to store data generally of a single type contiguously. For eg : we can use array to generate any data structure like stack or queue where the sizes are predefined.
<vector> : vectors are also known as dynamic array where the size is no more a constraint. For eg. : vectors are used in places where we want the data to be contiguously stored but the size is not fixed.
<sets> : set templates can be used whenever we want data in any order but without repetation. For eg. : sets are useful whenever we want to check within a set of values instead of single values.
<trees> : tree templates can be used when we can have more than one route which can be taken. For eg. : trees are useful when we create directory structure because there can be many folders in a folder but there will always be only one parent folder for every folder.
<stacks> : stack templates can be used whenever the situation has Last in First out approach. For eg. : stacks are useful when we parse an expression either to check the parenthesis or evalute it.
<queues> : queue templates can be used whenever the situation has First in First out approach. For eg. : queues are useful when processing user requests, providing service to clients, etc.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.