Introduction to Data Structures and Algorithms, Summaries of Mathematical Physics

An introduction to fundamental concepts in data structures and algorithms, including a review of relevant mathematical topics such as exponents, logarithms, and series. It covers key programming techniques like recursion and the use of generic objects in java. Important data structure concepts like arrays, collections, and comparators. Overall, this material lays the groundwork for a comprehensive study of data structures and algorithms, which are essential for computer science and software engineering students. The depth and breadth of the topics covered make this document a valuable resource for university-level coursework and self-study.

Typology: Summaries

2022/2023

Uploaded on 07/29/2023

sandeep-mishra-1
sandeep-mishra-1 🇺🇸

2 documents

1 / 45

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
© 2022 by Greg Ozbirn, UT-Dallas, for use with Data
Structures book by Mark Allen Weiss
1
Chapter 1
Introduction
Fall 2022
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d

Partial preview of the text

Download Introduction to Data Structures and Algorithms and more Summaries Mathematical Physics in PDF only on Docsity!

© 2022 by Greg Ozbirn, UT-Dallas, for use with Data Structures book by Mark Allen Weiss 1

Chapter 1

Introduction

Fall 2022

Objectives

This chapter reviews some pre-requisite

material we will need.

  • (^) It is assumed you have already learned

much of this material in previous courses.

Exponents

Rule

  • (^) XAXB^ = XA+B
  • (^) XA^ / XB^ = XA-B
  • (^) (XA)B =^ XAB

X

N

+ X

N

= 2X

N

  • 2 N^ + 2N^ = 2N+

Example

  • (^22) * 2^3 = 22+3^ = 2^5
  • (^25) / 2^3 = 25 – 3^ = 2^2
  • (^) (2^2 )^3 = 2^6

2

2

2

  • (^22) + 2^2 = 2^3

Logarithms

  • (^) X A

= B if and only if log

X

B = A

3 = 8 so log 2

  • (^) log A

B = log

C

B / log

C

A; A,B,C > 0, A ≠ 1

log 2 16 = log 10 16 / log 10

Logarithms

  • (^) log X

A

B

= B log

X

A

log 10

4 = 4 log 10

  • (^) log 2

X < X for all X > 0

Logarithms

Normally ln is base e, and log is base 10.

  • (^) In our textbook, log is always base 2. log 1 = 0 log 2 = 1 log 1024 = 10 log 1048576 = 20 log 1073741824 = 30
  • (^) If 0<A<1: N ∑ A i ≤ 1 / (1-A) i=
  • (^) As N →∞, the sum approaches 1/(1-A).
  • (^) Proof: S = 1 + A + A 2 + A 3 + A 4 + A 5 + … Multiply through by A: AS = A + A 2
  • A 3
  • A 4
  • A 5
  • … Subtract AS from S (permitted if convergent): S – AS = 1 So S = 1/(1-A)

Series

Arithmetic series - the difference between

successive terms is constant.

N ∑ i = N(N+1)/2 ≈ N 2 / i=

To find the sum of 2 + 5 + 8 + … + 3k-

  • (^) Write as: 3(1+2+3+…+k) – (1+1+1+…+1)

= 3(k(k+1)/2) – k

Proof by Contradiction

  • (^) Assume theorem is false, then show how this assumption leads to a conclusion that something which is known to be true is false, hence the original false assumption cannot be true, proving the theorem is true.
  • (^) For example, prove that the sum of two even numbers is always even.
  • (^) Assume it is false: given even x and y, then x+y is odd.
  • (^) If x+y is odd, then x+y = 2c+1.
  • (^) But x=2a and y=2b means 2a+2b = 2c+
  • (^) So 2(a+b) = 2c + 1, but this says an even number equals an odd number, which is impossible.
  • (^) Therefore, the sum of two even numbers is even.

Induction

Steps:

1. Basis step : Prove for the minimal case. 2. Inductive step: a. Inductive hypothesis: Assume the theorem holds for all cases up to some limit k. b. Prove the next case: for example, k+

  1. Conclusion : by induction, the theorem holds for all cases, i.e., the minimal case and all its successors.

Prove: for Fibonacci numbers, F i

i , i>= Basis step: F 1

1 , F 2

2 Inductive step: assume true for i=1, 2, …, k Show F k+

k+ F k+

= F

k +

F

k- F k+

k

  • (5/3) k- < (3/5)(5/3) k+
  • (3/5) 2 (5/3) k+ < (3/5 + (3/5) 2 ) (5/3) k+ < (24/25) (5/3) k+ < (5/3) k+ Conclusion: by induction, it is proved

Recursion

  • (^) A function defined in terms of itself is

recursive.

  • (^) Many math problems can be expressed this

way.

  • (^) For example: xn^ = x * xn-

x! = x * (x-1)!

  • (^) We can see that these examples are

naturally recursive.

Recursion

public static int power(int x, int n) { if (n = = 0) return 1; else return x * power(x, n-1); } power(5,3) = 5*power(5,2) = 5 * (5 * power(5,1)) = 5 * (5 * (5 * power(5,0))) = 5 * (5 * (5 * 1)) = 5 * (5 * 5) = 5 * 25 = 125

Recursion

Consider this recursive function: public static void print(int n) { if (n >= 10) print( n / 10); printDigit( n % 10); } print(6371); print(637) print(63) print(6) printDigit(6%10); printDigit(63%10); printDigit(637%10); printDigit(6371%10);