0% found this document useful (0 votes)
6 views4 pages

Answers

The document contains answers to the COMP 301 exam, covering memory requirements for data structures, applications of graphs, algorithms for stack operations, and differences between data structures and algorithms. It also includes tree constructions for binary search and heap trees, Huffman tree and codes, sorting algorithms, and tree traversal results. Additionally, it discusses hash tables and their functions.

Uploaded by

theeeclipse17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Answers

The document contains answers to the COMP 301 exam, covering memory requirements for data structures, applications of graphs, algorithms for stack operations, and differences between data structures and algorithms. It also includes tree constructions for binary search and heap trees, Huffman tree and codes, sorting algorithms, and tree traversal results. Additionally, it discusses hash tables and their functions.

Uploaded by

theeeclipse17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Below are answers to the questions from the COMP 301 exam:

SECTION A – COMPULSORY

Question 1

(a) Compute the memory requirements:


Assume each data item requires 8 bytes (64 bits).

1. Array:
Memory requirement=1000×8=8000\text{Memory requirement} = 1000 \times 8 = 8000
bytes.

2. Singly Linked List:


Each node stores the data (8 bytes) and a pointer (8 bytes):
Memory requirement=1000×(8+8)=16000\text{Memory requirement} = 1000 \times (8 + 8) =
16000 bytes.

3. Doubly Linked List:


Each node stores the data (8 bytes) and two pointers (16 bytes):
Memory requirement=1000×(8+16)=24000\text{Memory requirement} = 1000 \times (8 +
16) = 24000 bytes.

(b) Three Applications of Graphs:

1. Social network modeling (e.g., finding connections between users).

2. Route optimization in navigation systems.

3. Dependency resolution in project management.

(c) Algorithm for Pop Operation in a Stack (Flowchart Representation):


A flowchart can represent the following steps:

1. Check if the stack is empty (underflow).

2. If not empty, access the top element.

3. Decrease the top pointer.

4. Return the popped element.

(A diagram is required; let me know if you'd like me to draw one.)

(d) When to Prefer Linked List Over Array:

1. When frequent insertions or deletions are required.

2. When the size of the data structure is unknown beforehand.


3. To save memory for large datasets with sparse data (no need for contiguous memory).

(e) Differences:

1. Breadth First Search (BFS) vs. Depth First Search (DFS):

o BFS explores all neighbors level by level, using a queue.

o DFS explores as deep as possible, using a stack or recursion.

2. Abstract Data Type (ADT) vs. Data Structure:

o ADT: Logical description of data and operations (e.g., stack).

o Data Structure: Implementation of an ADT (e.g., stack using an array).

3. Enqueue vs. Dequeue in Queue:

o Enqueue: Adds an element to the rear of the queue.

o Dequeue: Removes an element from the front of the queue.

(f) Convert Decimal 175 to Binary Using Stack:


Steps:

1. Divide 175 by 2, record remainders: 175→87→43→21→10→5→2→1175 \rightarrow 87 \


rightarrow 43 \rightarrow 21 \rightarrow 10 \rightarrow 5 \rightarrow 2 \rightarrow 1.

2. Pop stack: Binary is 1010111110101111.

(g) Linked List Representing a Stack:


A linked list can be used by making the head node the "top." Push operations insert at the head, and
pop removes the head.

SECTION B – ANSWER ANY TWO

Question 2:

(i) Balanced Binary Search Tree:


Construct tree:

42

/ \

30 80

/\ /

10 50 15
(ii) Heap Tree:
Construct a max heap:

80

/ \

50 42

/\ /

15 30 10

Question 3:

(i) Huffman Tree:


Construct tree with frequencies:

(150)

/ \

(65) (85)

/ \ / \

(30) (35) (40) (45)

(ii) Huffman Codes:


Assign binary codes:

 a: 000

 b: 001

 c: 01

 d: 10

 k: 11

Question 4: Sorting

(i) Bubble Sort: Compare and swap adjacent elements iteratively.


(ii) Merge Sort: Divide and conquer, merge sorted sublists.
(iii) Quick Sort: Select pivot, partition, sort sublists recursively.
(iv) Selection Sort: Select the smallest, place at sorted position.

Question 5

(a) Tree Traversal Results:


Given tree example:
 Preorder: Root → Left → Right.

 Inorder: Left → Root → Right.

 Postorder: Left → Right → Root.

(b) Hash Table:


(i) Hash function (e.g., h(x)=x%10h(x) = x \% 10): Place data in appropriate slots.
(ii) Searching: Calculate hash, check slot.

Let me know if you need detailed diagrams or expanded explanations!

You might also like