0% found this document useful (0 votes)
6 views

Programming

Uploaded by

Ahmad Houry
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 views

Programming

Uploaded by

Ahmad Houry
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/ 1

Lebanese University – Faculty of Engineering – Branch I

Course: Programming IV Ahmad HOURY


Data Structures Date: July 1, 2024

1. (a) TransferNodesToBST(SinglyLinkedList, DoublyLinkedList, CircularLinkedList): Transfers all nodes


from the singly linked list, doubly linked list, and circular linked list to the binary search tree.
(b) PrintAllStructures(): Prints all the data structures before and after the transfer.
2. SplitList(): Splits the circular linked list into two equal halves. If the list has an odd number of nodes, the extra
node should go to the first list.
3. ReverseDoublyList(): Reverses the doubly linked list.
4. ReverseCircularList(): Reverses the Circular linked list.
5. FindMiddle(): Finds and returns the middle node of the doubly linked list.
6. RemoveDuplicates(): Removes all duplicate values from the doubly linked list.
7. MergeTwoLists(SinglyLinkedList list1, SinglyLinkedList list2): Merges two sorted linked lists into one sorted
list.
8. RotateRight(int k): Rotates the list to the right by k places.
9. ReverseList(): Reverses the linked list.
10. JosephusProblem(int k): Solves the Josephus problem with step count k and returns the position of the last re-
maining node. write in the method in iterative and recursive ways.
The Josephus problem is a theoretical problem related to a certain elimination game. The problem is described as
follows:
There are n people standing in a circle waiting to be executed. The counting out begins at a specified point in the
circle and proceeds around the circle in a fixed direction. In each step, a certain number of people k are skipped and
the next person is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as
people are removed), until only the last person remains, who is given freedom. The task is to determine the position
of that person.
11. LowestCommonAncestor(int value1, int value2): Finds the lowest common ancestor of two given nodes.
Lowest Common Ancestor (LCA): The lowest (i.e., deepest) node in the tree that is a common ancestor of two
given nodes. In other words, the LCA of two nodes is the lowest node in the tree that has both nodes as descendants
(a node can be a descendant of itself).
12. Implement a data structure that supports the following operations:
(a) Given a binary tree, convert it to a circular doubly linked list. The order of the nodes in the circular doubly
linked list must follow the in-order traversal of the binary tree. Convert the binary tree to a circular doubly
linked list.
(b) Detect and remove a cycle in a singly linked list.
(c) Convert the BST to a doubly linked list in sorted order.
(d) Find the maximum path sum between any two nodes in a BST.
(e) Given a binary search tree (BST) and a doubly linked list, merge them into a balanced binary search tree
(BBST). Implement the following operations:
i. Convert the doubly linked list to a sorted array.
ii. Merge the sorted array and the BST into a balanced binary search tree.
iii. Perform in-order, pre-order, and post-order traversals on the BBST to verify the order.
(f) Given a binary tree, write a function to check whether it is balanced. Additionally, ensure that the tree satisfies
the following constraints:
• The sum of the node values in the left subtree is equal to the sum of the node values in the right subtree.
• No two leaf nodes have the same depth.
(g) Implement Morris traversal (in-order traversal without recursion and stack).
(h) Given two sorted Binary Trees (containing integers), write a C# function that merges them into a single sorted
Binary Search Tree.
END

You might also like