Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Bartleby Related Questions Icon
Related questions
bartleby
Concept explainers
Question
Transcribed Image Text:Write a program in JAVA Programming langaugue.
Given an array of integers, in which each elements repeats twice except one.
Your task is to find that element in O(n) Time complexity and O(1) Space Complexity.
Expert Solution
Check Markarrow_forward
Step 1
Required :
Java program that finds in an array, the only number which doesn't repeats itself.
Constraints : Time complexity : O(n), Space Complexity : O(1)
The idea is to use XOR operator. It has the following properties :
XOR of a number with itself is 0
XOR of a number with 0 is the number itself.
For example,
5 ^ 5 = 0
5 ^ 0 = 5
Where ^ is the XOR operator.
So consider the following array is given :
{4, 8, 3, 6, 3, 8, 9, 6, 4}
Here, 9 is the only non repeating element.
So we do XOR for all the elements :
4 ^ 8 ^ 3 ^ 6 ^ 3 ^ 8 ^ 9 ^ 6 ^ 4
Rearranging, we get :
4 ^ 4 ^ 8 ^ 8 ^ 3 ^ 3 ^ 6 ^ 6 ^ 9
Using above properties, we have
0 ^ 0 ^ 0 ^ 0 ^ 9
= 9
This the required element.
Below is the Java program as required.
bartleby
Step by stepSolved in 4 steps with 2 images
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- solve in C please. Implement the following two functions that get a string, and compute an array of non-emptytokens of the string containing only lower-case letters. For example:●くろまる For a string "abc EFaG hi", the list of tokens with only lower-case letters is ["abc", "hi"].●くろまる For a string "ab 12 ef hi ", the list of such tokens is ["ab","ef","hi"].●くろまる For a string "abc 12EFG hi ", the list of such tokens is ["abc","hi"].●くろまる For a string " abc ", the list of such tokens is ["abc"].●くろまる For a string "+*abc!! B" the list of such tokens is empty.That is, we break the string using the spaces as delimiters (ascii value 32), and look only at thetokens with lower-case letters only .1. The function count_tokens gets a string str, and returns the number ofsuch tokens.int count_tokens(const char* str);For example●くろまる count_tokens("abc EFaG hi") needs to return 2.●くろまる count_tokens("ab 12 ef hi") needs to return 3.●くろまる count_tokens("ab12ef+") needs to return 0.2. The function get_tokens gets a string str, and...arrow_forwardGiven an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. please do in pythonarrow_forwardin java ecplise . Implement a program that randomly generates 10 integers from -100 to 100,stores them in a 1D array, and finds their maximum value. Calculate theexecution time of finding a maximum. Repeat the test for 10,000 and10,000,000 numbers. Provide your results in the form of a table below andprovide a small summary. Implement a Java program that will populate a 5x5 matrix with randomlygenerated integers from 0 to 100.(1) print your matrix in a table form.(2) modify your code to multiply all even numbers by 10 and print the matrix.Your output of questions (1) and (2) should match the format of the followingsample outputs:arrow_forward
- Write and test a Java method mostFrequent() that returns the most frequent element in anarray of n integers.arrow_forwardWrite the javascript and the C++ code for this language. Right answer will be given thumbs up.arrow_forwardWrite a java program to print the number from 1 to 100 without using loop, recursion, bitset.Think about arrays and do this with array in O(1) time complexityarrow_forward
- You are given an integer n and an array of unique integers blacklist. Design an algorithm to pick a random integer in the range [0, n − 1] that is not in blacklist. Any integer that is in the mentioned range and not in blacklist should be equally likely to be returned. Optimize your algorithm such that it minimizes the number of calls to the built-in random function of your language.arrow_forwardFor the non-recursive towers problem, we used an array of vectors to represent the towers: vector T[3]. To move the top of tower from to the top of tower to. we would write: T[to],push_front(T[from].back()) T[to].push_back(T[from].pop_back()) T[to).push_back(T[from].back()) T[tol.push_front(T[from].pop_back()) O None of the abovearrow_forwardImplement a function in Java to find the largest and smallest elements in an array of integers, and return them in a pair. The function should have a time complexity of O(n) and a space complexity of O(1).arrow_forward
- LeetCode Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words. If there is more than one possible answer, return the longest word with the smallest lexicographical order. If there is no answer, return the empty string. Example 1: Input: words = ["w","wo","wor","worl","wo Output: "world" Explanation: The word "world" can be buil Example 2: Input: words = ["a", "banana", "app","appl" Output: "apple" Explanation: Both "apply" and "apple" can Constraints: • 1 <= words.length <= 1000 • 1 <= words [i]. length <= 30 words [1] consists of lowercase English letters.arrow_forwardGiven an array of integers and a positive integer k, find the maximum sum of any contiguous subarray of size k. For example, given the array [1, 2, 3, 4, 5] and k = 2, the maximum sum is 7, which is the sum of the subarray [4, 5] Please solve in C# language ..arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education