Question

In C++ please. 4. Differentiate sequential, associative and unordered STL containers. Explain the need for specialized...

In C++ please.

4. Differentiate sequential, associative and unordered STL containers. Explain the need for specialized list algorithms, i.e. why it is not sufficient to use general purpose STL algorithms. Give an example use of one such algorithm.

Homework Answers

Answer #1

Sequential Container :

Sequential containers are those data structures that store data sequentially, hence elements are accessed sequentially.

These are some sequential container like

1. ARRAY: It is used to stores data of the same types like ar[int], arr[char]... It has a fixed size.

2. VECTOR: It can grow dynamically(size can grow automatically as elements increase ) and fast random access are also there.

3. dequeue : It is doubly ended queue and supports insertion and deletion from front and back both side. as well as fast random access is also there.

4. List : it is a doubly-linked list library in c++. Doubly linked list provides the functionality of deletion and insertion faster in O(1) time.

Associative Container : These types of containers like map , set , multimap , multiset.

1.map : It contains that data in key - value pair and key must be unique and ordered map supports accessing element in O(long) and allow accessing of elements in constant time in O(log n) time .

2. set : set contains all the unique elements and supports insert in o(n) but searching is fast in O(log n).

3. multiset : Same as set but here duplicate elements can be also there.

4 .multimap: it is same as map but key need not to be unique

NOTE : most of the insertion and deletion and searching in associative containers have time complexity of O(log n)

unordered STL containers : These containers are like unordered_map, unordered_set, unordered_multiset ,unordered_multimap.

General purpose STL algorithms are not sufficient because we can have to do modification under some of the code to implement some new things , but in stl they are pre-implemented so we can only use it is difficult to modify the STL library.

eg. of deueue of stl

#include<bits/stdc++.h>
using namespace std;  

int main()
{
   deque<int>dq; // define doubly ended queue from STL directly
   dq.push_back(1); // to push element in back of queue
   dq.push_back(2); // to push front of queue
   dq.pop_front(); // to pop element from front
   dq.push_front(5); // to push front of queue
   dq.push_back(8); // to push element in back of queue

for(int x:dq)
cout<<x<<" ";

   return 0;
}

Output: 5 2 8

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Q. Name and differentiate the following two constructs: For (auto e: myContainer) and for (auto &e:...
Q. Name and differentiate the following two constructs: For (auto e: myContainer) and for (auto &e: myContainer) Explain the situation where one construct is preferred to the other. Give an example usage. I got the following answer here at Chegg but I still need an example (simple one) please: 1st one is call by value when you want use it for read only purpose than use this cal by value 2nd one is call by reference. we will use this...
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question....
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question. Thank you! Here’s the contents of a file called example.cpp: // example.cpp #include "LinkedList.h" #include <iostream> #include <string> using namespace std; int main() { cout << "Please enter some words (ctrl-d to stop):\n"; LinkedList lst; int count = 0; string s; while (cin >> s) { count++; lst.add(remove_non_letters(s)); } // while cout << "\n" << count << " total words read in\n"; cout <<...
Please I need answer for This question and it is very important and I need solution...
Please I need answer for This question and it is very important and I need solution for this issue with all the details just nu , and help me with all the details, so that I can read and understand your answer clearly.thanks in advance/Ha Q. This question will ask you to analyse the effect of trade liberalisation when there are economies of scale in production. a) Explain the difference between external and internal economies of scale. b) Give three...
Buying any type of product or good is a sequential game in which the owner of...
Buying any type of product or good is a sequential game in which the owner of the product or good sets the price and then the buyer can buy, not buy, or counter and offer a new price.  This can be broken down into the following simple tree diagram: However, the determination of what Price A and Price B is is often a simultaneous game played between two or more competing companies. For example:   Taking this into consideration, imagine you are...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
Please explain in FULL detail. This is for Business Law 1. On October 1, 2011, Ralph...
Please explain in FULL detail. This is for Business Law 1. On October 1, 2011, Ralph purchased a single family home in Highland park, Illinois for the price of $450,000.00. During the negotiation for said sale, Stanley the seller, represented to Ralph that said home was constructed of fire proof materials and additionally was flood proof. On November 15, 2011 at 2 a.m. a fire broke out in the residence's kitchen, spreading throughout the first level. The fire was finally...
1. Juanita wants to write an essay for her school paper arguing for the need for...
1. Juanita wants to write an essay for her school paper arguing for the need for more parking near campus. She expects that the students and faculty who read the essay will likely agree with her position. Which organizational pattern should she use? A.from least to most important B.from general to specific C.spatial D.from most to least important 2. Identify the option that describes one purpose of an argument essay. A.to teach someone about the similarities between two things or...
Answer the following questions as detailed as possible: Question #1 – Time Value of Money Please...
Answer the following questions as detailed as possible: Question #1 – Time Value of Money Please give a detailed example from your own personal or professional experiences (life/career) that involves the Time Value of Money. The Time Value of Money defined as in Chapter 4 as: Present Value, Future Value, Present Value of an Annuity, Future Value of an Annuity, Amortization. It can be one of these above or multiple. Explain the example and how this/these money valuation tools fit...
Answer the following questions as detailed as possible: Question #1 – Time Value of Money Please...
Answer the following questions as detailed as possible: Question #1 – Time Value of Money Please give an example from your own personal or professional experiences (life/career) that involves the Time Value of Money. The Time Value of Money defined as in Chapter 4 as: Present Value, Future Value, Present Value of an Annuity, Future Value of an Annuity, Amortization. It can be one of these above or multiple. Explain the example and how this/these money valuation tools fit into...
please get the correct answer. no need explain 1- Bronfenbrenner's ................provides theoretical support for effects on...
please get the correct answer. no need explain 1- Bronfenbrenner's ................provides theoretical support for effects on children's development that comes from their environment, such as home, child care, and school . a• mesosystem b• macrosystem c• microsystem 2- When conferring with family members about a child's classroom difficulties, teachers must Olay out multiple possible diagnoses . never suggest a diagnosis . make sure to tell the parent what they are doing wrong 3- Nurturing environments with responsive caregivers a•increase a...