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

Dynamic Storage Management & Data Structures: Q5. Solve Any TWO of The Following Questions (2x6 12)

The document discusses dynamic storage management and data structures, focusing on stack operations, queue insertion algorithms, and postfix evaluation using stacks. It also covers characteristics of good algorithms, analysis of time and space complexity, methods for storing binary tree elements, and the concept of Abstract Data Types (ADT) with a specific emphasis on queues. Additionally, it defines key graph terminology including undirected graphs, vertex degrees, simple paths, and cycles.

Uploaded by

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

Dynamic Storage Management & Data Structures: Q5. Solve Any TWO of The Following Questions (2x6 12)

The document discusses dynamic storage management and data structures, focusing on stack operations, queue insertion algorithms, and postfix evaluation using stacks. It also covers characteristics of good algorithms, analysis of time and space complexity, methods for storing binary tree elements, and the concept of Abstract Data Types (ADT) with a specific emphasis on queues. Additionally, it defines key graph terminology including undirected graphs, vertex degrees, simple paths, and cycles.

Uploaded by

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

Dynamic Storage Management & Data Structures

Q5. Solve any TWO of the following questions (2x6 = 12)

a) Stack Operations

A stack follows the LIFO (Last In, First Out) principle.

Given an initial stack: A, D, E, F, G (Top), and N = 6 (max size), the operations are performed as

follows:

1. Push(K) -> Stack full (N=6)

2. Pop(Item) -> Removes K

3. Push(L) -> Success

4. Push(S) -> Overflow (Stack full)

5. Pop(Item) -> Removes L

6. Push(T) -> Success

b) Queue and Insertion Algorithm

A Queue follows FIFO (First In, First Out) principle.

Algorithm to insert an item into a queue using a singly linked list:

struct Node {

int data;

struct Node* next;

};

struct Queue {

struct Node *front, *rear;

};

void enqueue(struct Queue* q, int value) {


struct Node* temp = (struct Node*)malloc(sizeof(struct Node));

temp->data = value;

temp->next = NULL;

if (q->rear == NULL) {

q->front = q->rear = temp;

return;

q->rear->next = temp;

q->rear = temp;

c) Postfix Evaluation using Stack

Given postfix expression: 10, 5, 6, *, +, 8, /

Stepwise stack operations:

1. Push(10)

2. Push(5)

3. Push(6)

4. Pop(5,6) -> Multiply -> Push(30)

5. Pop(10,30) -> Add -> Push(40)

6. Push(8)

7. Pop(40,8) -> Divide -> Push(5)

Final Result: 5

Q6. Solve all of the following questions (4x3 = 12)

a) Characteristics of Good Algorithm & Analysis

Characteristics:

1. Correctness
2. Efficiency

3. Finiteness

4. Definiteness

5. Generality

Analysis:

- Time Complexity: Measures execution time based on input size.

- Space Complexity: Measures memory usage.

b) Storing Binary Tree Elements

Binary Tree:

/\

B C

/\

D F

Storage:

- One-Dimensional Array: A, B, C, D, F

- Linked List: Each node has data, left child, right child pointers.

c) Abstract Data Type (ADT) & Queue as ADT

ADT is a mathematical model defining operations without implementation details.

Queue is an ADT because it defines enqueue(), dequeue() operations without specifying storage

(array or linked list).

d) Graph Terminology

1. Undirected Graph: A graph where edges have no direction.


2. Total Degree of Vertex: Number of edges connected to a vertex.

3. Simple Path: A path without repeating vertices.

4. Cycle: A closed path where first and last vertex are same.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy