logo

Crowdly

Browser

Add to Chrome

Problem Solving with Algorithms (2024/2025)

Looking for Problem Solving with Algorithms (2024/2025) test answers and solutions? Browse our comprehensive collection of verified answers for Problem Solving with Algorithms (2024/2025) at moodle.kent.ac.uk.

Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!

 

NOTE: Do not attempt this problem until you have finished all the other problems. Even if you do not attempt this problem you can still get an 80% (high enough for a first-class degree!) This problem is meant to reward those of you who have honed your algorithm / problem-solving skills and let those of you set yourselves apart.

 

The year is 3023. You are Dr. Susan Calvin, the world's leading robo-psychologist. You are in the room with three robots. One robot is always happy. The second robot is always sad. The third robot is happy half the time you ask him, and sad the other half. The robots used to be clearly labelled with a badge that said either "always happy", "always sad" or "half and half". However, your arch-nemesis Dr. Asimov, has stolen into your lab and switched the badges around so that every robot now is guaranteed to have an incorrect badge. 

You now need to switch the badges back to their correct robot. You can do this by asking each robot "how do you feel?" Design an algorithm that minimises the total number of times you need to ask the question "how do you feel?" What is the minimum number of times you need ask the question in order to solve the problem?

View this question

Suppose that Queue is a properly built First in First Out (FIFO) data structure. Analyse the next bit of code:

  1. Queue numbers = new Queue();

  2. numbers.push(1);

  3. numbers.push(2);

  4. numbers.push(3);

  5. numbers.push(4);

  6. numbers.push(5);

  7. while (! numbers.isEmpty()) {

  8. System.out.print(numbers.pop());

  9. }

What is the output of this program at the end of line 9? Hint: Note that the program does NOT write any white spaces.

View this question

Suppose that Stack is a properly built Last In First Out (LIFO) data structure. Analyse the next bit of code:

  1. Stack numbers = new Stack();

  2. numbers.push(1);

  3. numbers.push(2);

  4. numbers.push(3);

  5. numbers.push(4);

  6. numbers.push(5);

  7. while (! numbers.isEmpty()) {

  8. System.out.print(numbers.pop());

  9. }

What is the output of this program at the end of line 9? Hint: Note that the program does NOT write any white spaces.

View this question

Read carefully the following program:

  1. import java.util.Scanner;
  2. public class root

  3. {
  4.     public static void main(String[] args)

  5.     {

  6. Scanner input = new Scanner(System.in); 

  7. double number = input.nextDouble();

  8. double a = 2;

  9. while (Math.abs(a-(number/a))>=0.25) {

  10. a = (a+(number/a))/2;

  11. }

  12. a = Math.floor(a);

  13. number = a;

  14. a = 2;

  15. while (Math.abs(a-(number/a))>=0.25) {

  16. a = (a+(number/a))/2;

  17. }

  18. a = Math.floor(a);

  19.         System.out.println((int) a);

  20.     }
  21. }

In Big O notation, what is the run-time of this algorithm as a function of the input n?

0%
0%
0%
0%
0%
View this question

Read carefully the following program:

  1. import java.util.Scanner;
  2. public class root

  3. {
  4.     public static void main(String[] args)

  5.     {

  6. Scanner input = new Scanner(System.in); 

  7. double number = input.nextDouble();

  8. double a = 2;

  9. while (Math.abs(a-(number/a))>=0.25) {

  10. a = (a+(number/a))/2;

  11. }

  12. a = Math.floor(a);

  13. number = a;

  14. a = 2;

  15. while (Math.abs(a-(number/a))>=0.25) {

  16. a = (a+(number/a))/2;

  17. }

  18. a = Math.floor(a);

  19.         System.out.println((int) a);

  20.     }
  21. }

Suppose the input of this program is the integer 81. What is the value of the variable number right after the execution of line 13? 

View this question

Read carefully the following program:

  1. import java.util.Scanner;
  2. public class root

  3. {
  4.     public static void main(String[] args)

  5.     {

  6. Scanner input = new Scanner(System.in); 

  7. double number = input.nextDouble();

  8. double a = 2;

  9. while (Math.abs(a-(number/a))>=0.25) {

  10. a = (a+(number/a))/2;

  11. }

  12. a = Math.floor(a);

  13. number = a;

  14. a = 2;

  15. while (Math.abs(a-(number/a))>=0.25) {

  16. a = (a+(number/a))/2;

  17. }

  18. a = Math.floor(a);

  19.         System.out.println((int) a);

  20.     }
  21. }

Suppose the input of this program is the integer 81. What is the output

View this question

Read carefully the following program:

  1. import java.util.Scanner;

  2. public class submission1

  3. {

  4.     public static void main(String[] args)

  5.     {

  6. Scanner input = new Scanner(System.in); 

  7. double number = input.nextDouble();

  8. double a = 2;

  9. while (Math.abs(a-(number/a))>=0.25) {

  10. a = (a+(number/a))/2;

  11. }

  12. a = Math.floor(a);

  13. if (a * a > number) a = a -1;

  14. if ((a+1) * (a+1) <= number) a = a +1;

  15.         System.out.println((int) a);

  16.     }

  17. }

In Big O notation, what is the run-time of this algorithm as a function of the input size n?

100%
0%
0%
0%
0%
View this question

Read carefully the following program:

  1. import java.util.Scanner;

  2. public class submission1

  3. {

  4.     public static void main(String[] args)

  5.     {

  6. Scanner input = new Scanner(System.in); 

  7. double number = input.nextDouble();

  8. double a = 2;

  9. while (Math.abs(a-(number/a))>=0.25) {

  10. a = (a+(number/a))/2;

  11. }

  12. a = Math.floor(a);

  13. if (a * a > number) a = a -1;

  14. if ((a+1) * (a+1) <= number) a = a +1;

  15.         System.out.println((int) a);

  16.     }

  17. }

In Big O notation, what is the run-time of this algorithm as a function of the input n?

0%
0%
0%
0%
0%
View this question

Read carefully the following program:

  1. import java.util.Scanner;

  2. public class submission1

  3. {

  4.     public static void main(String[] args)

  5.     {

  6. Scanner input = new Scanner(System.in); 

  7. double number = input.nextDouble();

  8. double a = 2;

  9. while (Math.abs(a-(number/a))>=0.25) {

  10. a = (a+(number/a))/2;

  11. }

  12. a = Math.floor(a);

  13. if (a * a > number) a = a -1;

  14. if ((a+1) * (a+1) <= number) a = a +1;

  15.         System.out.println((int) a);

  16.     }

  17. }

Suppose the input to this program is the integer 81. What is the output?

0%
0%
0%
0%
0%
View this question

Read carefully the following program:

  1. import java.util.Scanner;

  2. public class sum

  3. {

  4.   public static void main(String[] args)

  5.   {

  6.     Scanner input = new Scanner(System.in); 

  7.     int n = input.nextInt();

  8.     int sum = 0;

  9.     for (int i = 1; i <= n; i++) {

  10.       sum = sum + i;

  11.     }

  12.     System.out.println(sum);

  13.   }

  14. }

In Big O notation, what is the run-time of this algorithm as a function of the size of the input n?

0%
0%
0%
0%
0%
View this question

Want instant access to all verified answers on moodle.kent.ac.uk?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome