2) Consider an ordered linked list with n entries in ascending order. Each entry has 2 components: a key component of type int and the usual next link component. a) Write a function to insert a new entry with key x into its proper place. Note that a key may be added as the new first or last entry in the list, and so there are n+1 locations where x could be inserted. b) Assume that each of the n+1 possibilities is equally likely. Determine the average number of times ints are compared in the above insertion algorithm. Your answer should be a precise function of n. An asymptotic answer (such as one that uses big-oh, big-theta, etc.) is not ассeptable.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 17SA
icon
Related questions
Question

Needs C++ Solution!

2) Consider an ordered linked list with n entries in ascending order. Each entry has 2
components: a key component of type int and the usual next link component.
a) Write a function to insert a new entry with key x into its proper place. Note that a key may be
added as the new first or last entry in the list, and so there are n+1 locations where x could be
inserted.
b) Assume that each of the n+1 possibilities is equally likely. Determine the average number of
times ints are compared in the above insertion algorithm. Your answer should be a precise
function of n. An asymptotic answer (such as one that uses big-oh, big-theta, etc.) is not
ассeptable.
Transcribed Image Text:2) Consider an ordered linked list with n entries in ascending order. Each entry has 2 components: a key component of type int and the usual next link component. a) Write a function to insert a new entry with key x into its proper place. Note that a key may be added as the new first or last entry in the list, and so there are n+1 locations where x could be inserted. b) Assume that each of the n+1 possibilities is equally likely. Determine the average number of times ints are compared in the above insertion algorithm. Your answer should be a precise function of n. An asymptotic answer (such as one that uses big-oh, big-theta, etc.) is not ассeptable.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Linked List Representation
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning