fbpx

C++ interview questions on STL containers like vector and list

C++ interview questions on STL containers like vector and list
(Last Updated On: May 12, 2010)

C++ interview questions on STL containers like vector and list

Containers:
vector and list difference. complexities of alogrithms.

Vector –
1> Insertion – O(n) /* Resizing the array */
2> Search – O(n) /* Sequential */ , O(logn ) /* Binary */
3> Random Access – Yes .
4> Deletion – O(n) /* Shifting & Resizing */
5> Sequential Memory used .

List –
1> Insertion – O(1)
2> Search – O(n)
3> Deletion – O(n)
4> Random Access – No
5> Linked allocation , hence more memory efficient .
Reply to Comment
Anonymous on April 10, 2010 |Edit | Edit

For list, the complexity of deletion should be O(1).
3> Deletion – O(1)

What is a container class? What are the types of container classes?
A container class is a class that is used to hold objects in memory or external storage. A container class acts as a generic holder. A container class has a predefined behavior and a well-known interface. A container class is a supporting class whose purpose is to hide the topology used for maintaining the list of objects in memory. When a container class contains a group of mixed objects, the container is called a heterogeneous container; when the container is holding a group of objects that are all the same, the container is called a homogeneous container.
how to delete a node in a list
single linked list ? – then save pointer to next node, start from head and go to the node right before the node being deleted, and change it’s “next” pointer to the one you saved.
Now you can delete node.
double linked list ? – no need to start from head, just reassign pointers in neighbor nodes properly to point to each other instead of to the node being deleted, and then delete the node. Of course, special care for first and last nodes, which have some NULL pointers.

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!
share this recipe:
Facebook
Twitter
Pinterest

Still hungry? Here’s more

New Educational Content: Power Up Your Trading

I posted TraderPost.io brand new video educational content playlist on the QuantLabs YouTube channel, offering a treasure trove of resources designed to equip you with the knowledge and skills to navigate the ever-evolving world of quantitative trading.

Read More

Are you interested in:

If so, CLICK HERE 

FREE 2 Hour Video! 

 

As you know with the crazy restrictive emergency laws being introduced in the last week, many moving their savings out of FIAT banks into cryptocurrency trading.

Here are some questions to get your started:

  • Create your own ‘bank’ anonymously with crypto
  • In the future, draw off your crypto saving with a Visa debit card
  • Trade using a European de-central exchange to trade perpetual contracts and other high performing coins
(All your info is kept private nor released!  Don’t forget to check to click your promo or spam inbox after the confirmation email is sent) 

Create your own  PRIVATE Bank