Question

1.             (5 marks) Perform a selection sort on the list 23, 59, 34, 13, 31, 10. Show...

1.             (5 marks) Perform a selection sort on the list 23, 59, 34, 13, 31, 10. Show the list after each exchange that has an effect on the list ordering.

2.             (5 marks) Explain why the bubble sort algorithm does Ө(n2) comparisons on an n-element list. The bubble-sort algorithm is shown just after question 10 on p. 141.

3.              (5 marks) Write the resulting data list, give the ending value of legit, and find the exact number of copies done by the converging pointers algorithm when executed on this set of data:

72

0

0

35

41

0

13

27

44

0

4.              (5 marks) If the pattern-matching problem was changed to only find the first instance of a pattern of length m in the text of length n.

(a)    Describe the data that would cause the worst-case performance and the performance in terms of n. Use "Big-O" notation, e.g. Θ(n), Θ(n2), etc.

(b)   Describe the data that would cause the best-case performance and the performance in terms of n. Use "Big-O" notation, e.g. Θ(n), Θ(n2), etc.

5.             (5 marks) Do Exercise 38 from Chapter 3 on page 147.

6.             (5 marks) Calculate the decimal value of the following numbers. Show your work.

(a) The base 5 number 342

(b) The base 6 number 415

(c) The base 16 hexadecimal number 7EAh (the h indicates hex)

7.             (5 marks) Give the decimal value of the following numbers). Show your work.

(a) The 2s complement number 01010101

(b) The 2s complement number 10101101

(c) The 2s complement number 01111111

(d) The 2s complement number 10000111

(e) The a sign/magnitude number 10001101

8.              (5 marks) Using the ASCII code given in Figure 4.3 on p. 164 (162 in 6th edition) give the binary representation for the phrase "Hi Paul!", ignoring the quotation marks. Make sure to space each 8-bit ASCII code apart from the next so they are easy to read, e.g.

01000001 01100010 01000011

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

Answer 1.


23 59 34 13 31 10

Find minimum element in [23 59 34 13 31 10] and swap it with the element at beginning of [23 59 34 13 31 10]
10 59 34 13 31 23

Find minimum element in [59 34 13 31 23] and swap it with the element at beginning of [59 34 13 31 23]
10 13 34 59 31 23

Find minimum element in [34 59 31 23] and swap it with the element at beginning of [34 59 31 23]
10 13 23 59 31 34

Find minimum element in [59 31 34] and swap it with the element at beginning of [59 31 34]
10 13 23 34 31 59

Find minimum element in [31 59] and swap it with the element at beginning of [31 59]
10 13 23 34 31 59

Find minimum element in [59] and swap it with the element at beginning of [59]
10 13 23 34 31 59

LIST IS SORTED

AS PER CHEGG'S POLICY ONLY FIRST QUESTION WILL BE ANSWERED

Add a comment
Know the answer?
Add Answer to:
1.             (5 marks) Perform a selection sort on the list 23, 59, 34, 13, 31, 10. Show...
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
  • Data Structure and Algorithm (a) Given the following integer list: 10 23 12 34 a[0] a[1]...

    Data Structure and Algorithm (a) Given the following integer list: 10 23 12 34 a[0] a[1] a[2] a[3] a[4] Show a trace (step by step) for each execution of Bubble Sort based on the following algorithm. //passes llone pass l/one comparison for (pass = 1 ; pass<= n ; pass++) for (i = 0); i<=n-2; i++) if (a[i] > a[i+1]) { hold = a[i]; a[i] = a[i+1]; a[i+1] = hold; } l/one swap (6 marks)

  • 1. [5 marks Show the following hold using the definition of Big Oh: a) 2 mark...

    1. [5 marks Show the following hold using the definition of Big Oh: a) 2 mark 1729 is O(1) b) 3 marks 2n2-4n -3 is O(n2) 2. [3 marks] Using the definition of Big-Oh, prove that 2n2(n 1) is not O(n2) 3. 6 marks Let f(n),g(n), h(n) be complexity functions. Using the definition of Big-Oh, prove the following two claims a) 3 marks Let k be a positive real constant and f(n) is O(g(n)), then k f(n) is O(g(n)) b)...

  • [Code in C] Help me with this. Not sure what to do. 1 Couting Sort You...

    [Code in C] Help me with this. Not sure what to do. 1 Couting Sort You may have learned some sorting algorithms - such as bubble sort ad quicksort in CS 110 and CS 210. This homework is about counting sort. Let n be the number of elements to be sorted. Bubble sort and quicksort assume tha time, which one is larger and which one is smaller. They make no assumption on the values of the elements t we can...

  • 1. (10 points) Write an efficient iterative (i.e., loop-based) function Fibonnaci(n) that returns the nth Fibonnaci...

    1. (10 points) Write an efficient iterative (i.e., loop-based) function Fibonnaci(n) that returns the nth Fibonnaci number. By definition Fibonnaci(0) is 1, Fibonnaci(1) is 1, Fibonnaci(2) is 2, Fibonnaci(3) is 3, Fibonnaci(4) is 5, and so on. Your function may only use a constant amount of memory (i.e. no auxiliary array). Argue that the running time of the function is Θ(n), i.e. the function is linear in n. 2. (10 points) Order the following functions by growth rate: N, \N,...

  • Practical 5: Write a program that implements several sorting algorithms, and use it to demonstrate the comparative perfo...

    Practical 5: Write a program that implements several sorting algorithms, and use it to demonstrate the comparative performance of the algorithms for a variety of data sets. Need Help With this Sorting Algorithm task for C++ Base Code for sorting.cpp is given. The header file is not included in this. Help would be much appreciated as I have not started on this due to personal reasons #include <cstdlib> #include <iostream> #include <getopt.h> using namespace std; long compares; // for counting...

  • Can you please help with the below? 1)   Which of the following is true about using...

    Can you please help with the below? 1)   Which of the following is true about using a 2-3-4 tree? a.   It is designed to minimize node visits while keeping to an O(log n) search performance b.   It is designed to self-balance as new values are inserted into the tree c.   As soon as a node becomes full, it performs the split routine d.   None of the above 2)   Which of the following is true about a binary search tree? a.  ...

  • ld ts biovs Part II: Analysis of recursive algorithms is somewhat different from that of non-recursive...

    ld ts biovs Part II: Analysis of recursive algorithms is somewhat different from that of non-recursive algorithms. We are very much interested in how many times the method gets called. The text refers to this as the number of activations. In inefficient algorithms, the number of calls to a method grows rapidly, in fact much worse than algorithms such as bubble sort. Consider the following: public static void foo ( int n ) { if n <=1 ow ura wor...

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
ADVERTISEMENT