Question

In: Computer Science

what are Sorted lists and their efficiency? in c++ and data structures

what are Sorted lists and their efficiency? in c++ and data structures

Solutions

Expert Solution

In C++ Lists are containers used to store data in a non contiguous fashion, Normally, Arrays and Vectors are contiguous in nature, therefore the insertion and deletion operations are costlier as compared to the insertion and deletion option in Lists. To store data in a non contiguous fashion, Normally, Arrays and Vectors are contiguous , therefore the insertion and deletion operations are costlier as compared to the insertion and deletion option in Lists. sort() function is used to sort the elements of the container by changing their positions.

nameoflist.sort()
Parameters :
No parameters are passed.
Result :
by default The elements of the container are sorted in ascending order.

example:

Input  : mylist{8,5,7,4,6,1};
         mylist.sort();
Output : 1,4,5,6,7,8

Input  : mylist{"excellent", "nice", "cool"};
         mylist.sort();
Output : cool,excellent,nice

Time Complexity : O(nlogn) : its much faster.


Related Solutions

C++ Data Structures 4. Write a client function that merges two instances of the Sorted List...
C++ Data Structures 4. Write a client function that merges two instances of the Sorted List ADT using the following specification. MergeLists(SortedType list1, SortedType list2, SortedType& result) Function: Merge two sorted lists into a third sorted list. Preconditions: list1 and list2 have been initialized and are sorted by key using function ComparedTo. list1 and list2 do not have any keys in common. Postconditions: result is a sorted list that contains all of the items from list1 and list2. c. Write...
"Python lists are power data structures. Describe some of the benefits of Python lists" Answer the...
"Python lists are power data structures. Describe some of the benefits of Python lists" Answer the question above in a few sentences.
"Python lists are power data structures. Describe some of the benefits of Python lists" Make sure...
"Python lists are power data structures. Describe some of the benefits of Python lists" Make sure you don't just give me a list but a few sentences instead just answering it.
Given two sorted lists, L1 and L2, write an efficient C++ code to compute L1 ∩...
Given two sorted lists, L1 and L2, write an efficient C++ code to compute L1 ∩ L2 using only the basic STL list operations. What is the running time of your algorithm?
c. Taking every 20th passenger in your sorted table, create a new table that lists Passenger...
c. Taking every 20th passenger in your sorted table, create a new table that lists Passenger ID and Rating for the 20 data points you will now have (In excel please) with formula. I am stomped by this. TABLE C5-1: PASSENGER ID and CUSTOMER EXPERIENCE RATING Passenger ID Rating (1-5) T006 4 T007 5 T008 1 T009 4 T010 5 T011 3 T012 2 T013 3 T014 2 T015 3 T016 4 T017 4 T018 4 T019 5 T020 3...
04 Prove : Homework - Data Structures Linked Lists Outcomes At the end of this study,...
04 Prove : Homework - Data Structures Linked Lists Outcomes At the end of this study, successful students will be able to: Articulate the strengths and weaknesses of Linked Lists. Use Linked Lists in Python to solve problems. Preparation Material Read the following sections from Wikipedia: Linked Lists: The Introduction Advantages Disadvantages Basic concepts and nomenclature The following subsections are sufficient: Intro Singly Linked Lists Doubly Linked Lists Tradeoffs The following subsections are sufficient: Linked Lists vs. Dynamic Arrays Data...
(Subject: Data Structures and Algorithms) Faster merging. You are given two sorted sequences of $\lg{n}$ and...
(Subject: Data Structures and Algorithms) Faster merging. You are given two sorted sequences of $\lg{n}$ and $n-1$ keys. We would like to merge those two sorted sequences by performing $o(n)$ comparisons. (Note we are interested in comparisons, not running time.) Show how this can be done or argue that it cannot be done. Note: In class we showed that ordinary merging would require no more than $\lg{n}+n-1+1= n + \lg{n}$ comparisons.
A Lecturer wishes to create a program that lists his students sorted by the number of...
A Lecturer wishes to create a program that lists his students sorted by the number of theory assignment marks they have completed. The listing should be greatest number of assignment first, sub-sorted by name in lexicographical order (A to Z). A class Student stores the name and marks of assignment completed for a student.                                                    [5 marks] Note: Assume the variable name of collection is list.       i.         Provide a definition of Student with an equals() method. The comparison is based...
c++ Create a program that creates a sorted list from a data file. The program will...
c++ Create a program that creates a sorted list from a data file. The program will prompt the user for the name of the data file. Create a class object called group that contains a First Name, Last Name, and Age. Your main() function should declare an array of up to 20 group objects, and load each line from the input file into an object in the array. The group class should have the following private data elements: first name...
How would you show two linked lists are equal? (Java for Data Structures and Algorithms)
How would you show two linked lists are equal? (Java for Data Structures and Algorithms)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT