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.
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?
Do a regression analysis using R software OR Excel. You may use legitimate sources of data...
Do a regression analysis using R software OR Excel. You may use legitimate sources of data such as Yahoo finance, nasdaq.com, bloomberg.com, US Dept of Labor etc. The data you analyze should be business related or economics related. Attempt to explain why you received the results of your analysis. What do you believe caused these results? Is there anything you found in the news or online which would explain these results?
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(),...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(), and isEmpty(). For this assignment, enqueue() will be implemented in an unusual manner. That is, in the version of enqueue() we will use, if the element being processed is already in the queue then the element will not be enqueued and the equivalent element already in the queue will be placed at the end of the queue. Additionally, you must implement a circular queue....
C++ ***Please include makefile*** Requirements: You should name your Prority Queue class as PQ. The queue...
C++ ***Please include makefile*** Requirements: You should name your Prority Queue class as PQ. The queue must be able to hold unlimited number of integers. It has two key operations: Push and Pop, which should have the time complexity of O(logn). Files to turn in: You need to turn in four files: makefile, main.C, PQ.C, PQ.h. You should have a main.C that reads in or generates some integers, pushes them into the PQ one by one, and pops and prints...
Sensitivity analysis If you can sell a product for $67 and it costs you $28 per...
Sensitivity analysis If you can sell a product for $67 and it costs you $28 per unit to produce, while also paying $3,900 per month in fixed expenses, how many units must you sell each month in order to earn a monthly profit of $2,500? Show all your work. Using the information from the first problem, your variable costs per unit include labor ($18) and parts ($10). Your fixed costs include maintenance of $750, rent and utilities of $2000, and...
This problem has two parts.  In Part A, you are asked to do account analysis based on...
This problem has two parts.  In Part A, you are asked to do account analysis based on cost and activity information that you are given for one particular month. In Part B, you are asked to do the high-low method based on cost and activity information for that same month and another one. Note that for both parts, you are asked to make predictions for the same month. Each part of the problem is worth five points and has two questions....