0% found this document useful (0 votes)
252 views3 pages

DSA Practice Test 2024 2025 Test02

DSA_Practice_Test_2024_2025_Test02 (2)

Uploaded by

Minh Hung
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)
252 views3 pages

DSA Practice Test 2024 2025 Test02

DSA_Practice_Test_2024_2025_Test02 (2)

Uploaded by

Minh Hung
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/ 3

UNIVERSITY OF INFORMATION TECHNOLOGY PRACTICE TEST

FACULTY OF INFORMATION SYSTEMS TERM I, ACADEMIC YEAR 2024-2025

Course Title: Data Structures and Algorithms


Duration: 90 minutes (References are not allowed)
Test’s Code: 02

Question 1:

Write a program to insert nodes into a single linked list. Each node's value is a character.
Insertion stops when the program encounters a node with a "0" value (this node is not inserted
into the list).
Do the following requirements:
- Given two lists, a and b, the number of elements of b is less than that of a. Check if list a
contains b and find all containing positions.
- Suppose that a contains b; delete all the appearances of b in a.
Input:
- Elements of a separated by a new line.
- Elements of b separated by a new line.
Output:
- Print out "Empty List" if any of the two lists is empty.
- Print out the inserted lists.
- Print out the start and end indexes of found containing positions, separated by a new line.
- If a does not contain b, print out "not found" .
- Print out the list a after deleting all the appearances of b in a.
Examples:
Input Output
s a: s a u v u v k
a b: u v
u 23
v 45
u sak
v
k
0
u
v
0

Question 2:

Implement a Stack and its operators using a Single Linked List. Each element is an integer.
Do the following requirements:
- Push a sequence of integers into the stack. Insertion stops when encountering the "0"
element.
- Use only stack or queue operators to sort the odd numbers of the stack in ascending
order and keep the relative positions of the other numbers unchanged.
Input:
- Sequence of integers separated by a new line.
Output:
- Print out elements of the stack separated by a space.
- Print the result stack after sorting the stack.

Input Output
12 1 6 5 9 8 10 3 12
3 1 6 3 5 8 10 9 12
10
8
9
5
6
1
0

Question 3:

Implement a Binary Search Tree with distinct keys and do the following requirements:
- Find the lowest node (lowest level) satisfied that the sum of keys in its left subtree is
equal to the sum of keys in its right subtree.
Input:
- The list of integer keys of the tree separated by a new line. Insertion stops when
encountering the "0" node.
Output:
- Print out the tree in left-node-right order.
- Print out the key of the satisfied node.
- If there is no satisfied node in the tree, print out “Not found!”.
- If the tree is empty, print out "Empty tree".
Examples
Input Output
12 6 7 8 9 10 11 12 15 20 23
9 9
8
6
7
11
10
20
15
23
0
Question 4:

Given an array satisfied that the left part of the array is in decreasing order, and the right part is
in increasing order. Elements that lie in the middle of these two parts are called trough elements.
In other words, these numbers are smaller or equal to their neighbors. Find the number of trough
elements of the array using Binary search.
Input:
- The number of elements of the array.
- Elements of the given array, separated by space.
Output:
- Print out elements of the array in space separation.
- Print out the number of trough elements.
Examples
Input Output
10 13 8 5 2 2 2 9 11 13 15
13 8 5 2 2 2 9 11 13 15 3

Question 5:
Given a directed graph and two nodes, S and T of the graph, find all paths from A to B.
Input:
- The first line contains the number of nodes (V) and edges (E) separated by a space.
- The second line is the list of node labels separated by a space.
- Each subsequent line contains a pair (i, j). Each pair represents an arc from node i to node
j.
- The last line contains the two nodes, S and T.
Output:
- Print all paths found from S to T in the given format, separated by a new line.
format: "i -> j -> k ->...".
- If no paths are found from S to T, print "not found".

Examples:
Input Output
56 A -> C -> E
ABCDE A -> D -> C -> E
AB A -> D -> E
AC
DE
DC
AD
CE
EB
AE

You might also like