C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Want to see more full solutions like this?
Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
To start, create your own set of 10 numbers in an array that are not sorted. Using your array, do the following exercises:
Show how the Mergesort algorithm sorts your array by:
Showing which sub parts of the array are being examined with each recursive call to Mergesort
Showing the results of the array each time the Merge function is used
Your demonstration should be similar to slides 19-33 in the Mergesort presentation. You do not have to show the details of the function calls in the stack (unless it helps you), but do explain what is happening at each step to show understanding of the algorithm and receive partial credit if you’re incorrect.
Using your same original array, show how the Quicksort algorithm sorts this array by:
Showing the results of the array each time the Partition function is used
Showing which sub parts of the array are being examined with each recursive call to Quicksort
Your demonstration should be similar to slides 35-64 in the Quicksort presentation.…
python code. instructions are given within the quotations for each function.
1) def invert_dict(d): """ Given a dictionary d, create the invert of the dictionary where the key is a value v in d, and v is mapped to a set of keys in original d whose values are equal to v. Return the inverted dictionary mapping value to set of keys """
return {1:1}
2) def histogram(words):
""" Given a list of words, create a histogram dictionary where the key is the length of a word and the value is the count of how many words in the list are of that length. Return the histogram dictionary mapping length to word counts """
return {1:1}
3) def max_kv(d):
""" Given a dictionary, return a tuple of key value pair where the key is the largest in d. """
return (1, {1})
4) def run():
""" Get words list from the file listed in argv[1]; create histogram of count of each word length; create invert…
WRITE THE MAIN.CPP FOR THIS PROGRAM
a. Write a version of the sequential search algorithm that can be used to search a sorted list. (1, 2)
b. Consider the following list: 2, 20, 38, 41, 49, 56, 62, 70, 88, 95, 100, 135, 145
Using a sequential search on ordered lists, that you designed in (a), how many comparisons are required to determine whether the following items are in the list? (Recall that comparisons mean item comparisons, not index comparisons.) (1, 2)
2
57
88
70
135
Write a program to test the function you designed.
Note: Have the function,seqOrdSearch, return -1 if the item is not found in the list. (return the index of the item if found).
Chapter 16 Solutions
C++ How to Program (10th Edition)
Ch. 16 - Exercises 16.4 State whether each of the following...Ch. 16 - Fill in the blanks in each of the following...Ch. 16 - Prob. 16.6ECh. 16 - Prob. 16.7ECh. 16 - (Duplicate Elimination) Read 20 integers into an...Ch. 16 - (Duplicate Elimination) Modify Exercise 16.8 to...Ch. 16 - Prob. 16.10ECh. 16 - (Merging Ordered Lists) Write a program that uses...Ch. 16 - Prob. 16.12ECh. 16 - Prob. 16.13E
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- dont write code. just write algorithm or related theory of the following question. Narrative 2: We need to have a generic module which reads in file and gives the output in the format which would facilitate other programs to do comparison like the one we saw above to carry out analysis and comparison. Response Required: Write a program that reads a given text, outputs the text as is, and also prints the number of lines and the number of times each letter appears in the text. An uppercase letter and a lowercase letter are treated as being the same; that is, they are tallied together. Since there are 26 letters, we use an array of 26 components to perform the letter count. We also need a variable to store the line count. The text is stored in a file, which we will call textin.txt. The output will be stored in a file, which we will call textout.txt Input: A file containing the text to be processed. Output: A file containing the text, number of lines, and the number of times a letter…arrow_forwardUsing binary search approach, write a python function named update_record, which takes the following inputs: 1: students_records – Nested List of Tuples. Each tuple of the list represents student's data. 2: ID – An ID of a student whose data has to be updated 3: record_title – type of data that has to be updated 4: data – A new data that should replace record_title data and update the record of students' data associated to specific ID. If ID is given as the data to be updated, then return a message that ID cannot be updated. If ID is not found in students_records, then return a message that Record not found. NOTE: The type of record_title input can be "ID", "Email", "Mid1" or "Mid2". Please use the same spelling for these types in your code, because the same have been used in test cases. Test cases are attached below: student_records = '[("aa02822", "ea02822", 80, 65),("ea02822", "ea02822@st.habib.edu.pk", 80, 65),("fa08877", "fa08877@st.habib.edu.pk", 66, 67),("gh04588",…arrow_forwardTo start, create your own set of 10 numbers in an array that are not sorted. Using your array, do the following exercises: Show how the Mergesort algorithm sorts your array by: 1) Showing which sub parts of the array are being examined with each recursive call to Mergesort 2) Showing the results of the array each time the Merge function is used Your demonstration should be similar to slides 19-33 in the Mergesort presentation. You do not have to show the details of the function calls in the stack (unless it helps you), but do explain what is happening at each step to show understanding of the algorithm. Using your same original array, show how the Quicksort algorithm sorts this array by: 3) Showing the results of the array each time the Partition function is used 4) Showing which sub parts of the array are being examined with each recursive call to Quicksort Your demonstration should be similar to slides 35-64 in the Quicksort presentation. Again, you do not have to show all the…arrow_forward
- Complete the docstring below using the helper function and information attached: def get_last_syllable(word_phonemes: PHONEMES) -> PHONEMES: """Return the last syllable from word_phonemes. The last syllable in word_phonemes is formed from the last vowel phoneme and any subsequent consonant phoneme(s) in word_phonemes, in the same order as they appear in word_phonemes. >>> get_last_syllable(('AE1', 'B', 'S', 'IH0', 'N', 'TH')) ('IH0', 'N', 'TH') >>> get_last_syllable(('IH0', 'N')) ('IH0', 'N') >>> get_last_syllable(('B', 'S')) () """arrow_forwardModify the following program to read dictionary items from a file and write the inverted dictionary to a file: characters = {'Bugs':['Rabbit', 1940, 'boy'], 'Garfield': ['Cat', 1978, 'boy'], 'Tweety': ['Bird', 1942, 'girl'], 'Sandy': ['Squirrel', 1999, 'female']} print("Printing the original dictionary") print(characters) print("") def invert_dict(characters): inverse = dict() for key in characters: val = characters[key] for list_item in val: if list_item not in inverse: inverse[list_item] = [key] else: inverse[list_item].append(key) return inverse my_invert = invert_dict(characters) print("Printing the inverted dictionary") print(my_invert) Include the following: 1) The input file for your original dictionary (with at least six items).2) The Python program to read from a file, invert the dictionary, and write to a different file.3) The output file for your inverted dictionary.…arrow_forwardCreate two Arrays A with 10 unsorted integer elements and B with 10 unsorted floatelements. Find the largest element in A and B and then sum both of them calling afunction SumAB() by reference. Sort A and B and then call another function StichAB()to merge B with A. Be careful about memory leakage.arrow_forward
- 15.14 LAB: Binary search Binary search can be implemented as a recursive algorithm. Each call makes a recursive call on one-half of the list the call received as an argument. Complete the recursive function BinarySearch() with the following specifications: Parameters: a target integer a vector of integers lower and upper bounds within which the recursive call will search Return value: the index within the vector where the target is located -1 if target is not found The template provides the main program and a helper function that reads a vector from input. The algorithm begins by choosing an index midway between the lower and upper bounds. If target == integers.at(index) return index If lower == upper, return -1 to indicate not found Otherwise call the function recursively on half the vector parameter: If integers.at(index) < target, search the vector from index + 1 to upper If integers.at(index) > target, search the vector from lower to index - 1 The vector…arrow_forward15.14 LAB: Binary search Binary search can be implemented as a recursive algorithm. Each call makes a recursive call on one-half of the list the call received as an argument. Complete the recursive function BinarySearch() with the following specifications: Parameters: a target integer a vector of integers lower and upper bounds within which the recursive call will search Return value: the index within the vector where the target is located -1 if target is not found The template provides the main program and a helper function that reads a vector from input. The algorithm begins by choosing an index midway between the lower and upper bounds. If target == integers.at(index) return index If lower == upper, return -1 to indicate not found Otherwise call the function recursively on half the vector parameter: If integers.at(index) < target, search the vector from index + 1 to upper If integers.at(index) > target, search the vector from lower to index - 1 The vector…arrow_forwardQ1)Suppose you are given an array A of n elements. Your task is to sort n numbers stored in array A by reading the first element of A and placing it on its original position (position after sorting). Then read the second element of A, and place it on its original position. Continue in this manner for the first n-1 elements of A. What type of sorting is this? Write the algorithm and also mention the name of this sorting algorithm. What loop invariant does this algorithm maintain? Give the best-case and worst-case running times of this sorting algorithm. Q2)Consider an array consisting of the following sequence: 1, 4, 9, 16, 25, 49, …, n Suppose a number in the sequence is missing. Write the mathematical process to find the missing number, i.e. some equation. What is the time complexity of finding the missing number in the sequence? Q3)Sort the text “SARHAD UNIVERSITY” in ascending order using the insertion sort algorithm. Discuss also the best, worst and average case complexity of the…arrow_forward
- g. Include a delete() function in LinearProbingHashST that deletes a key-value pair by changing the value to null (while leaving the key in place) and then deleting the pair from the table in resize(). The most difficult decision you must make is when to use resize(). Note: If a future put() action associates a new value with the key, you should replace the null value. Make sure that while deciding whether to enlarge or shrink the table, your programme takes into consideration both the number of such tombstone items and the number of vacant places.arrow_forwardPlease use python codes and don't copy from previous answers. 3.) Consider the matrix list x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]. Write a list comprehension to extract the last column of the matrix [3, 6, 9]. Write another list comprehension to create a vector of twice the square of the middle column [8, 50, 128].arrow_forwardpython code. define the run function. Instructions are given within the quotations. 1)def invert_dict(d): """ Given a dictionary d, create the invert of the dictionary where the key is a value v in d, and v is mapped to a set of keys in original d whose values are equal to v. Return the inverted dictionary mapping value to set of keys """ 2)def histogram(words): """ Given a list of words, create a histogram dictionary where the key is the length of a word and the value is the count of how many words in the list are of that length. Return the histogram dictionary mapping length to word counts """ 3)def max_kv(d): """ Given a dictionary, return a tuple of key value pair where the key is the largest in d. """ 4)def run(): """ Get words list from the file listed in argv[1]; create histogram of count of each word length; create invert dictionary that maps count to list of word length; use invert dictionary to find the list of word length with the most popular word count (use max_kv) """…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License