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.
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.
Loop invariants: Consider the following Python function that merges two sorted lists. Here is a loop...
Loop invariants: Consider the following Python function that merges two sorted lists. Here is a loop invariant for loop 1: “the contents ofnewlistare in sorted order,newlistcontainsaelements oflistAandbelements oflistB” def mergeSortedLists(listA, listB):  newlist = [ ]  a = 0  b = 0  # loop 1  while a < len(listA) and b < len(listB):   if listA[a] < listB[b]:    newlist.append(listA[a])    a +=1   else:    newlist.append(listB[b])    b +=1  if a < len(listA):   newlist.extend(listA[a:])  if b < len(listB):   newlist.extend(listB[b:])  return newlist (a) Write down (in regular...
JAVA *** All data structures, including array operations, queues, stacks, linked lists, trees, etc need to...
JAVA *** All data structures, including array operations, queues, stacks, linked lists, trees, etc need to be implemented by you. Write a menu driven program that implements the following Binary Search Tree Operations FIND (item) INSERT (item) DELETE (item) DELETE_TREE (delete all nodes - be careful with the traversal!)
C++ Linked Lists Practice your understanding of linked lists in C++ by creating a list of...
C++ Linked Lists Practice your understanding of linked lists in C++ by creating a list of songs/artist pairs. Allow your user to add song / artist pairs to the list, remove songs (and associated artist) from the list and be sure to also write a function to print the list! Have fun! Make sure you show your implementation of the use of vectors in this lab (You can use them too ) You MUST modularize your code ( meaning, there...
Meta Language(ML) has two commonly used data structures(Lists and tuples). Distinguish between two of them and...
Meta Language(ML) has two commonly used data structures(Lists and tuples). Distinguish between two of them and rationalize your argument by the support of code snippet of each.        Lists Tuples How can we concatenate a string in Meta Language(ML)? Also write one coding example of string concatenation.                                                                                                                         What is meant by right-associative ? Elaborate it using an example.                                Write a condition in the given blank below using comparison operator to get the require output from this code.                                                                ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT