Total Pageviews

962,945

Monday, July 24, 2023

merge sort



Analysis of merge sort





The divide-and-conquer approach

 The divide-and-conquer approach

The divide-and-conquer paradigm involves three steps at each level of the recursion:

Divide the problem into a number of subproblems that are smaller instances of the

same problem.

Conquer the subproblems by solving them recursively. If the subproblem sizes are

small enough, however, just solve the subproblems in a straightforward manner.

Combine the solutions to the subproblems into the solution for the original problem.

EXAMPLE

The merge sort algorithm closely follows the divide-and-conquer paradigm. Intuitively, it operates as follows.

Divide: Divide the n-element sequence to be sorted into two subsequences of n=2

elements each.

Conquer: Sort the two subsequences recursively using merge sort.

Combine: Merge the two sorted subsequences to produce the sorted answer.

Sunday, July 23, 2023

ISCE- LIST OF PROGRAMS

1 Magic number CLICK
2 Happy number CLICK
3 Fibonacci series CLICK
4 Check twin prime from a series CLICK
5 Armstrong number CLICK
6 Automorphic number CLICK
7 decimal to binary conversion CLICK
8 a+a/2! +a/3! +a/4! +.... n th term
9 neon number in java CLICK
10 KaprekarNumbers CLICK
11 Fascinating Number CLICK
12 square Matrix CLICK
13 string having repeating characters CLICK
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
PATTERN * * * * * * * * * * *

ISCE

 THEORY

APC BOOK

PRACTICAL


PROJECT


SAMPLE COPY



UNION MAKE SET FIND SET


 













void make_set(int v) {
    parent[v] = v;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b)
        parent[b] = a;
}











There are two ways to improve it: 
1. Path Compression
2. Union by Rank










DAA

 The divide-and-conquer approach

DEFINITION-LINK

merge sort--LINK


SORT:

merge sort--LINK


GRAPH:

UNION MAKE SET FIND SET---LINK

PRIMS--

KRUSKAL--

DYSTRAS--

DFS--

BFS--

FLOYD--

WARSHALL--

WRAPPER CLASS

 Wrapper Classes-INTRODUCTION  CLICK

WRAPPER CLASS-AUTOBOX UNBOX  CLICK

WRAPPER CLASS-INTEGER  CLICK

WRAPPER CLASS-CHARACTER  CLICK

ARTIFICIAL INTELLIGENCE

 THOERY ---LINK

PRACTICAL---

CHAPTER WISE QUESTION----

ASSIGNMENT----

CBCS SYLLABUS-----

FOL PRACTISE--LINK


Saturday, July 22, 2023

GRAPHICS ADVANCED LEARNER

 1.

The Cohen-Sutherland Algorithm

2.

The Sutherland-Hodgman Algorithm

3.

Midpoint Subdivision Algorithm

GRAPHICS SLOW LEARNER

AI-SLOW LEARNER

AI-ADVANCED LEARNER

 

1.

If P represents 'This book is good' and Q represents 'This book is cheap', write the following sentences in symbolic form:

(a) This book is good and cheap.

(b) This book is not good but cheap.

(c) This book is costly but good.

(d) This book is neither good nor cheap.

(e) This book is either good or cheap.

 

2.

Translate the following sentences into propositional forms:

(a) If it is not raining and I have the time. then I will go to a movie.

(b) It is raining and I will not go to a movie.

(c) It is not raining.

(d) I will not go to a movie.

(e) I will go to a movie only if it is not raining.

Hints:

 Let P be the proposition 'It is raining'.

Let Q be the proposition 'I have the time'.

Let R be the proposition '1 will go to a movie'.

 

3.

Write the following sentences in symbolic form: (

a) This book is interesting but the exercises are difficult.

(b) This book is interesting but the subject is difficult.

(c) This book is not interesting. the exercises are difficult but the subject is not difficult.

(d) If this book is interesting and the exercises are not difficult then the subject is not difficult.

(e) This book is interesting means that the subject is not difficult, and conversely.

(f) The subject is not difficult but this book is interesting and the exercises are difficult.

(g) The subject is not difficult but the exercises are difficult.

(h) Either the book is interesting or the subject is difficult.

 

 

4.

Derive S from the following premises using a valid argument:

(i)                  P => Q

(ii)                Q => ¬R

(iii)               P v S

(iv)               R

 

5.

Check the validity of the following argument:

If Ram has completed B.E. (Computer Science) or MBA, then he is assured of a good job.

 If Ram is assured of a good job, he is happy.

Ram is not happy.

So Ram has not completed MBA.

 

6.

Express the following sentences involving predicates in symbolic form:

1. All students are clever.

2. Some students are not successful.

3. Every clever student is successful.

4. There are some successful students who are not clever.

5. Some students are clever and successful.

7.

Discuss the validity of the following argument:

All educated persons are well behaved.

Ram is educated.

No well-behaved person is quarrelsome.

Therefore. Ram is not quarrelsome.

8.

Test the validity of the following argument:

Babies are illogical.

Nobody is despised who can manage a crocodile.

Illogical persons are despised.

Therefore babies cannot manage crocodiles.

 

9.

Show that the following argument is valid:

All men are mortal.

Socrates is a man.

So Socrates is mortal.

 

10.

Test the validity of the following argument:

If Ram is clever then Prem is well-behaved.

If Joe is good then Sam is bad and Prem is not well-behaved.

If Lal is educated then Joe is good or Ram is clever.

Hence if Lal is educated and Prem is not well-behaved then Sam is bad.

Monday, July 17, 2023

15. Write a Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List using cut predicate.

 15. Write a Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List using cut predicate. 


maxlist([H],H).

maxlist([H|T],R):-

maxlist(T,M1),

 H>=M1,

 R is H,!.

maxlist([H|T],R):-

maxlist(T,M1),

 H<M1,

 R is M1.


OUTPUT:.

maxlist([1,20,2],X).

X = 20

 



16. Write a Prolog program to implement GCD of two numbers.

 16. Write a Prolog program to implement GCD of two numbers. 


gcd(X,0,X).

gcd(X,Y,Z):-

 R is mod(X,Y),

gcd(Y,R,Z).

OUTPUT:

gcd(6,9,X).

X = 3


17. Write a prolog program that implements Semantic Networks/Frame Structures.

 17. Write a prolog program that implements Semantic Networks/Frame Structures.




OUTPUT:

11. Write a Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List.

 11. Write a Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List.


max([H|T],R):-

 length(T,L),

 L>0 -> (  max(T,R1),  (   H > R1 ->     R is H    ;     R is R1  ) ) ; R is H.



OUTPUT:

max([6,9,7],X).

X = 9

max([6,9,70],X).

X = 70


10. Write a Prolog program to implement max(X,Y,Max) so that Max is the greater of two numbers X and Y.

 10. Write a Prolog program to implement max(X,Y,Max) so that Max is the greater of two numbers X and Y.


max(X,Y,R):-

 X>=Y ->

  R is X,

  write(R)

 ;

  R is Y,

  write(R).

 

OUTPUT:

max(2,6,X).

6

X = 6



12. Write a Prolog program to implement sumlist(List,Sum) so that Sum is the sum of a given list of numbers List.

  12. Write a Prolog program to implement sumlist(List,Sum) so that Sum is the sum of a given list of numbers List. 


sumlist([],0).

 

sumlist([H|T],R):-

sumlist(T,R1),

  R is H+R1.

OUTPUT:

sumlist([6,9,70],X).

X = 85


14. Write a Prolog program to implement reverse(List,ReversedList) that reverses lists.

 14. Write a Prolog program to implement reverse(List,ReversedList) that reverses lists. 


reverse([],[]).

reverse([X|T],REV):-reverse(T,R),append(R,[X],REV).


OUTPUT:


reverse([1,2,2],X).

X = [2, 2, 1]


13. Write a Prolog program to implement two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length respectively.

 13. Write a Prolog program to implement two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length respectively. 

evenlength:-

write('true --> even').

oddlength:-

write('true --> odd').

 

oddeven([_|T]):- length(T,L), L>=0 -> (  L1 is L+1,  L2 is mod(L1,2),  L2=:=0 ->evenlength  ;   oddlength ).




OUTPUT:

 

oddeven([5,8,9]).

true --> odd

1true

oddeven([5,8,6,9]).

true --> even

1true