Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6. Suppose we construct a data structure to store distinct nonnegative integers as follows: We have a standard list (1-d array) A for which

 

6. Suppose we construct a data structure to store distinct nonnegative integers as follows: We have a standard list (1-d array) A for which each entry has the form [a, ptr] where a is a nonnegative integer and ptr is a pointer to a sorted linked list. The list A is sorted by the integer values. Given an integer k which we wish to store, Let a be the leftmost half (rounding down) of the digits in k and let be the rightmost remaining digits. (For example if k = 1234 then a = 12 and B 34 and if k 12345 then a = 12 and = 345.) = = We first see if [a, ptr] (for some pointer ptr) exists in A and if it does then we insert into the linked list which ptr points to, otherwise we create a linked list pointed to by ptr consisting of the value and insert [a, ptr] into A. (a) Illustrate the data structure look like after the following are inserted: k = = 46, 456, 1234, 409 (b) As a function of n, the number of elements in the data structure, What is the worst-case O time complexity of inserting some integer k? Assume that we can use a binary search on A (but not on the linked lists) and that extracting a and from k are O(1). Explain.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Programming questions

Question

Find a, b, c and d so that 7 7

Answered: 1 week ago

Question

What is the financial outlook of the organization?

Answered: 1 week ago