Lect 13 - 2024
Lect 13 - 2024
aft
Foundations of
Data Structures and Algorithms
Lect 13
Sameera Muhamed Salam
Dept of CSIS, BITS Pilani, Hyderabad Campus
Dr
QUEUE
Tree
1. Given a sorted doubly linked list and a target value, determine if there are two
distinct nodes in the doubly linked list whose values add up to the target value. It
is guaranteed that the values of the nodes in the doubly linked list are unique (i.e.,
no two distinct nodes have the same value). Note that positive as well as negative
integers and zero can be present as the elements of the linked list. Your solution
must use only constant extra space. The expected time complexity of your
solution should be O(n), where n is the number of nodes in the doubly linked list.
2. Pearl ′ 24 is here and lots of students from all over the country are visiting your
college. Suppose you have been tasked with choosing the colors for each college.
Unfortunately, there is no list of colleges participating in the fest, only a list of
students participating in the fest. To make your task easier, your friends have
assigned an integer to every student such that no two students belonging to
different colleges have the same integer and no two students belonging to the
same college have different integers. They have then sorted this sequence of
integers and provided it to you as an array. Given this array, write a program to
count the number of different colleges participating in the fest so that you can
assign colors to them. The time complexity of your solution should be
O(k ∗ log (n)), where k is the number of different colleges and n is the size of the
array, respectively.
Figure: [Ref:Log2Base2]
▶ Empty Queue:
▶ Front=Rear = NULL
▶ Enqueue
▶ If Queue is empty
▶ Front = Rear = Newnode
▶ Otherwise
▶ Rear→ next = Newnode
▶ Rear=Newnode
▶ Dequeue
▶ If queue is not empty
▶ Front=Front→ next
▶ Video streaming
▶ Process scheduling
▶ Ticket booking system
▶ Printer Spooler
Figure: [Ref:GeeksforGeeks]
▶ There are input restricted Queues and output restricted queues also.
▶ Applications?
▶ Array
▶ Array
▶ Linked list
Tree
A Tree T is a set of nodes storing elements in a parent-child relationship with the
following properties:
▶ T has a special node r, called the root of T.
▶ Each node y of T different from r bas a parent node u.
▶ In most operating systems, files are organized hierarchically into nested directories
(also called folders), which are presented to the user in the form of a tree.
▶ A tree is ordered if there is a linear ordering defined for the chi1dren of each node;
that is, we can identify children of a node as being the first, second, (third, and so
on.
▶ Ordered trees typically indicate the linear order relationship existing between
siblings by listing them in a sequence or iterator in the correct order.
▶ A structured document, such as a book, is hierarchically organized as a tree whose
internal nodes are chapters, sections, and subsections, and whose external nodes
are paragraphs, tables, figures, the bibliography, and so on.