Question

How do you implement lists and related ADTs with arrays? Include in your analysis fixed-sized arrays,...

How do you implement lists and related ADTs with arrays? Include in your analysis fixed-sized arrays, expandable arrays, and the pros and cons of using arrays to implement them.

Homework Answers

Answer #1

Implementing List using array.
here we store elements of list into an array.
functions:
(1)insertion(value , position) : for inserting an element at given position ,we will shift right all elements after that position ,so that it create a space for new elements .
if it is fixed-sized array and array is full then no insertion allowed.
and if it is expandable array and array is full then first expand the array then follow insertion procedure.

(2)deletion(value): to delete first occurrence of value in array ,first we need to search value in the array.
if(value not found) return.
else shift all right elements of given value 1 position left.

(3)get(position) : To get an element from array at any given position,first we check whether array contain position number of element s or not.
if(it contain)then return arr[position-1];

pro:
(a)Accessing an element in an array is fast.we can access any element in array just using index value(O(1) time)

(b)Arrays have better cache locality that can make a pretty big difference in performance.

cons:
(a)Inserting a new element in an array of elements is expensive because a room has to be created for the new elements and to create room existing elements have to be shifted.

(b)Operations like insertion and deletion in arrays consume a lot of time.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
If linked lists are so much better than arrays, why do you think arrays are used...
If linked lists are so much better than arrays, why do you think arrays are used at all? Briefly explain your thought in 1 paragraph.
What gear will you need when you do your fieldwork project? How will you obtain it?...
What gear will you need when you do your fieldwork project? How will you obtain it? 2. What organizing principles can help you study “music in your own backyard?” 3. What four approaches can you take to select a subject for your musical ethnography? 4. What is documentation, description, and interpretation, and how are they related in a musical ethnography? 5. Why are interviews useful in fieldwork? What makes an interview good or bad? 6. What is the difference between...
How do you define a triangular two-dimensional array using just vectors, not arrays or pointers? (C++)
How do you define a triangular two-dimensional array using just vectors, not arrays or pointers? (C++)
summarize key components of donor behavior and how do you implement these to your annual giving...
summarize key components of donor behavior and how do you implement these to your annual giving plan.
1.How do you think this affect proposals for Medicare Reform? 2.What are the pros and cons...
1.How do you think this affect proposals for Medicare Reform? 2.What are the pros and cons purchasing LTC insurance?
Now that the ACA/AHCA is in full effect, how do you think this will impact the...
Now that the ACA/AHCA is in full effect, how do you think this will impact the need for quality health care practitioners? How will this impact the quality of healthcare overall - or in the long term view? What do you think are the Pros and Cons of the current legislation? (minimum of 200 words)
You are considering the purchase of a $600,000 house using a regular fixed rate mortgage loan...
You are considering the purchase of a $600,000 house using a regular fixed rate mortgage loan with a 20% down payment; what is the monthly payment (not including taxes and insurance) using a 30-year (5.0%), 20-year (4.50%), and a 15-year (4.00%)? How much total interest would you pay using the three different loans over the course of the loan? What are the pros and cons of using a 5/1 adjustable rate mortgage?
Specify and implement an ADT character string by using a linked chain of characters. Include typical...
Specify and implement an ADT character string by using a linked chain of characters. Include typical operations such as fi nding its length, appending one string to another, fi nding the index of the leftmost occurrence of a character in a string, and testing whether one string is a substring of another. Do not #include<string>...you are making something like a STL string. Also do not use an array or vector...the point is to practice linked lists. Remember the last character...
Describe two test-taking strategies you have learned this week and how you will implement them on...
Describe two test-taking strategies you have learned this week and how you will implement them on your next exam
Give it your best shot: How do you think you would need to extend Lagrangian analysis...
Give it your best shot: How do you think you would need to extend Lagrangian analysis to describe the “motion” of a quantum particle?
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT