Question

Design an algorithm which finds the difference A - B of two sets of integer numbers, A-{a!, a2, , an] , B = {bi, b2, ,bn} (the difference A-B is a collection of such elements of A which are not elements of B). Consider two cases, when the sets A and B are ordered and when they are not ordered.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

*****PLEASE GIVE A LIKE TO THIS ANSWER*****Algethn find dievence betuten Set A & 8 (A-0 If set A and sct 8 are ordernd goto i else Sort SetA and set 8 et aFirst Element of A First Element f 8. Result ui be in C ) while a〈b : Insert a into C anda:Next Ebrut 2 hile ayb: b Next Etme of 8 3) if arb: ar Next E lement of A 4f 6to end: Insert rest of A into s) If a goes to end: stop rn nsest a of A b bt Next Element of 8 C and stop

Add a comment
Know the answer?
Add Answer to:
Design an algorithm which finds the difference A - B of two sets of integer numbers,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Design an algorithm to find all the non-common elements in two sorted lists of numbers....

    1. Design an algorithm to find all the non-common elements in two sorted lists of numbers. What is the maximum number of comparisons your algorithm makes if the lengths of the two given lists are m and n, ?respectively 2. Estimate how many times faster it will be to find ged(98765, 56789) by Euclid's algorithm compared with the algorithm based on checking consecutive integers from min{m, n} down to gcd(m, n). 3. For each of the following functions, indicate how...

  • 8. Consider the following algorithm, which finds the sum of all of the integers in a...

    8. Consider the following algorithm, which finds the sum of all of the integers in a list procedure sum(n: positive integer, a1, a2,..., an : integers) for i: 1 to n return S (a) Suppose the value for n is 4 and the elements of the list are 3, 5,-2,4. List assigned to s as the procedure is executed. (You can list the the values that are values assigned to all variables if you wish) b) When a list of...

  • (a) Design an algorithm that reveals some secret integer number from the set {1, 2, ......

    (a) Design an algorithm that reveals some secret integer number from the set {1, 2, ... , n} by guessing random numbers within the given range until the secret number has been guessed. Numbers should be replaced after being guessed such that ​it is possible to guess 2 and then 2 again​, assuming 2 is in the given range. The algorithm should return both the secret number as well as the number of guesses taken. (b) If possible, calculate the...

  • 3. (10 pts) Design an algorithm how to multiply two complex numbers abi and c + di using only three multiplications of real numbers. Your algorithm should take a, b, c and d as input and produce the...

    3. (10 pts) Design an algorithm how to multiply two complex numbers abi and c + di using only three multiplications of real numbers. Your algorithm should take a, b, c and d as input and produce the real component a*c-b*d and the imaginary component a*d + b*c separately MULTIPLY-COMPLEX-NUMBER(a, b, c, d) 3. (10 pts) Design an algorithm how to multiply two complex numbers abi and c + di using only three multiplications of real numbers. Your algorithm should...

  • 1. Let A = {a1, ..., an} and B = {b1, ..., bm} be two sets...

    1. Let A = {a1, ..., an} and B = {b1, ..., bm} be two sets of numbers. Consider the problem of finding their intersection, i.e., the set C of all the numbers that are in both A and B. a. Design a presorting based algorithm for solving this problem and determine its efficiency class. 2. Estimate how many searches will be needed to justify time spent on presorting an array of 103 elements if sorting is done by mergesort...

  • B) Consider two time series as two sets on numbers: e.g. S1 = {3, 5, 7,...

    B) Consider two time series as two sets on numbers: e.g. S1 = {3, 5, 7, 8 , .., 4, 7} and S2 = {5, 5, 8 , .., 9, 7}. You need to come up with 2 sets, each having 100 elements. You can make them random if you like. 1) Normalize each set in range [0,1]. 2) Find the probabilities of S2 in the ranges [0,0.1], (0.1,0.2], (0.2,0.3], .., (0.9,1] when S1 are in the same ranges [0,0.1],...

  • 1. For each of the two sets of numbers below, determine whether it is a field....

    1. For each of the two sets of numbers below, determine whether it is a field. If it is a field, just write it is a field. If it is not a field, write It is not a field, state which of the field properties does not hold, and give an example showing this. (a) F = { a+bV2: a,b € Z} That is, F is the set of all numbers of the form a + b2, where a and...

  • 5. Design a Turing machine that takes as input two numbers a and b, such that...

    5. Design a Turing machine that takes as input two numbers a and b, such that a is not equal to b and determines which number is higher. Give the transition table for the machine. Show by drawing the steps, how the machine works when a-3 and b-2. Can we use a PDA for the same problem? Give reasons for your answer (10+5+5-20).

  • Plz i want answer these question using list in python programme. You are given two sequences...

    Plz i want answer these question using list in python programme. You are given two sequences of n integers: 21, 22, ...,an and b1,b2, ..., bn Print a sequence of 2n integers created by alternating elements from the given sequences: a1, 61, 42, 62, a3, 63, ..., an, bn. Input The first line contains a positive integer n (1 <n<1000) - the length of the sequences The second line contains n space-separated integers 01, 02, ..., an (-1000 <a; <...

  • 1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer...

    1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer >(); ArrayList b = a; a.add(new Integer(4)); b.add(new Integer(5)); a.add(new Integer(6)); a.add(new Integer(7)); System.out.println(b.size()); A)1 B)2 C)3 D)4 E)5 2. Assume the Student and Employee classes each extend the Person class. The Student class overrides the getMoney method in the Person class. Consider the following code:     Person p1, p2, p3;     int m1, m2, m3;     p1 = new Person();     m1 = p1.getMoney();     // assignment 1...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT