Professional Documents
Culture Documents
Ver. 1.0
Session 11
However, the rate at which the requests are received is much faster than the rate at which they are processed.
Therefore, you need to store the request somewhere until they are processed.
Session 11
FRONT
REAR
Ver. 1.0
Session 11
Answer:
FIFO
Ver. 1.0
Session 11
FRONT
REAR
Ver. 1.0
Session 11
FRONT
REAR REAR
Ver. 1.0
Session 11
FRONT FRONT
REAR
Ver. 1.0
Session 11
Answer:
rear, front
Ver. 1.0
Session 11
Ver. 1.0
Session 11
FRONT = 1 REAR = 1
Ver. 1.0
Session 11
2. Increment REAR by 1. 3. Store the element at index position REAR in the array.
Ver. 1.0
Session 11
Increment REAR by 1. Store the element at index position REAR in the array.
FRONT = 1 REAR = 1
10 0 1 2 3 4
Ver. 1.0
Session 11
Increment REAR by 1. Store the element at index position REAR in the array.
FRONT = 1 REAR = 1
10 0 1 2 3 4
Ver. 1.0
Session 11
Increment REAR by 1. Store the element at index position REAR in the array.
FRONT = 1 REAR = 1
10 0 1 2 3 4
Ver. 1.0
Session 11
Increment REAR by 1. Store the element at index position REAR in the array.
REAR = 1
10 0 1 2 3 4
Ver. 1.0
Session 11
Increment REAR by 1. Store the element at index position REAR in the array.
310 0 1 2 3 4
Insertion complete
Ver. 1.0
Session 11
Increment REAR by 1. Store the element at index position REAR in the array.
310 0 1 2 3 4
Ver. 1.0
Session 11
Increment REAR by 1. Store the element at index position REAR in the array.
310 0 1 2 3 4
Ver. 1.0
Session 11
Increment REAR by 1. Store the element at index position REAR in the array.
310 0 1 2 3 4
Ver. 1.0
Session 11
Increment REAR by 1. Store the element at index position REAR in the array.
310 0
5 1 2 3 4
Insertion complete
Ver. 1.0
Session 11
Increment REAR by 1. Store the element at index position REAR in the array.
310 0
5 1 2 3 4
Ver. 1.0
Session 11
Increment REAR by 1. Store the element at index position REAR in the array.
310 0
5 1 2 3 4
Ver. 1.0
Session 11
Increment REAR by 1. Store the element at index position REAR in the array.
310 0
5 1 2 3 4
Ver. 1.0
Session 11
Increment REAR by 1. Store the element at index position REAR in the array.
310 0
5 1
7 2 3 4
Insertion complete
Ver. 1.0
Session 11
10
Increment REAR by 1. Store the element at index position REAR in the array.
310 0
5 1
7 2 3 4
Ver. 1.0
Session 11
10
Increment REAR by 1. Store the element at index position REAR in the array.
310 0
5 1
7 2 3 4
Ver. 1.0
Session 11
10
Increment REAR by 1. Store the element at index position REAR in the array.
310 0
5 1
7 2 3 4
Ver. 1.0
Session 11
10
Increment REAR by 1. Store the element at index position REAR in the array.
310 0
5 1
7 2
10 3 4
Insertion complete
Ver. 1.0
Session 11
15
Increment REAR by 1. Store the element at index position REAR in the array.
310 0
5 1
7 2
10 3 4
Ver. 1.0
Session 11
15
Increment REAR by 1. Store the element at index position REAR in the array.
310 0
5 1
7 2
10 3 4
Ver. 1.0
Session 11
15
Increment REAR by 1. Store the element at index position REAR in the array.
310 0
5 1
7 2
10 3 4
Ver. 1.0
Session 11
15
Increment REAR by 1. Store the element at index position REAR in the array.
310 0
5 1
7 2
10 3
15 4
Insertion complete
Ver. 1.0
Session 11
Ver. 1.0
Session 11
Ver. 1.0
Session 11
3 0
5 1
7 2
10 3
15 4
Ver. 1.0
Session 11
FRONT = 0
REAR = 4
310 0
5 1
7 2
10 3
15 4
Ver. 1.0
Session 11
FRONT = 0 FRONT = 1
REAR = 4
10 0
5 1
7 2
10 3
15 4
Ver. 1.0
Session 11
FRONT = 1
REAR = 4
10 0
5 1
7 2
10 3
15 4
Ver. 1.0
Session 11
FRONT = 1
REAR = 4
10 0
5 1
7 2
10 3
15 4
Ver. 1.0
Session 11
FRONT = 1 FRONT = 2
REAR = 4
10 0 1
7 2
10 3
15 4
Ver. 1.0
Session 11
10 0 1 2
10 3
15 4
REAR is at the last index position. Therefore, you cannot insert elements in this queue, even though there is space for them. This means that all the initial vacant positions go waste.
Ver. 1.0
Session 11
FRONT = 0
REAR = 3
3 10 0
5 1
7 2
10 3 4
Ver. 1.0
Session 11
FRONT = 0
REAR = 3
5 10 0
5 1
7 2
10 3 4
Ver. 1.0
Session 11
FRONT = 0
REAR = 3
5 10 0
7 1
7 2
10 3 4
Ver. 1.0
Session 11
FRONT = 0
REAR = 3
5 10 0
7 1
10 2
10 3 4
Ver. 1.0
Session 11
FRONT = 0
REAR = 2REAR = 3
5 10 0
7 1
10 2 3 4
Ver. 1.0
Session 11
FRONT = 0
REAR = 2
5 10 0
7 1
10 2 3 4
Ver. 1.0
Session 11
Insert 5
510 0 1 2 10 3 15 4
Ver. 1.0
Session 11
[0]
[4]
[1]
REAR = 3
10 [3]
7 [2]
FRONT = 2
Ver. 1.0
Session 11
10 0
20 1
23 2
10 3 4
3. 4.
Ver. 1.0
Session 11
15
REAR = 3
10 0
20 1
23 2
10 3 4
2. 3.
Ver. 1.0
Session 11
15
REAR = 3
10 0
20 1
23 2
10 3 4
1. 2.
Ver. 1.0
Session 11
15
REAR = 3 = 4 REAR
10 0
20 1
23 2
10 3 4
1. 1.
Ver. 1.0
Session 11
15
REAR = 4
10 0
20 1
23 2
10 3
15 4
3. 1.
Insertion complete
Ver. 1.0
Session 11
17
REAR = 4
10 0
20 1
23 2
10 3
15 4
3. 4.
Ver. 1.0
Session 11
17
REAR = 4
10 0
20 1
23 2
10 3
15 4
2. 3.
Ver. 1.0
Session 11
17
REAR = 4
10 0
20 1
23 2
10 3
15 4
1. 2.
Ver. 1.0
Session 11
17
REAR = 4
10 0
20 1
23 2
10 3
15 4
3. 4.
Ver. 1.0
Session 11
17
10 0
20 1
23 2
10 3
15 4
3. 4.
Ver. 1.0
Session 11
17
17 10 0
20 1
23 2
10 3
15 4
3. 1.
Insertion complete
Ver. 1.0
Session 11
25
17 10 0
20 1
23 2
10 3
15 4
3. 4.
Ver. 1.0
Session 11
25
17 10 0
20 1
23 2
10 3
15 4
2. 3.
Ver. 1.0
Session 11
25
17 10 0
20 1
23 2
10 3
15 4
1. 2.
Ver. 1.0
Session 11
25
17 10 0
20 1
23 2
10 3
15 4
1. 1.
Before cannot be incremented operation, you should always check for the Inserting an element in ainsert because the queue is full. REAR implementing an full queue leads to queue overflow. queue full condition.
Ver. 1.0
Session 11
If FRONT = REAR + 1
OR
REAR = 2 FRONT = 3
310 0
5 1
7 2
10 3
15 4
17 10 0
20 1
23 2
10 3
15 4
Ver. 1.0
Session 11
If queue is empty (If FRONT = 1): a. b. c. Set FRONT = 0 Set REAR = 0 Go to Step 5
1.
2. 3.
Ver. 1.0
Session 11
Ver. 1.0
Session 11
REAR = 0
FRONT = 4
17 10 0
20 1 2 3
15 4
3.
Increment FRONT by 1
Ver. 1.0
Session 11
17 10 0
20 1 2 3
15 4
3.
Increment FRONT by 1
Ver. 1.0
Session 11
17 10 0
20 1 2 3
15 4
2.
Increment FRONT by 1
Ver. 1.0
Session 11
17 10 0
20 1 2 3
15 4
1.
Increment FRONT by 1
Ver. 1.0
Session 11
17 10 0
20 1 2 3
15 4
3.
Increment FRONT by 1
Ver. 1.0
Session 11
17 10 0
20 1 2 3 4
3.
Increment FRONT by 1
Deletion complete
Ver. 1.0
Session 11
17 10 0
20 1 2 3 4
3.
Increment FRONT by 1
Ver. 1.0
Session 11
17 10 0
20 1 2 3 4
2.
Increment FRONT by 1
Ver. 1.0
Session 11
17 10 0
20 1 2 3 4
1.
Increment FRONT by 1
Ver. 1.0
Session 11
17 10 0
20 1 2 3 4
1.
Increment FRONT by 1
Deletion complete
Ver. 1.0
Session 11
10 0
20 1 2 3 4
3.
Increment FRONT by 1
Ver. 1.0
Session 11
10 0
20 1 2 3 4
2.
Increment FRONT by 1
Ver. 1.0
Session 11
FRONT = 1
10 0
20 1 2 3 4
3.
Increment FRONT by 1
Ver. 1.0
Session 11
FRONT = 1 REAR = 1
10 0 1 2 3 4
3.
Increment FRONT by 1
Ver. 1.0
Session 11
FRONT = 1 REAR = 1
10 0 1 2 3 4
2.
Increment FRONT by 1
Deletion complete
Ver. 1.0
Session 11
FRONT = 1 REAR = 1
10 0 1 2 3 4
3.
Increment FRONT by 1
Therefore, before implementing a delete operation, you first need to check whether the queue is empty or not.
Ver. 1.0
Session 11
2.
3.
Increment FRONT by 1
Ver. 1.0
Session 11
Answer:
If you implement a queue in the form of a linear array, you can add elements only in the successive index positions. However, when you reach the end of the queue, you cannot start inserting elements from the beginning, even if there is space for them at the beginning. You can overcome this disadvantage by implementing a queue in the form of a circular array. In this case, you can keep inserting elements till all the index positions are filled. Hence, it solves the problem of unutilized space.
Ver. 1.0
Session 11
Ver. 1.0
Session 11
To solve this problem, you should implement the queue in the form of a linked list.
Ver. 1.0
Session 11
Ver. 1.0
Session 11
Ver. 1.0
Session 11
4.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
1. 2.
3.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
1. 1.
2.
10 3
4.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
2. 1.
1.
10 3
3.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
2. 3.
1.
10 3
2.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
2. 3.
4.
10 3
6.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
2. 3.
4.
10 3
6.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
2. 3. 4.
FRONT REAR
10 3
6.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
2. 3. 4.
FRONT REAR
10 3
6.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
1. 2. 3.
FRONT REAR
10 3
5.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
1. 1. 2.
FRONT REAR
10 3
10 5
4.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
2. 1. 1.
FRONT REAR
10 3
10 5
3.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
2. 3. 1.
FRONT REAR
10 3
10 5
2.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
2. 3. 4.
FRONT REAR
10 3
10 5
1.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
2. 3. 4.
FRONT REAR
REAR
10 3
10 5
1.
Make the next field of REAR point to the new node. Make REAR point to the new node.
Ver. 1.0
Session 11
Ver. 1.0
Session 11
Mark the node marked FRONT as current Make FRONT point to the next node in its sequence Release the memory for the node marked as current
FRONT 310 5 7
REAR 10
4.
Ver. 1.0
Session 11
Mark the node marked FRONT as current Make FRONT point to the next node in its sequence Release the memory for the node marked as current
FRONT 310 5 7
REAR 10
3.
Ver. 1.0
Session 11
Mark the node marked FRONT as current Make FRONT point to the next node in its sequence Release the memory for the node marked as current
REAR 10
2.
Ver. 1.0
Session 11
Mark the node marked FRONT as current Make FRONT point to the next node in its sequence Release the memory for the node marked as current
FRONT 5 7
REAR 10
1.
Ver. 1.0
Session 11
Mark the node marked FRONT as current Make FRONT point to the next node in its sequence Release the memory for the node marked as current
FRONT 3 5 7
REAR 10
1.
Ver. 1.0
Session 11
Answer:
In a linked list, you can insert and delete elements anywhere in the list. However, in a linked queue, insertion and deletion takes place only from the ends. More specifically, insertion takes place at the rear end and deletion takes place at the front end of the queue.
Ver. 1.0
Session 11
Ver. 1.0
Session 11
Ver. 1.0
Session 11
Session 11
Ver. 1.0
Session 11
Ver. 1.0
Session 11
Ver. 1.0
Session 11
Session 11
An alternate searching algorithm that overcomes these limitations and provides good efficiency is hashing.
Ver. 1.0
Session 11
Ver. 1.0
Session 11
Ver. 1.0
Session 11
Ver. 1.0
Session 11
There are various techniques that can be used to design a hash function:
Truncation method Modular method Mid Square method Folding method
Ver. 1.0
Session 11
Ver. 1.0
Session 11
Ver. 1.0
Session 11
Ver. 1.0
Session 11
The fundamental principle of hashing is to convert a given key value to an offset address to retrieve a record. In hashing, conversion of the key to an address is done by a relation (formula), which is known as a hashing function. The situation in which the hash function generates the same hash value for two or more keys is called collision. The occurrence of collision can be minimized by using a good hash function.
Ver. 1.0
Session 11
There are various techniques that can be used to design a hash function, some of which are:
Truncation method Modular method Mid Square method Folding method
The problem of collision can be resolved by using a method called separate chaining.
Ver. 1.0
Session 11