Posts

Showing posts from June, 2023

Prove that (f+g)(x) is an odd function, if f and g are odd functions (Stewart, Calculus)

Suppose f(x) and g(x) are odd functions. Prove that (f+g)(x) is also an odd function.  Answer:  1. Strategy By definition, f is an odd function if and only if f(-x) = - f(x) To show (f+g) is an odd function, we need to show (f+g)(-x) = - (f+g)(x) 2. Explanation Since $f(x)$ and $g(x)$ are odd functions $\Rightarrow f(-x) =-f(x)$ and $g(-x) =-g(x)$ By definition of sum of functions. $(f+g)(-x) =f(-x)+g(-x)$ $=-f(x)-g(x)$ $=-(f(x)+g(x))$ $=-(f+g)(x)$ (by definition of sum of functions) $\Rightarrow(f+g)(-x) =-(f+g)(x)$ $\Rightarrow f+g$ is an odd function. Q.E.D. 

[Java] Excercise: compare two given arrays and determine their equality

Motivation: In Java, c heck if Two Arrays are Equal or not Equal. a={1,2,3,4,5,6} b={2,3,1,4,5,4,4} Time complexity: $O(n^2)$ (because of the bubble sort algorithm) - Version 1: 1 process. double-nested loop statement. - Version 2: 2 processes. 1) bubble sort algorithm: $O(n^2)$, 2) single-nested loop statement O(n) - Version 3: 1 process. 1) Arrays . equals ( a , b ): $O(n^2)$ (still $n^2$) - Version 4: 2 processes. 1) check lengths of arrays, 2) sort arrays, 3) compare elements of arrays. Still $O(n^2)$ because of sorting arrays. Java codes import java.util.Arrays ; public static void main ( String [] args ) { int a [] = { 1 , 2 , 3 , 4 , 5 , 6 }; int b [] = { 2 , 3 , 1 , 4 , 5 , 4 , 4 }; boolean result = true ; // version 1 // determine whether two arrays are equal, by comparing elements one-by-one: version 1 // this is theta(n^2) algorithm for ( int i = 0 ; i < a . length ; i ++) { for ( int j = 0 ; j < b . len