From ee65eea156f5c93fb0b6c3d6d8f1fea6429abed4 Mon Sep 17 00:00:00 2001 From: Boyan Date: Sat, 5 Nov 2022 01:05:12 +0100 Subject: [PATCH] Added 4, bare with me, i am sleepy --- 1_Data_Storage.md | 2 +- 4_Algorithms.md | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 4_Algorithms.md diff --git a/1_Data_Storage.md b/1_Data_Storage.md index 835e296..631fa1c 100644 --- a/1_Data_Storage.md +++ b/1_Data_Storage.md @@ -33,7 +33,7 @@ B49F 011000 - D 101101 - F -### What is the smallest negative integer that can be represented in a two's complement system in which each value is represented by eight bits? + # What is the smallest negative integer that can be represented in a two's complement system in which each value is represented by eight bits? 10000000, -128 (either is correct) ### Which of the following data storage systems provides the most efficient random access to individual data items? diff --git a/4_Algorithms.md b/4_Algorithms.md new file mode 100644 index 0000000..27b183f --- /dev/null +++ b/4_Algorithms.md @@ -0,0 +1,81 @@ +### In general, an algorithm in which of the following categories is considered more efficient? +Θ(log n) + +### Suppose the statement "X is an integer and X < 5" is a loop invariant at the point at which the test for termination is performed in the loop outlined below. +``` +repeat ( . . . ) +until (X > 3) +``` +### At the end of this loop, X equals? +4 + +### What sequence of numbers would be printed if the following procedure were executed with the value of N being 0? +``` +procedure xxx (N) + + print the value of N; + + if (N < 2) then + + (apply the procedure xxx to the value N + 1) + + else + + (print the value of N) + +print the value of N +``` +0,1,2,2,2,1,0 + +### What sequence of numbers would be printed if the procedure named xxx as described below were executed with the value of N being 2? + +``` +procedure xxx(N) + print the value of N; + if (N<3) + then (apply procedure yyy to the value 4) +procedure yyy(N) + print the value of N; + apply the procedure xxx to the value 5 + print the value of N +``` +2,4,5,5,4,2 + +### Which of the following is not a way of representing algorithms? +Stepwise refinement + +### Q6 is a table again +![Table](https://media.discordapp.net/attachments/458628210272239626/1038241407078506536/image.png?width=638&height=335) + +### Preconditions, postconditions, and loop invariants are examples of which of the following? +Assertions + +### The binary search algorithm is an example of an algorithm in which of the following classes? +Θ(log n) + +### Under the assumption that N takes on only integer values, which of the following is the termination condition in the following recursive procedure? + +``` +procedure xxx (N) + + if (N < 5) then + + (apply the procedure xxx to the value N + 1) + + else + + (print the value of N) +``` +N > 4 + +### When searching within the list ` Lewis, Maurice, Nathan, Oliver, Pat, Quincy, Roger, Stan, Tom` which of the following entries will be found most quickly using the binary search algorithm? +Pat + +### Which of the following set of instructions defines an algorithm in the formal, strict sense? +``` +X ← 3; + +while (X < 5)do + + (X ← X + 1) +``` \ No newline at end of file