ACTIVITY 3: i +
def sum(n):
a = 0
for i in range(n):
for j in range(n, i, -1):
a = a + j;
return a
1. How many times did the operation execute?
Answer: n * n times
2. What is the final time complexity of the given algorithm?
Answer: O(n2)
3. What is the final space complexity of the given algorithm?
Answer: O(1
Defines the Array class that represents an array of integers. Please fulfill the following requirements
constructor, destructor, copy constructor
The function allows inputting data from the keyboard and the function displays to the screen for Array (2 functions)
The function allows to assign (write) and the function to get (read) the value of a certain element in the Array (2 functions)
Write a main program that illustrates how to use it
ACTIVITY 2:
# A is the array and n is the array size
def sum(A,n):
total =0
for i in range(n):
total = total + A [ i ]
return total
1. How many times did the operation execute?
Answer: n times
2. What is the final time complexity of the given algorithm?
Answer: O(n)
3. What is the final space complexity of the given algorithm?
Answer: O(n)
ACTIVITY 1:
def sum(a, b):
return a+b
1. How many times did the operation execute?
Answer: 1
2. What is the final time complexity of the given algorithm?
Answer: O(1)
3. What is the final space complexity of the given algorithm?
Answer: O(1)
C++ Programs to print integers Pattern
C++ Programs to print Integers Pattern
LOOPS ( READ QUESTION AND SOLVE IT AS REQUIRED)
If diff is 0, then guess is correct and the program outputs a message indicating that the user guessed the correct number.
1. If diff is greater than or equal to 50, the program outputs the message indicating that the guess is very high (if guess is greater than num) or very low (if guess is less than num).
2. If diff is greater than or equal to 30 and less than 50, the program outputs the message indicating that the guess is high (if guess is greater than num) or low (if guess is less than num).
3. If diff is greater than or equal to 15 and less than 30, the program outputs the message indicating that the guess is moderately high (if guess is greater than num) or moderately low (if guess is less than num).
4. If diff is greater than 0 and less than 15, the program outputs the message indicating that the guess is somewhat high (if guess is greater than num) or somewhat low (if guess is less than num).
Give the user no more than five tries to guess the number.
x1 = -b + sqrt(b2-4ac) / 2a
x2 = -b - sqrt(b2-4ac) / 2a
These functions are useful only if the discriminant is non-negative. Let these functions
return 0 if the discriminant is negative.
Write a test program that prompts the user to enter values for a, b, and c, and displays the result based on the discriminant. If the discriminant is positive, display the two roots. If the discriminant is 0, display the one root. Otherwise, display "The equation has no real roots".
Write a program to perform deletion operation on BST. While deleting, consider all the deletion cases. a. Deletion of node with degree 0. b. Deletion of node with degree 1. c. Deletion of node with degree 2.
Note: No global declarations
Call the functions in main through menu
Implement the following :
Singly Linked List with following functions :
1)insert_at_head(node* & head, int val);
2)insert_at_tail(node* & head, int val);
3)display(node* head) ;
4)insert_at_pos(node* & head, int val,int pos);
5)delete_at_head(node* & head);
6)delete_at_tail(node* & head);
7)delete_at_pos(node* & head, int pos);