0% found this document useful (0 votes)
47 views12 pages

Assignment 1 AIML A

Uploaded by

abhinandanhl60
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)
47 views12 pages

Assignment 1 AIML A

Uploaded by

abhinandanhl60
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/ 12

DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING, CANARA

ENGINEERING COLLEGE

Programme: B.E. CIE: ASSIGNMENT – 1 Semester: III

Course Title: DATA STRUCTURES & APPLICATIONS Course Code: BCS304

Date: 25/09/2024 Submission: 02-12-2024 Section: - A

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

G3 1 Write a program to Rearrange an array in maximum minimum form using Two


Pointer Technique

2 Develop a C program to rotate a linked list


Input: 10->20->30->40->50->60 , k=4
Output: 50->60->10->20->30->40
3 Develop a C Program Search element in Doubly Linked list(Display NO if no such
element present in list, YES if it found).
4 Write a function to perform an inorder traversal on a Binary Search Tree and return
the elements in sorted order. Ensure that the function has a time complexity of O(n)
where 'n' is the number of nodes in the tree.
5 Explain the importance of constructing optimal binary search trees in terms of search
efficiency

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.

1 Write a program to Reorder an array according to given indexes


2 Develop a C program to delete last occurrence of an item from linked list
Input: 1->2->3->4->5->NULL
Output: 1->2->3->4->NULL
3 Given two numbers represented by two lists, write a function that returns the sum in
the form of a linked list.
Example:
G5
Input: List1: 5->6->3 // represents number 563
List2: 8->4->2 // represents number 842
Output:
Resultant list: 1->4->0->5 // represents number 1405
Explanation: 563 + 842 = 1405
4 Write a function to calculate the height of a Binary Search Tree. The height of an
empty tree is considered 0, and the height of a tree with a single node is 1.
5 Include methods for insertion, extraction of both the minimum and maximum priority
elements, and any additional operations specific to a double-ended priority queue.

1 Write a program to Search an element in a sorted and rotated array


2 Develop a C program to delete last occurrence of key from linked, given a linked list and a
key to be deleted
Input: 10->20->30->40->20->60->30 , key=20
Output: 10->20->30->40->60->30
3 Suppose you have a doubly linked list with the following nodes:
10<->20<->30<->40->NULL

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

1 Write a program to Find the Rotation Count in Rotated Sorted array

2 Develop a C program to delete middle element of the linked list


Input: 1->2->3->4->5
Output: 1->2->4->5
3 Given two numbers represented by linked lists, write a function that returns the
multiplication of these two linked lists.
Examples:
G7
Input : 9->4->6 and 8->4
Output : 79464
4 Write a function to find the Lowest Common Ancestor of two nodes in a Binary
Search Tree.

5 Implement a double-ended priority queue class in a programming language of your


choice.

1 Write a program to compute K-th Largest Sum Contiguous Subarray

2 Develop a C program to remove duplicate element from sorted linked list


Input: 11->11->11->25->34->34->45->50
Output: 11->25->34->45->50
3 Given a singly linked list containing n nodes. Modify the value of first half nodes
such that 1st node’s new value is equal to the first node’s current value minus last
G8
node’s value, 2nd node’s new value is equal to the 2nd node’s current value minus
second last node’s value, likewise for first half nodes. If n is odd then the value of the
middle node remains unchanged. (No extra memory to be used).
Input : 10 -> 4 -> 5 -> 3 -> 6
Output : 4 -> 1 -> 5 -> 3 -> 6
4 Implement a function to convert a Binary Search Tree to a sorted doubly linked list.

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 Find the smallest missing number

2 Develop a C program to delete N nodes after M nodes in a linked list


Input: M=3, N=2
1->2->3->4->5->6->7->8->9->10
Output: 1->2->3->6->7->8
G9 3 Develop a C Program to find the size of a Doubly Linked List
4 Write a function to check if a given Binary Search Tree is balanced, i.e., the height of
the left and right subtrees of any node differ by at most 1.

5 Implement a single-ended priority queue class in a programming language of your


choice.

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

2 Develop a C program to traverse circular linked list.


Input: 1->2->3->4->5
Output: 1->2->3->4->5
3 Finding Middle Element of a Doubly Linked List: Create a function to find the
G11 middle element/node of a doubly linked list.
4 Write a program that uses nested selection trees to determine a student's letter grade
based on their numerical score. Consider the typical grading scale (A: 90-100, B: 80-
89, C: 70-79, D: 60-69, F: 0-59).

5 Discuss the advantages of having both minimum and maximum priority elements in a
double-ended priority queue.

1 Write a program to Reverse a String using Stack

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

3 Develop a CompareList function to do the following task

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.

1 Write a program to Reverse an array using Stack

2 Develop a C program to delete an element without using head pointer


Input: 1->2->3->4->5
Data = 3
Output: 1->2->4->5
3 Finding Nth Node from the End in a Doubly Linked List: Write an algorithm to find
G13 the Nth node from the end of a doubly linked list
4 Implement a program that uses a switch-case selection tree to determine the day of
the week based on a numerical input (1 for Monday, 2 for Tuesday, etc.). Ensure the
program handles invalid inputs gracefully.

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.

2 Develop a C program to implement queue linked list


Input: 44 -> 33 -> 22 -> 11
Output: Front element is 44
G14 Rear element is 11
3 i) The postorder traversal of a binary tree is 8,9,6,7,4,5,2,3,1. The inorder
traversal of the same tree is 8,6,9,4,7,2,5,1,3. The height of a tree is the
length of the longest path from the root to any leaf. The height of the
binary tree above is ______.
Consider a binary tree T that has 200 leaf nodes. Then, the number of nodes in T that
have exactly two children are ________.
4 Develop a simple calculator program that takes two numbers and an operator as input
from the user and uses a selection tree to perform the corresponding operation
(addition, subtraction, multiplication, division).

5 Define what a double-ended priority queue is and how it extends the concept of a
standard priority queue.

1 Write a program to Check for balanced parentheses in an expression


2 Develop a C program to Implement stack using singly linked list
Input: 44 -> 33 -> 22 -> 11
Output: Top element is 44
Input: 22 -> 11
Output: Top element is 22
3 For the given sparse matrix, write the diagrammatic linked list representation

G15

4 Write a program to find strongly connected components in a directed graph using


Kosaraju’s algorithm
5 List and explain the basic operations that can be performed on a single-ended priority
queue.

1 Write a program to Reverse a four digit number using stack


2 Develop a C program to remove every kth node of the linked list
Input: 11->22->33->44->55->66->77->88->99 k=3
Output: 11->22->44->55->77->88
3 For the given sparse matrix, write the diagrammatic linked list representation

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.

5 Include a code snippet or pseudocode to illustrate a basic implementation.

1 Write a program to Delete Middle letter from string


2 Develop a C program to pairwise swap of a linked list
Input: 11->22->33->44->55->66->Null
G17 Output: 22->11->44->33->66->55->Null
3 i. If the trees Tree-1 and Tree-2 are the ones listed below:
Which traversals of Tree-1 and Tree-2 will yield the same sequence, respectively?
Explain the answer in detail
a) Postorder, inorder
b) Postorder, preorder
c) Inorder, preorder
d) Preorder, postorder
e) None of the above

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?

5 Provide examples of situations where a single-ended priority queue would be more


appropriate than a standard priority queue.

1 Write a program to Reverse individual words


2 Develop a C program to count number of times a given integer appears in a linked list.
Input: 1->2->1->3->1->1->4 N=3
Search for =1
Output: 4 (1 appears four times)
3 Choose the correct option and explain the answer in detail.
I) FBGADCE was the outcome of traversing a tree in sequence. The tree's pre-order
traversal would then result in
a) ABFGCDE
G18
b) BFGCDEA
c) FGBDECA
d) AFGBDEC
II). dbeafcg and abdecfg are the inorder and pre-order Traversals of a binary Tree,
respectively. The postorder traversal is
a) debfagc
b) dbefcga
c) debfgca
d) dbefacg

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.

1 Convert the following infix expressions to postfix expressions : (a+(b-c)*(d-e)%f)


2 Develop a C program to sort the given linked list of 0’s 1’s and 2’s
Input: 1->2->2->0->0->1->1->2->Null
Output: 0->0->1->1->1->2->2->2->Null
3 For the given data, draw a Binary search tree and show the array and linked representation
of the same: 100, 85, 45, 55, 110, 20, 70, 65
G19 4 Develop a program that compares two strings entered by the user and uses a selection
tree to determine if they are equal, or if one is lexicographically greater than the
other.

5 Write functions for inserting an element and extracting the minimum (or maximum)
element in a binary heap-based priority queue

1 Convert the following infix expressions to postfix expressions : (a+b) * d – e / (f + a


* d) +c
2 Develop a C program to delete an element from beginning of a linked list
Input: 1->2->3->4->5->6->Null
Output: 2->3->4->5->6->Null
3 Let LASTPOST, LASTIN, LASTPRE denote the last vertex visited in a postorder,
inorder and preorder traversal respectively of a complete binary tree. Which of the
following is always true? Explain the answer with example.

G20 A. LASTIN = LASTPOST


B. LASTIN = LASTPRE
C. LASTPRE = LASTPOST
None of these
4 The preorder traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19. Give
the postorder traversal of the tree?

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)

2 Develop a C program to find the sum of the given linked list


Input: 1->3->5->8->2->4->Null
Output: 23
G21
3 Develop iterative function to print the Preorder traversal of a binary tree without
recursion
4 Implement a function to initialize a disjoint set for each node in a binary tree.

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

2 Develop a C program to find the difference of given linked list


Input: 9->6->2->Null
Output: 2
G22 3 Develop iterative function to print the Postorder traversal of a binary tree without
recursion
4 Write a function to perform the union operation on two disjoint sets represented by
nodes in a binary tree.

5 Discuss scenarios where using a priority queue is more suitable than a regular queue.

1 Convert the following infix expressions to postfix expressions : a+(b+c)+(b/d)*a+z*u

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

1 Write a function to swap the contents of 2 variables using pointer


2 Develop a C program to reverse a linked list in groups of given size
Input: 1->2->3->4->5->6->7->8->Null k=3
Output: 3->2->1->6->5->4->8->7->Null
3 a. Compare and contrast the performance of linked list representation with other
methods (like arrays) when dealing with sparse matrices.
G24 b. Under what scenarios would the linked list representation be more efficient, and
when would it be less efficient?
4 Write a function to calculate the total number of binary trees that can be formed with
'n' nodes. The function should take an integer 'n' as input and return the count of
binary trees.

5 Compare and contrast Leftist Trees with Skew Heaps.


1 Convert the following infix expressions to postfix expressions : A-B/C(C*D$E)

2 Develop a C program to merge two sorted linked list


Input: List1: 6->8->10 List2: 2->7->9
Output: 2->6->7->8->9->10
3 Write an efficient algorithm to check if two binary trees are identical or not. Two
binary trees are identical if they have identical structure and their contents are also
G25 the same.
4 Given an integer 'n', write a Python function to determine the number of unique
binary search trees that can be constructed with 'n' nodes. You can assume that the
values of the nodes are unique.

5 Provide examples of real-world scenarios where a priority queue can be applied


1 Evaluate the following Postfix Expressions: a / b – c + d * e – a * c, Where
a=6,b=3,c=1,d=2,e=4.

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).

5 Discuss techniques for avoiding collisions in hash functions.

1 Write a failure array step by step for pattern matching of string using KMP algorithm.
Pattern: a b c d a b c

2 Develop a C program to merge K sorted linked list


Input: K=3, N=4
List1=1->3->5->7->Null
List2=2->4->6-8->Null
List3=0->9->10->11->Null

G28 Output: 0->1->2->3->4->5>6->7>8->9->10->11


3 Develop a C Program display elements (Display NULL if no element is present, If
elements presents display elements with space separated) in Doubly Linked List
4 Write a program to implement an adjacency matrix and adjacency list representation
of a graph.

5 What is rehashing, and when is it necessary in the context of hash tables?

1 Consider the following sequence of operations on an empty stack.push(54);


push(52); pop(); push(55); push(62); s = pop();
G29
2 Develop a C program to add two numbers represented by linked list
Input: List1:2->4->8 List2:3->5->2
Output:6->0->0 (248+352=600)
3 Write a Program to Check whether a binary tree is a balanced binary tree or not.
4 Write a function to convert an adjacency matrix to an adjacency list.

5 Describe how a hash table works and its advantages


1 Evaluate the following Postfix Expressions: 623+-382/+*2$3+

2 Develop a C program to construct a linked list from 2d matrix


Input: 1 2 3
456
Output: 1->2->3->Null
4->5->6-Null
G30 3 Given a binary tree which has T nodes, Develop a c function to find the diameter of
that binary tree. The diameter of a tree is the number of nodes on the longest path
between two leaves in the tree.
4 Prove that every binary tree is uniquely defined by its preorder and inorder
sequences.
5 Compare and contrast open addressing and chaining as collision resolution
techniques.
1 Evaluate postfix expression and Trace the same on 562+*841-

2 Develop a C program to reverse a sub list of linked list


Input: 10->20->30->40->50->60->70->80 m=3, n=6
G31 Output: 10->20->60->50->40->30->70->80
3 Develop a C Program to reverse a Doubly Linked List.
4 Prove that Prims algorithm finds a minimum cost spanning tree for every undirected
connected graph
5 Define a hash collision and explain why it is undesirable.

Students Groups:
4CB23AI001 – 4CB23AI002 => G1
4CB23AI003 – 4CB23AI004 => G2
4CB23AI005 – 4CB23AI006 => G3
4CB23AI007 – 4CB23AI008 => G4

: : :
4CB23AI061– 4CB23AI062 => G30
4CB23AI063- 4CB23AI064 => G31

Rubrics for Assessment:


SI.No. Criteria for Evaluation Marks
1 Coding functionality and its correctness 4
2 Readability, documentation and following standard coding practices 2
3 Results 3
4 Innovative/Creative/Optimal solutions 2
5 Timely submission 2
TOTAL 13

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

HEAD OF THE DEPARTMENT/CHAIRMAN – MODERATION COMMITTEE

You might also like