You are on page 1of 2

Recursion

Bit manipulation
Two's complement
AND
OR
XOR
Shift operators
Masks

00001011
00001000 & 00001000 - 1<<3
00001000

if(n & (1<<i)==0)


ith bit is 0
else
ith bit is 1

Functional Programming

HOF(lambda expression)

[1,2,5,4]

reduce

List<Integer> numList=Arrays.asList(1,2,5,4);
numList.stream().reduce(x,y->x+y).orElse(0)

List<Integer> words=Arrays.asList("Functional programming","Efficient


Coding","Higher order functions");
Optional<String> longestString=words.stream().reduce((word1,word2)-
>word1.length()>=word2.length()?word1:word2)

Algorithm Design Techniques


Brute Force
Greedy approach

Optimal solution

Find optimal solutions at each and every step - locally optimal solutions

1. We might get a globally optimal solution


2. We might get a solution but not a globally optimal solution
3. We might not even get a solution

Change making

Case 1

Rs. 34 - 4 notes
20, 10, 5, 2

34
20 14
10 4
2 2
2 0

Case 2

Rs. 20 - 6 notes

15, 10, 1

20
15 5
1 4
1 3
1 2
1 1
1 0

Case 3

Rs. 20 - No solution

15, 10

20
15 5

Traveling salesman problem

25 cities

24! = 6.2*10^23

A, B, C, D

A->C->B->D

You might also like