ii) Suppose we are having a queue with capacity 3 with values in the queue are 10,20 and 30. Write the algorithm for enqueue and explain with a diagram the enqueue operation in queue if we are inserting value 45 in the queue. i) Consider an array arr {10, 50, 70, 80, 130, 190, 200, 230, 290}. a. Find the location of the item 23 in the array using Binary Search with the help of diagram. b. How many searches are needed to find the element 23. c. What has to be done if the array is not sorted?
ii) Suppose we are having a queue with capacity 3 with values in the queue are 10,20 and 30. Write the algorithm for enqueue and explain with a diagram the enqueue operation in queue if we are inserting value 45 in the queue. i) Consider an array arr {10, 50, 70, 80, 130, 190, 200, 230, 290}. a. Find the location of the item 23 in the array using Binary Search with the help of diagram. b. How many searches are needed to find the element 23. c. What has to be done if the array is not sorted?
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Expert Solution
Step 1
Hey, since there are multiple questions posted, we will answer first question. If you want any specific question to be answered then please submit that question only or specify the question number in your message.
ii)
EXPLANATION:
- Queue is a linear structure that follows a particular order in which the operations are performed.
- They use First In First Out order.
- Queue has two major functions. They are enqueue and dequeue.
- Enqueue is used to add an item to the queue. If the queue is full, then it is an overflow condition.
- Dequeue is used to remove an item from the queue. The items are removed in the same order which they are pushed. If the queue is empty then it is an underflow condition.
- Front variable is used to get the front item from the queue.
- Rear variable is used to get the last item from the queue.
Step 2
ENQUEUE OPERATION ALGORITHM:
procedure enqueue(item)
//Check if the queue is full
if queue is full
/*if the queue is full, it will generate overflow error and exit*/
return overflow
end if
//if the queue is not full, increment the rear pointer
rear<-rear+1
//Add the item to the queue location, where rear is pointing
queue[rear]<-item
//return true
return true
end procedure
Step by step
Solved in 3 steps with 2 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY