Question
a)You are given a sequence S of n integers each within range [0..n]. Give the pseudocode for an O(n) algorithm that checks if S contains
a)You are given a sequence S of n integers each within range [0..n]. Give the pseudocode for an O(n) algorithm that checks if S contains equal elements, and returns a sequence of those elements that appear in S at least twice.
b) [3 pts] Explain why your algorithm runs in O(n) time.
c) [3 pts] Also explain the space requirement of your algorithm (other than the input sequence S), and remember that the time required cannot be less than the space required. d) [16 pts]
d)Now answer the same questions as above, but there is no restriction that all elements are within range [0..n]. You are allowed to run in expected O(n) time. Write down any assumptions you make.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started