A linear list is being maintained circularly in an array c[0...n-1] with front, and rear set up as for circular queues. a) Draft a formula/algorithm in terms of front, rear, and n for the number of elements in the list. Answer: Algorithm If Front == -1 then number of elements = 0 If Front == Rear then number of elements = 1 If Front < Rear then number of elements = Rear - Front +1 If Front> Rear then number of elements = (Front - n) + (Rear + 1) b) Write an algorithm to delete the k-th element in the list. Answer: Algorithm We have to transverse the ayerse list and do following (a) Count node before deletion. b) If (count ==k) that means current node is to be deleted. (i) Delete current nodes (ii) Reset count as 0, i.e., do count = 0. (c) Update the previous node if cQunt != 0, if count is 0 that means that node is a starting point. (d) Update pointer and continue until all k-th node gets deleted. c) Write an algorithm to insert an element y immediately after the k-th element. Answer: Replace the current kh element with new element as Step 1) edit list to k-1 location Step 2) set (k-1)-> next node = new element which you want to insert. Step 3) new element-> next =k-> next. Step 4) free older k which is now replaced with new element d) Calculate the time complexity of your algorithms for b) and c). Answer: The time complexity of enQueue(value) or deQueue(value) operation is Q(1) because we have the hands over front and rear at any time. And we simply insert at rear and delete from front.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Circular Lists in C PROGRAM

this is what I have, is it correct?

A linear list is being maintained circularly in an array c[0...n-1] with front, and rear set up as for
circular queues.
a) Draft a formula/algorithm in terms of front, rear, and n for the number of elements in the
list.
Answer:
Algorithm
If Front =
-1 then number of elements = 0
If Front == Rear then number of elements = 1
If Front < Rear then number of elements = Rear - Front +1
If Front > Rear then number of elements = (Front - n) + (Rear + 1)
b) Write an algorithm to delete the k-th element in the list.
Answer:
Algorithm
We have to transverse the ayerse, list and do following
(a) Count node before deletion.
(b) If (count == k) that means current node is to be deleted.
(i) Delete current nodes
(ii) Reset count as 0, i.e., do count = 0.
(c) Update the previous node if count = 0, if count is 0 that means that node is a starting point.
(d) Update pointer and continue until all k-th node gets deleted.
c) Write an algorithm to insert an element y immediately after the k-th element.
Answer:
Replace the current kh element with new element as
Step 1) edit list to k-1 location
Step 2) set (k-1)-> next node = new element which you want to insert.
Step 3) new element-> next = k-> next.
Step 4) free older k which is now replaced with new element
d) Calculate the time complexity of your algorithms for b) and c).
Answer:
The time complexity of enQueue(value) or deQueue(value) operation is Q(1) because we have
the hands over front and rear at any time. And we simply insert at rear and delete from front.
Transcribed Image Text:A linear list is being maintained circularly in an array c[0...n-1] with front, and rear set up as for circular queues. a) Draft a formula/algorithm in terms of front, rear, and n for the number of elements in the list. Answer: Algorithm If Front = -1 then number of elements = 0 If Front == Rear then number of elements = 1 If Front < Rear then number of elements = Rear - Front +1 If Front > Rear then number of elements = (Front - n) + (Rear + 1) b) Write an algorithm to delete the k-th element in the list. Answer: Algorithm We have to transverse the ayerse, list and do following (a) Count node before deletion. (b) If (count == k) that means current node is to be deleted. (i) Delete current nodes (ii) Reset count as 0, i.e., do count = 0. (c) Update the previous node if count = 0, if count is 0 that means that node is a starting point. (d) Update pointer and continue until all k-th node gets deleted. c) Write an algorithm to insert an element y immediately after the k-th element. Answer: Replace the current kh element with new element as Step 1) edit list to k-1 location Step 2) set (k-1)-> next node = new element which you want to insert. Step 3) new element-> next = k-> next. Step 4) free older k which is now replaced with new element d) Calculate the time complexity of your algorithms for b) and c). Answer: The time complexity of enQueue(value) or deQueue(value) operation is Q(1) because we have the hands over front and rear at any time. And we simply insert at rear and delete from front.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
ADT and Class
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education