0% found this document useful (0 votes)
10 views15 pages

Assignment #1

The document outlines an assignment with multiple questions related to algorithms and data structures, including tasks such as detecting loops in linked lists, designing a special stack, and merging binary search trees. Each question requires pseudocode, a dry run of the algorithm, and efficient solutions with specified time complexities. The assignment emphasizes the importance of submitting work on time and originality in data generation for dry runs.

Uploaded by

gniharika622
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views15 pages

Assignment #1

The document outlines an assignment with multiple questions related to algorithms and data structures, including tasks such as detecting loops in linked lists, designing a special stack, and merging binary search trees. Each question requires pseudocode, a dry run of the algorithm, and efficient solutions with specified time complexities. The assignment emphasizes the importance of submitting work on time and originality in data generation for dry runs.

Uploaded by

gniharika622
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Assignment #1

1. To be submitted on portal before the timeline


2. Provide a pseudocode for the algorithm asked
3. Perform a dry run, on the data generated “at random” (by yourself, if not
given in the question), and show its implementation. (handwritten form,
using pen and paper).
 Copy cases can be tracked, if they generating the same data, and
perform dry run on it (as how like minded two person are, but they cannot generate the
same sequence of random data).

BITS Pilani, Pilani Campus


Question1
Write an efficient algorithm that checks whether a given singly linked list
contains a loop. A loop is a sequence of nodes v1, v2, . . . , vk such that v1->
v2-> . . . -> vk -> v1.

2
BITS Pilani, Pilani Campus
Question2
Design a data structure SpecialStack that supports all the stack operations like
push(), pop(), isEmpty(), top() and an additional operation getMin() which
should return minimum element from the SpecialStack. All these operations of
SpecialStack must be O(1). To design SpecialStack, you should only use
standard Stack data structure and no other data structure like arrays, list, etc.

3
BITS Pilani, Pilani Campus
Question3
Describe a O(nlog(n))-time algorithm that, given a set S of n integers in sorted
order and another integer x, determines whether or not there exist two
elements in S whose sum is exactly x.

4
BITS Pilani, Pilani Campus
Question4
Given an unsorted array A of size n that may contain duplicates and a number k
< n, design an O(n) algorithm that returns true if array contains duplicates
within a distance of k, ie. Ǝ i, j Ɛ [0, n − 1] such that A[i] = A[j] and |i − j| < k.

5
BITS Pilani, Pilani Campus
Question5
You are given two binary search trees (not necessarily balanced). Design an
algorithm that merges the two given trees into a balanced binary search tree
in linear time.

6
BITS Pilani, Pilani Campus
Question6
Consider a stack with an additional operation, MULTIPOP(S, k) which removes
the k top objects of stack S, popping the entire stack if the stack contains
fewer than k objects. The cost of the operation MULTIPOP(S, k) is k, while
that of PUSH(S, x) and POP(S) is 1. Now consider a sequence of n stack
operations on an initially empty stack, where each operation is either PUSH,
POP or MULTIPOP. Prove that the total cost of these n operations is θ(n)

7
BITS Pilani, Pilani Campus
Question7
Provide an efficient algorithm for finding the kth Object of a Binary Tree

8
BITS Pilani, Pilani Campus
Question8
Provide an efficient algorithm for finding the successor & predecessor of the Binary
tree

9
BITS Pilani, Pilani Campus
Question9
One question of Hashing using quadratic Probing, list of elements & hash
functions are to be generated randomly.

10
BITS Pilani, Pilani Campus
Question10
Give an O(n)-time algorithm for Collapse problem (“in ONE loop”, & InPlace )
INPUT
A B C D E F G

OUTPUT

A B C D E F G

11
BITS Pilani, Pilani Campus
Question11
Give an O(n)-time algorithm for Collapse problem (“in ONE loop”, & InPlace )
INPUT
A B C D E F G

OUTPUT

A B C D E F G

12
BITS Pilani, Pilani Campus
Question12
 Give an O(n)-time algorithm for computing the depths of all the nodes of a
tree T, where n is the number of nodes of T.

BITS Pilani, Pilani Campus


Question13
 Give an efficient algorithm for Searching an arbitrary element (may or may
not be a member of the heap) into a Heap (Max or Min, based on your
assumption).

BITS Pilani, Pilani Campus


Question14
 Give an efficient algorithm that check the AVL condition, at the time of
calculating the height of each node in a BST, and perform a dry run.

BITS Pilani, Pilani Campus

You might also like