Chapter 34 - Queues Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

How is an abstract data type created?

A

» Data type that is created by the programmer, rather than defined within the programming language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are some examples of structures contained in abstract data types?

A

» Queues
» Stacks
» Trees
» Graphs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an abstract data type?

A

» Logical description of how the data is viewed and the operations that can be performed on it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is one good example of data abstraction?

A

» Where its up to the programmer to decide how to construct the data structure
» This encapsulates around the data, hiding the details of implementation from the user

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a queue?

A

» A first in First out (FIFO) data structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where are elements added in a queue?

A

» At the end of a queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Where are elements retrieved from?

A

» From the front of a queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the sequence of data items in a queue is determined by?

A

» By the order they are inserted in

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an example of how a queue is in real life?

A

» Imagine people printing out work to be printed at more or less the same time
» By putting the output into a queue on disk, the output is printed on a first come first served basis

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a queue described as?

A

» An ordered collection of items which are added at the rear of the queue, and remove front the front

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What happens if the first person in the queue leaves?

A

» The front pointer is made to the next point, the elements do not move, when a new person joins the queue, the rear pointer moves to the last item

» Think of a queue, in a doctor’s surgery, people leave and join the queue, but no one moves chairs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does enQueue(item) do?

A

» Add a new item to the rear of the queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does deQueue do?

A

» Remove the front item from the queue and return it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does isEmpty() do?

A

» Test to see whether the queue is empty

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does isFull() do?

A

» Test to see whether queue is full

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a front pointer also known as?

A

» Header pointer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a queue overflow?

A

» Where items are enqueued, added to the back in a full queue

18
Q

What is a queue underflow?

A

» While trying to dequeue an item from an empty queue

19
Q

What is a queue an example of?

A

» Linear data structure

20
Q

What are the 2 ways an abstract data type can be implemented?

A

» Using either a dynamic or static data structure

21
Q

What is a dynamic data structure?

A

» Refers to a collection of data in memory, that has the ability to grow or shrink in size
» Does with the aid of the heap

22
Q

What is the heap?

A

» A portion of memory from which space is automatically allocated or de-allocated as required

23
Q

What is a disadvantage of a dynamic data structure?

A

» The data structure may cause overflow if it exceeds the maximum memory limit, and the program will crash

24
Q

What are the benefits of inbuilt dynamic data structures?

A

» Many methods such as append are already written in

25
Q

How can queues be implemented as a dynamic data structure?

A

» Maximum size of data structure is not known in advance
» Queue can be given some arbitrary maximum to avoid causing memory overflow

26
Q

What is a static data structure?

A

» such as an array is fixed in size, and cannot increase in size or free up memory while the program is running

27
Q

What is an array suitable for?

A

» Storing fixed number of items

28
Q

What are the disadvantages of using an array to implement a queue?

A

» Size of array has to be decided by the programmer in advance

29
Q

What is the 1st way to implement a linear queue in an array or a list?

A

» As items leave the queue, all items move up one position in allocated memory

30
Q

What is the 2nd way to implement a linear queue?

A

» Can be implemented as an array with pointers to the front and rear of the queue
» Integer holding the size of the array is needed
» As well a variable giving the number of items in the array is needed

31
Q

What is the problem caused by implementing a queue as an array?

A

» Both back and front pointers are moving in the same direction as items are added and removed from the queue, the array will quickly run out of space

32
Q

What is one way of overcoming the limitation of a static data structure such as an array?

A

» To implement the queue as a circular queue

33
Q

What happens in a circular queue?

A

» The last element say q[5] will be made to point q[o] when the next person joins the queue, assuming the element is empty

34
Q

What is a priority queue?

A

» Is like a queue in that items are dequeued by removing them from the front of the queue

35
Q

What are queues used for?

A

» Process scheduling
» Transferring data between processors and printer spooling
» Performing breadth-first searches on graph data structures

36
Q

What is peeking?

A

» Returning the value from the front of the queue without removing it

37
Q

What is the difference between a Queue and a Stack?

A

» Queue has 2 pointers whereas a Stack has one poitner

38
Q

What are 3 main operations you need to know for a queue?

A

» Enqueue - Adding an item to the back of the queue
» Dequeue - Removing an item from the front of the queue
» Peek - Returning the value from the front of the queue without removing it

39
Q

What are the steps to add an item to a queue?

A

» Check for queue overflow. Output an error if the queue is full
» Increment the back/tail pointer
» Insert the new item data at the location pointed by the back pointer

40
Q

What are the 2 pointers in a Queue?

A

» Header pointer
» Back/tail pointer