BIT201 ยท 2082 ยท 5 marks
What is simple queue? Describe about any three types of graphs. [2+3]
What is simple queue? Describe about any three types of graphs. [2+3]
Quick answer
A simple queue (also called a linear queue) is a linear data structure that follows the FIFO (First In First Out) principle, meaning the element inserted first is the element removed first.
Simple Queue and Types of Graphs
Simple Queue [2 marks]
Key characteristics:
- Elements are inserted from the REAR end
- Elements are deleted from the FRONT end
- Once the rear reaches the maximum size, no more insertions are possible (even if space exists at the front after deletions)
FRONT REAR
| |
v v
[ 10 | 20 | 30 | 40 | 50 ]
^ ^
Delete Insert
Basic Operations:
- Enqueue: Insert an element at the rear
- Dequeue: Remove an element from the front
- Peek/Front: View the front element without removing it
Three Types of Graphs [3 marks]
A graph is a non-linear data structure consisting of a set of vertices (nodes) and edges (connections) represented as G = (V, E).
1. Directed Graph (Digraph)
A graph in which every edge has a specific direction is called a directed graph. The edges are represented as ordered pairs (u, v), meaning the edge goes from vertex u to vertex v but not necessarily from v to u.
A -----> B
| |
v v
C -----> D
- Edge (A, B) means A points to B
- Used in: web page linking, task scheduling
2. Undirected Graph
A graph in which edges have no direction is called an undirected graph. The edges are represented as unordered pairs {u, v}, meaning the connection is bidirectional.
A ----- B
| |
| |
C ----- D
- Edge {A, B} means both A connects to B and B connects to A
- Used in: social networks, road maps
3. Weighted Graph
A graph in which each edge is assigned a numerical value (weight or cost) is called a weighted graph. It can be either directed or undirected.
A ---5--- B
| |
3 7
| |
C ---2--- D
- The weight may represent distance, cost, time, or capacity
- Used in: shortest path algorithms (Dijkstra's), network routing, GPS navigation
Note: Other types include cyclic/acyclic graphs, connected/disconnected graphs, and complete graphs.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.