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

Data Structures Exam Questions and Solutions

The document contains instructions for a final exam in a data structures and algorithms course. It includes 4 questions covering topics like binary trees, queues, heaps, graphs, and binary search trees. Students are asked to draw and traverse various data structures, implement algorithms like topological sorting, and determine which data structures are suitable for given scenarios. The exam tests understanding of fundamental data structures and algorithms.

Uploaded by

Partho Protim
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)
6 views2 pages

Data Structures Exam Questions and Solutions

The document contains instructions for a final exam in a data structures and algorithms course. It includes 4 questions covering topics like binary trees, queues, heaps, graphs, and binary search trees. Students are asked to draw and traverse various data structures, implement algorithms like topological sorting, and determine which data structures are suitable for given scenarios. The exam tests understanding of fundamental data structures and algorithms.

Uploaded by

Partho Protim
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

United International University (UIU)

Dept. of Computer Science and Engineering (CSE)


Final Exam Year: 2022 Trimester: Spring
Course: CSE 2215 Data Structure and Algorithms I
Total Marks: 40, Time: 2 hours

There are FOUR questions. Answer all of them. Figures in the right-hand margin
indicate full marks.

1. a) Draw a binary tree using the data given below, where x, y, z, p, r, t, u and v are nodes of the [1]
tree.
y p z x r t u v
Here, x=last two digits of your student id+7, y=x+3, z=x+y, p=y+z, r=x+2, t=p+r, u=800, v=900

b) Traverse the binary tree of Ques. 1(a) using the inorder, postorder and level order techniques. [4]
Level each of the nodes of the tree. Also find the height of the tree using level.

c) Draw a binary tree from the following Inorder and Postorder sequences [2]
Inorder: v p y r x t z u
Postorder: v p r y t u z x
Here, x=last two digits of your student id+7, y=x+3, z=x+y, p=y+z, r=x+2, t=p+r, u=800, v=900

d)Write an algorithm for the preorder technique. Show the simulation for the tree in Ques. 1(a). [3]

2. a) Show the status of a QUEUE and a Priority QUEUE (Data in Descending Order) for the [3]
following operations, where both QUEUEs are implemented by an array of size, m=3. Here,
Enqueue and Dequeue mean insert and delete respectively, and x=last two digits of your student
id+7, y=x+3, z=x+y and p=y+z.
Enqueue(z), Enqueue(p), Dequeue(), Enqueue(y), Enqueue(z)

b) Draw a complete binary tree and then build the max-heap tree from the following [5]
data, where x= last two digits of your student id+100, y=x+30, and z=x+y. Finally, sort the data
in ascending order using the heapsort algorithm.
10 x 20 z y 8

c) Two disjoint sets {y, p, z, x} and {r, t} are given, where minimum one of a set is the [2]
representative of that set. Determine UNION(Find(x), Find(t)). How can you check x and y are
in the same set using Find operation? Here, x=last two digits of your student id+7, y=x+3,
z=x+y, p=y+z, r=x+2, t=900.

3. a) Draw a directed acyclic graph using the vertices y, p, z, x, r and u, where x=last two digits of [1]
your student id+7, y=x+3, z=x+y, p=y+z, r=x+2, u=p+r

b) Construct an Adjacency Marix and an Adjacency List for the graph in Ques. 3(a). [3]

c) Write an algorithm for Topological Sorting. Show the simulation of your algorithm using the [4]
graph in Ques. 3(a).

d) Draw a sparse and a dense graph using the vertices y, p, z, x, and r, where x=last two digits of [2]
your student id+7, y=x+3, z=x+y, p=y+z, r=x+2

4. a) Draw an undirected graph using the vertices y, p, z, x and r, where x=last two digits of your [2]
student id+7, y=x+3, z=x+y, p=y+z, r=x+2. Also find the Breadth First Search (BFS) sequence
from the graph considering x is the starting vertex.

1
b) Construct a binary search tree (BST) using the nodes y, p, z, x, r and t, where x=last two [3]
digits of your student id+7, y=x+3, z=x+y, p=y+z, r=x+2, t=900. Show the insertion and
deletion of p+r and p, respectively in/from the BST.

c) What are the merits of implementing a QUEUE in a circular fashion? How do you check the [2]
underflow and overflow in the QUEUE implemented circularly?

d) Which Data Structures are appropriate to implement the following and why? [3]

i) Different areas of Dhaka City with distances


ii) Bus Ticket Counter
iii) Arithmetic Expression Evaluation

Common questions

Powered by AI

In an inorder traversal, nodes are visited in the order of left subtree, root, right subtree. Postorder traversal visits nodes in the order: left, right, root. Level order traversal, also known as breadth-first traversal, visits nodes level by level starting from the root. The primary difference is the sequence of visiting nodes: inorder and postorder are depth-first, visiting all children before moving horizontally, whereas level order visits nodes horizontally across the tree height .

Adjacency matrices are useful for dense graphs or when quick edge existence checks are required, as they provide O(1) access time. They demand more storage space, specifically O(V^2). Adjacency lists, on the other hand, consume space proportional to the number of edges (O(V+E)), making them more efficient for sparse graphs. The trade-off involves balancing access time against memory usage, depending on the operations frequently performed, such as graph traversal or dynamic graph updates .

The Find operation locates the representative or root of the set a particular element belongs to, ensuring path compression for efficiency. The Union operation combines two sets by linking their roots, which can be done by rank or size to maintain a balanced tree. These operations are crucial for dynamically managing equivalence classes and can be used in algorithms requiring connectivity checks, like Kruskal’s algorithm for minimum spanning trees .

Dense graphs, where the number of edges is close to the maximum, are preferred in scenarios where there is a high level of interconnectedness, such as in social networks or communication systems. Sparse graphs, with fewer edges compared to maximum possible, are suitable for applications like road maps where not every point is directly connected to many others. The main structural difference is the edge-to-vertex ratio, with dense graphs having a ratio closer to 1 compared to sparse graphs .

Priority queues manage data in order of priority rather than time of arrival, allowing for urgent tasks to be processed before others in scheduling systems. This leads to more flexible handling of tasks compared to standard queues, which may delay important jobs until all previous ones are completed. The impact is significant in systems needing responsive real-time task handling, such as CPU job scheduling or print spooling, where priorities determine immediate task processing .

To perform a topological sort, first identify a node with no incoming edges, print it and remove it from the graph. Repeat the process until the graph is empty. This can be efficiently implemented using depth-first search (DFS). Topological sorting is useful in scheduling tasks where certain tasks must precede others, such as prerequisite chains in course scheduling or build order in software compilation .

To convert an array to a max-heap, you start by treating the array as a binary tree and apply the heapify process from the bottom non-leaf node up to the root to ensure each parent node is greater than its children. After establishing the max-heap structure, the heapsort algorithm involves repeatedly swapping the root (maximum element) with the last item of the heap, reducing the heap size by one, and heapifying the root, until the heap is empty. This results in a sorted array .

A circular queue efficiently utilizes space by connecting the end back to the start, allowing better memory usage over a linear queue, which may waste space when elements are dequeued from the front. Challenges include managing the circular indices, particularly checking underflow when it appears empty but isn't, and handling overflow when the queue appears full. These issues require careful handling of front and rear pointers .

BSTs have the specific property that all left subtree node values are less than the root's, and all right subtree values are greater, facilitating efficient searching and sorting. A general binary tree doesn’t enforce a specific node ordering, which can lead to inefficient operations. BSTs are ideal for applications requiring frequent searching, insertion, and deletion operations, while general binary trees can represent more arbitrary structures like heaps or syntax trees .

Tree height affects search operation time complexity as it determines the longest path from root to leaf; a taller tree increases the worst-case time complexity, which is O(height) for search operations. Balanced trees, like AVL or Red-Black trees, maintain a logarithmic height (O(log n)), ensuring efficient operations. Strategies to optimize height include balancing during insertions and deletions, or restructuring trees like converting BSTs into balanced variants when the height grows unnecessarily .

You might also like