Assignment 1 AIML A
Assignment 1 AIML A
ENGINEERING COLLEGE
Group Question
Question
No No
1 Write a program to Move all zeroes to end of array
2 Develop a C program to print the middle of the given linked list
Input: 1->2->3->4->5->6
Output: 4
3 Develop a SortList function to do the following task
Given a reference to the head of a doubly-linked list and an integer data, create a
new DoublyLinkedListNode object having data value data, and insert it at the proper
location to maintain the sort.
G1 Example: Head refers to the list 1<->2<->4->NULL
insert data=3
Return a reference to the new list: 1<->2<->3<->4->NULL
4 Write a function to insert a new node with a given value into a Binary Search Tree.
Ensure that the resulting tree remains a valid Binary Search Tree after insertion.
5 What is collision? What are the methods to resolve collision? Explain linear probing
with an example.
1 Write a program to Rearrange array such that even positioned are greater than odd
2 Develop a C program to reverse a linked list
Input: 1->2->3->4->5
Output: 5->4->3->2->1
3 Develop a CompareList function to do the following task
You’re given the pointer to the head nodes of two linked lists. Compare the data in
the nodes of the linked lists to check if they are equal. If all data attributes are equal
and the lists are the same length, return 1. Otherwise, return 0.
Example
G2
List1: 1<->2<->3->NULL
List2: 1<->2<->3<->4->NULL
The two lists have equal data attributes for the first 3 nodes. List2 is longer, though,
so the lists are not equal. Return 0
4 Implement a function to delete a node with a specific value from a Binary Search
Tree. Make sure to handle different cases such as nodes with zero, one, or two
children.
5 Explain open addressing and chaining used to handle overflows in hashing
1 Given an array of size N containing only 0s, 1s, and 2s; Write a program to sort the
array in ascending order
2 Develop a C program to find Nth node from end of the list
Input: 1->2->3->4->5 N=3
Output: 3
3 Develop a detect_cycle function to do the following task
A linked list is said to contain a cycle if any node is visited more than once while
traversing the list. Given a pointer to the head of a linked list, determine if it contains
a cycle. If it does, return 1. Otherwise, return 0.
Example
If Head refers to the list of nodes 1->2->3->NULL
G4
The numbers shown are the node numbers, not their data values. There is no cycle in
this list so return 0 .
If Head refers to the list of nodes 1->2->3->1->NULL
There is a cycle where node 3 points back to node 1, so return 1.
4 Implement a function to find the in-order successor of a given node in a Binary
Search Tree. If the given node has a right subtree, find the leftmost node in that
subtree; otherwise, find the first ancestor whose left child is also an ancestor of the
given node.
5 Implement a basic hash table class in a programming language of your choice Include
methods for insertion, deletion.
G6 If you are asked to insert a new node with a value of 25 between Node 2 and Node 3,
what steps would you take to perform this insertion in the doubly linked list?
Please provide the sequence of steps or operations required to insert the new node
with a value of 25 between Node 2 and Node 3 in the given doubly linked list
4 Implement a function to determine whether a given binary tree is a Binary Search
Tree or not.
5 Discuss optimization strategies for dynamic hashing to improve efficiency
5 Include methods for insertion, extraction of the highest priority element, and any
additional operations specific to a single-ended priority queue.
1 Write a program to compute Maximum profit by buying and selling a share at most
twice
2 Develop a C program to merge a linked list into another linked list at alternate positions
Input: 5->7->17->13->11
12->10->2->4->6
Output: 5->12->7->10->17->2->13->4->11->6
3 Node 1: Product = "Apples", Quantity = 2, Price = $1.50, Previous = NULL, Next = Node 2
Node 2: Product = "Bananas", Quantity = 3, Price = $2.00, Previous = Node 1, Next = Node
3
Node 3: Product = "Oranges", Quantity = 1, Price = $1.20, Previous = Node 2, Next = Node
G10 4
Node 4: Product = "Grapes", Quantity = 2, Price = $3.50, Previous = Node 3, Next = NULL
Now, perform the following operations on this doubly linked list representing the
shopping cart:Add a new product, "Milk", Quantity = 1, Price = $2.50, after the
"Bananas" node.Update the quantity of "Oranges" to 2.
4 Define what a selection tree is and explain its role in programming. Provide an
example code snippet that utilizes a selection tree to make a decision based on user
input.
5 Provide examples of scenarios where a double-ended priority queue is particularly
useful.
1 Write a program to find Smallest subarray with sum greater than a given value
5 Discuss the advantages of having both minimum and maximum priority elements in a
double-ended priority queue.
2 Develop a C program to delete an element from a circular linked list using head pointer
Input: 1->2->3->4->5->head
Data = 2
Output: 1->3->4->5->head
Given pointers to the heads of two sorted linked lists, merge them into a single,
sorted linked list. Either head pointer may be null meaning that the corresponding list
G12 is empty.
Example
headA refers to 1<->3<->7->NULL
headB refers to 1<->2->NULL
The new list is 1<->1<->2<->3<->7->NULL
4 Create a program that uses boolean conditions within a selection tree to determine
whether a given year is a leap year. Include appropriate conditions for divisibility by
4, 100, and 400.
5 Explain the basic operations supported by a double-ended priority queue.
5 Compare and contrast the features of a double-ended priority queue with a single-
ended one.
1 Given two strings string1 and string2, remove those characters from the first
string(string1) which are present in the second string(string2). Both strings are
different and contain only lowercase characters.
5 Define what a double-ended priority queue is and how it extends the concept of a
standard priority queue.
G15
G16
4 Create a program that checks the eligibility of a person to vote. Ask for the user's age
as input and use a selection tree to determine if they are eligible to vote or not.
ii. For the given data, draw a Binary search tree and show the linked representation of
the same: 30, 65, 85, 35, 40, 210, 90, 5
4 If G is forest with n vertices and k connected components, how many edges does G
have?
4 Design a program that presents a menu to the user and uses a selection tree to execute
the corresponding option selected by the user (e.g., options for a simple text-based
game, calculator, or file manipulation).
5 Define what a single-ended priority queue is and how it differs from a standard
priority queue.
5 Write functions for inserting an element and extracting the minimum (or maximum)
element in a binary heap-based priority queue
5 List and explain the fundamental operations that can be performed on a priority
queue
1 Convert the following infix expressions to postfix expressions : (( a / ( b – c + d)) * (e
– f ) * g)
5 Describe the binary heap data structure and how it is used to implement a priority
queue.
1 Give the following declaration. int a=8; int b=9; int *p=&a; int *q=&b; What is the
value of each of the following expression? ++a, ++(*p), --(*q), --b
5 Discuss scenarios where using a priority queue is more suitable than a regular queue.
2 Develop a C program to convert singly linked list into circular linked list
Input: 10->20->22->44->80->Null
Output: 10->20->22->44->80
3 Develop iterative function to print the inorder traversal of a binary tree without
G23 recursion
4 Implement a system that allows adding and removing edges dynamically in a binary
tree, and update the disjoint sets accordingly.
5 Explain the main differences between a regular queue and a priority queue
2 Develop a C program to remove all occurrence of one linked list in another linked list
Input: list1: 1->2->7->8->6->2->7 List2: 2->7
Output: 1->8->6
G26 3 Write a Program to Check whether a binary tree is a full binary tree or not.
4 The number of binary trees with 'n' nodes is known as the nth Catalan number. Write
a function that calculates the nth Catalan number using recursion.
5 Define what a priority queue is and explain its primary use in computer science.
1 For the given sparse matrix and its transpose (fast transpose), give the triplet
representation using one dimensional array
G27
2 Develop a C program to remove duplicates from an unsorted linked list
Input: 2->5->2->7->3->1->7->10->4
Output: 2->5->7->3->1->10->4
3 Write a Program to Check whether a binary tree is a complete binary tree or not
4 Write a function to find the number of binary trees with 'n' nodes where each node
has either 0 or 2 children (full binary trees).
1 Write a failure array step by step for pattern matching of string using KMP algorithm.
Pattern: a b c d a b c
Students Groups:
4CB23AI001 – 4CB23AI002 => G1
4CB23AI003 – 4CB23AI004 => G2
4CB23AI005 – 4CB23AI006 => G3
4CB23AI007 – 4CB23AI008 => G4
: : :
4CB23AI061– 4CB23AI062 => G30
4CB23AI063- 4CB23AI064 => G31
Instructions to Students:
1. Assignments should be submitted in handwritten format only.
2. Do not copy the assignments of other candidates. If copying is noticed, the assignments of
candidates who have copied as well as who have written originally both will be rejected.
3. The completed assignment should be submitted to the course instructor on or before 02/12/2022.
4. Marks distribution is tabulated in the above table, the same criteria will be adapted for evaluation
5. Students are expected to take the screenshot of the output and paste it in assignment book.
Signature of Course Instructor with Date Signature of Course Coordinator with Date
Coverage of modules is adequate.
APPROVED
Signature of Senior Faculty/Expert with Date Signature of Senior Faculty/Expert with Date