0% found this document useful (0 votes)
19 views5 pages

Data Structure Report

The document summarizes three methods to find a missing integer in a list of consecutive numbers from 1 to n with no duplicates: 1) Calculate the expected sum and compare to the actual sum. 2) Iteratively subtract numbers from the starting value. 3) Use XOR operations on binary representations to identify the missing number. Method 1 has the highest runtime due to integer overflow risks, while Methods 2 and 3 have similar, lower runtimes as they avoid overflow.

Uploaded by

iit2021027
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)
19 views5 pages

Data Structure Report

The document summarizes three methods to find a missing integer in a list of consecutive numbers from 1 to n with no duplicates: 1) Calculate the expected sum and compare to the actual sum. 2) Iteratively subtract numbers from the starting value. 3) Use XOR operations on binary representations to identify the missing number. Method 1 has the highest runtime due to integer overflow risks, while Methods 2 and 3 have similar, lower runtimes as they avoid overflow.

Uploaded by

iit2021027
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/ 5

INDIAN INSTITUTE OF DEPARTMENT OF

INFORMATION INFORMATION
TECNOLOGY ALLAHABAD TECHNOLOGY

DATA STRUCTURE REPORT

Assigned by : dr. GROUP NO : 14


Mohammed Javed Sir PRINCE KUMAR
(IIT2021027)
ABHISHEK ANAND
(IIT2021028)
ABSTRACT A⊕B
A B
You are given a list of n-1 integers
and these integers are in the range of 1 1 0
1 to n. There are no duplicates in the
list. One of the integers is missing in 1 0 1
the list. Write an efficient code to
find the missing integer. 0 1 1
Example: Input: arr[] = {1, 2, 4, 6, 3, 7,
8}
0 0 0
XOR of a number with itself is
Output: 5 0.
Explanation: The missing number DESCRIPTION
from 1 to 8 is 5
Method 1 : This method uses the
Input: arr[] = {1, 2, 3, 5} technique of the summation formula.
Output: 4 The length of the array is n-1. So the
sum of all n elements, i.e sum of
Explanation: The missing number numbers from 1 to n can be
from 1 to 5 is 4. calculated using the formula
n*(n+1)/2. Now find the sum of all
INTRODUCTION
the elements in the array and
 An array is a collection of subtract it from the sum of first n
items stored at contiguous natural numbers, it will be the value
memory locations. idea is to of the missing element.
store multiple items of the
Since sum of all integers may be a big
same type together.
number so overflow condition may
 Sum of n natural number = n *
arise.inorder to avoid such situations
(n + 1) / 2
we deploy method 2.
 The XOR logical operation
takes two Boolean operands Method 2 : in order to avoid
and returns true iff the integer overflow, pick one number
operands are different from known numbers and subtract
otherwise Returns false. one number from given numbers.
This way there won’t have Integer
Overflow ever.
Method 3: This method uses the
technique of XOR to solve the
problem.
ALGORITHM 5. For every index update b as b = b ^
array[i]
Method 1 :
6. Print the missing number as a ^ b.
1. Calculate the sum of first n natural
numbers as sumtotal= n*(n+1)/2 PROGRAM RUNTIME
2. Create a variable sum to store the We have used the above algorithm to
sum of array elements. perform the given task about . This
program was performed with a 64 bit
3. Traverse the array from start to
computer and VS Code compiler with
end.
no programs running in background.
4. Update the value of sum as sum = Time complexity in all the three
sum + array[i] methods are O(n).since only one
traversal of the array is needed.
5. Print the missing number as
sumtotal – sum RUNTIME CALCULATION
METHOD 2: Method no Runtime in ms
1.Create a variable sum = 1 which will
store the missing number and a
1 425
counter variable c = 2. 2 324
2.Traverse the array from start to
end. 3 323
Runtime is calculated for illustration
3.Update the value of sum as su m=
mentioned in abstract.
sum – array[i] + c and update c as
c++. CONCLUSION
4. Print the missing number as a sum. Time complexity for all the three
METHOD 3: methods is O(n) but as we can see
program runtime in ms for method 1
1. Create two variables a = 0 and b = is much more than method 2 and 3 (2
0. and 3 are almost same) So method 1
2. Run a loop from 1 to n with i as not preferred over 2 and 3.
counter.
3. For every index update a as a = a ^
i.
4. Now traverse the array from start
to end.
ACKNOWLEDGEMENT
We would like to thank our professor
dr javed and teaching assistent mr
Vishal Arya for providing us this
oppurtunity to learn .

REFERENCES
1)Find the Missing Number -
TutorialsPoint.dev
2)Find the Missing Number -
GeeksforGeeks
3)Answered: You are given a list of n-
1 integers… | Bartleby

You might also like