0% found this document useful (0 votes)
4 views5 pages

Assignment

This is the assignment question and answers in Islamic view

Uploaded by

cryptosavant7
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)
4 views5 pages

Assignment

This is the assignment question and answers in Islamic view

Uploaded by

cryptosavant7
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/ 5

Name: Nasiru Ahmed Mohammed

ID: ST10209298
Course Data Structures and Algorithms (CMP 202)
Assignment Question: 1

Introduction

Information structures and calculations are the spine of computer science, empowering proficient
information organization, preparing, and recovery. Two of the foremost crucial structures in this space
are charts and connected records, each serving unmistakable purposes in understanding computational
issues. Charts speak to interconnected information, permitting for the modeling of real-world
frameworks like social systems, street maps, and reliance structures. Navigating these charts effectively
is basic, which is where calculations like breadth-first look (BFS) and depth-first look (DFS) come into
play. BFS investigates graphs layer by layer employing a queue, while DFS digs profound into each
department employing a stack, exhibiting distinctive approaches to revealing information connections.

On the other hand, connected records are straight information structures that give adaptability in
energetic memory assignment and productive inclusion or erasure of hubs. The doubly connected list,
in specific, stands out with its bidirectional traversal capability, making it perfect for different
applications like fix usefulness in program and overseeing playlists in mixed media frameworks.
Understanding how to control these structures through operations like hub erasure is fundamental for
optimizing execution in real-world applications.

This exposition digs into two key zones:

the traversal of an non-cyclic chart utilizing BFS and DFS, and the usage of erasure calculations for a
doubly connected list. By outlining these concepts with cases, the paper highlights the practical
importance of these methods in computational problem-solving.

Part A: Acyclic Graph and Traversal Techniques

i. Graph Representation

Below is an acyclic graph with six vertices (A, B, C, D, E, F):


A
/\
B C
/\ \
D E F

This directed acyclic graph (DAG) can be represented using an adjacency list:

 A → B, C
 B → D, E
 C→F
 D, E, F → ∅ (no outgoing edges)

This structure ensures no cycles exist, a property crucial for many graph algorithms.

ii. Breadth-First Search (BFS)

BFS Overview: BFS could be a level-order traversal procedure that visits all vertices at the same level
some time recently moving to the following. It employments a line to keep track of hubs to be handled.

BFS Algorithm:

1. Initialize a line and enqueue the beginning vertex.


2. Stamp the beginning vertex as gone to.
3. While the queue is not empty:
 Dequeue a vertex, process it, and enqueue its unvisited neighbors.
4. Rehash until all reachable vertices are gone to.

Example Using the Graph: Start at vertex A:

1. Enqueue A → Queue: [A]


2. Dequeue A, visit, enqueue B and C → Queue: [B, C]
3. Dequeue B, visit, enqueue D and E → Queue: [C, D, E]
4. Dequeue C, visit, enqueue F → Queue: [D, E, F]
5. Dequeue and process D, E, F.

Final Order of Traversal: A → B → C → D → E → F

Queue in BFS: The line guarantees hubs are prepared in level-order, keeping up the breadth-first
nature of the calculation.
iii. Depth-First Search (DFS)

DFS Overview: DFS investigates as faraway as conceivable along each department some time recently
backtracking. It employments a stack (unequivocal or recursion-based) to keep track of ways.

DFS Algorithm:

1. Initialize a stack and push the starting vertex.


2. Mark the starting vertex as visited.
3. While the stack is not empty:
 Pop the top vertex, process it, and push its unvisited neighbors onto the stack.
4. Repeat until all vertices are visited.

Example Using the Graph: Start at vertex A:

1. Push A → Stack: [A]


2. Pop A, visit, push C and B → Stack: [C, B]
3. Pop B, visit, push E and D → Stack: [C, E, D]
4. Pop and process D → Stack: [C, E]
5. Pop and process E → Stack: [C]
6. Pop C, visit, push F → Stack: [F]
7. Pop and process F.

Final Order of Traversal: A → B → D → E → C → F

Stack in DFS: The stack enables backtracking, ensuring the depth-first nature of traversal.

Part B: Doubly Linked Lists

i. Node Deletion Algorithms

A doubly connected list comprises of hubs, each containing information, a pointer to the following hub
(following), and a pointer to the past hub (prev). The taking after are calculations for erasing hubs:

1. Delete from the Beginning:

 If the list is empty, return.


 Update the head to point to the second node.
 If the new head exists, set its prev pointer to NULL.

delete_beginning(head):
if head == NULL:
return
head = head.next
if head != NULL:
head.prev = NULL

2. Delete from the Middle:

 Traverse to the target node.


 Update the next pointer of the previous node to skip the target.
 Update the prev pointer of the next node to skip the target.

delete_middle(head, target):
if target == NULL or head == NULL:
return
target.prev.next = target.next
if target.next != NULL:
target.next.prev = target.prev

3. Delete from the End:

 If the list is empty or has one node, handle accordingly.


 Traverse to the last node.
 Update the next pointer of the second-to-last node to NULL.

delete_end(head):
if head == NULL:
return
if head.next == NULL:
head = NULL
return
temp = head
while temp.next != NULL:
temp = temp.next
temp.prev.next = NULL

ii. Explanation with Diagrams

Example List: Initial list: A <-> B <-> C <-> D

1. Delete from the Beginning:


 Remove A:

Before: NULL <- A <-> B <-> C <-> D


After: NULL <- B <-> C <-> D

2. Delete from the Middle:

 Remove C:

Before: B <-> C <-> D


After: B <-> D

3. Delete from the End:

 Remove D:

Before: B <-> D
After: B

These operations protect the structure of the list by suitably overhauling pointers.

Conclusion

Graphs and connected records are flexible structures with differing applications. BFS and DFS
effectively navigate non-cyclic charts utilizing lines and stacks, individually, to investigate hubs in
numerous orders. In the interim, overseeing hubs in doubly linked lists depends on exact pointer
control to preserve list keenness. Authority of these methods upgrades problem-solving capabilities in
computer science, demonstrating their significance in algorithmic plan.

Reference

 Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms
(3rd ed.). MIT Press.

 Goodrich, M. T., Tamassia, R., & Goldwasser, M. H. (2014). Data Structures and Algorithms in
Java (6th ed.). Wiley.

 Weiss, M. A. (2013). Data Structures and Algorithm Analysis in C++ (4th ed.). Pearson.

 Sedgewick, R., & Wayne, K. (2011). Algorithms (4th ed.). Addison-Wesley Professional.

 Forouzan, B. A. (2007). Data Structures: A Pseudocode Approach with C (2nd ed.). Cengage
Learning.

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