Total Pageviews

Tuesday, June 2, 2020

SEARCHING ALGORITHM

1. LINEAR SERACH ALGORITHM - CLICK HERE
2. BINARY SEARCH ALGORITHM - CLICK HERE

BINARY SEARCH ALGORITHM STEP BY STEP

BINARY SEARCH ALGORITHM STEP BY STEP

🎯 What is Binary Search?

Binary Search is a fast searching technique used to find an element in a sorted array by repeatedly dividing the search space into half.


📌 Definition

Binary Search is a divide-and-conquer algorithm that finds an element in a sorted list by comparing the target value with the middle element.


⚠️ Important Condition

✔ The array must be sorted (ascending or descending)
❌ Binary search does NOT work on unsorted data


🧠 How Binary Search Works

Steps:

  1. Find middle element
  2. Compare middle element with target
  3. If match → stop
  4. If target is smaller → search left half
  5. If target is larger → search right half
  6. Repeat until found or range becomes empty

📊 Example

Sorted Array:

A = [10, 20, 30, 40, 50, 60, 70]

Target:

Find 50

Step-by-step:

StepLowHighMidValueAction
10634050 > 40 → right half
24656050 < 60 → left half
344450✅ Found

💻 Algorithm (Pseudocode)

BinarySearch(A, key)

1. low = 0
2. high = n - 1

3. while low <= high
4. mid = (low + high) / 2
5. if A[mid] == key
6. return mid
7. else if key < A[mid]
8. high = mid - 1
9. else
10. low = mid + 1

11. return -1

🐍 Python Program for Binary Search

def binary_search(arr, key):
low = 0
high = len(arr) - 1

while low <= high:
mid = (low + high) // 2

if arr[mid] == key:
return mid
elif key < arr[mid]:
high = mid - 1
else:
low = mid + 1

return -1

# Example
arr = [10, 20, 30, 40, 50, 60, 70]
key = 50

result = binary_search(arr, key)

if result != -1:
print("Element found at index:", result)
else:
print("Element not found")

Output:

Element found at index: 4

⚡ Time Complexity

CaseComplexity
Best CaseO(1)
Worst CaseO(log n)
Average CaseO(log n)

📊 Why Binary Search is Fast?

Each step reduces search space by half:

Example:

  • 8 elements → 4 → 2 → 1

So it grows very slowly compared to linear search.


🆚 Binary Search vs Linear Search

FeatureLinear SearchBinary Search
Data RequirementUnsortedSorted
SpeedSlow (O(n))Fast (O(log n))
MethodSequentialDivide & Conquer
EfficiencyLowHigh

📌 Advantages of Binary Search

  • Very fast for large datasets
  • Reduces comparisons drastically
  • Efficient algorithm

❌ Disadvantages

  • Requires sorted data
  • Not suitable for dynamic/unsorted lists
  • More complex than linear search

🧠 Real Life Example

  • Finding a word in dictionary 📖
  • Searching a name in sorted telephone directory 📞

📌 Summary

  • Binary search works only on sorted data.
  • It divides the list into halves repeatedly.
  • It is much faster than linear search.
  • Time complexity is O(log n).

❓ Important Questions

Short Questions

  1. What is binary search?
  2. What is the condition for binary search?
  3. What is time complexity of binary search?
  4. What is mid element?
  5. Give one real-life example.

Long Questions

  1. Explain binary search with example.
  2. Write algorithm of binary search.
  3. Write Python program for binary search.
  4. Compare linear and binary search.
  5. Explain time complexity of binary search.

LINEAR SEARCH ALGORITHM STEP BY STEP

LINEAR SEARCH ALGORITHM STEP BY STEP

🎯 What is Linear Search?

Linear Search is a simple searching technique used to find an element in a list or array by checking each element one by one from the beginning to the end.


📌 Definition

Linear Search is a sequential searching algorithm where each element is compared with the target value until a match is found or the list ends.


🧠 How Linear Search Works

  • Start from the first element
  • Compare each element with the target value
  • If match found → Stop
  • If not found → Move to next element
  • Continue until end of list

📊 Example

Array:

A = [10, 25, 30, 45, 60]

Target:

Find 30

Step-by-step Process:

StepElement CheckedResult
110Not match
225Not match
330✅ Match found

💻 Algorithm (Pseudocode)

LinearSearch(A, n, key)

1. for i = 0 to n-1
2. if A[i] == key
3. return i
4. return -1

🐍 Linear Search Program (Python)

def linear_search(arr, key):
for i in range(len(arr)):
if arr[i] == key:
return i
return -1

# Example
arr = [10, 25, 30, 45, 60]
key = 30

result = linear_search(arr, key)

if result != -1:
print("Element found at index:", result)
else:
print("Element not found")

Output:

Element found at index: 2

⚡ Best Case, Worst Case

CaseConditionComplexity
Best CaseElement at first positionO(1)
Worst CaseElement at last or not presentO(n)
Average CaseRandom positionO(n)

📌 Advantages of Linear Search

  • Very simple to understand
  • Works on unsorted data
  • No extra memory required

❌ Disadvantages

  • Slow for large data sets
  • Not efficient compared to binary search

🆚 Linear Search vs Binary Search

FeatureLinear SearchBinary Search
Data RequirementUnsortedSorted
SpeedSlowFast
MethodSequentialDivide & Conquer

🧠 Real Life Example

  • Searching a name in attendance register
  • Finding a contact in phone list (unsorted)

📌 Summary

  • Linear search checks elements one by one.
  • It is simple but inefficient for large data.
  • Best used for small or unsorted datasets.

❓ Important Questions

Short Questions

  1. What is linear search?
  2. What is time complexity of linear search?
  3. Give one advantage of linear search.
  4. Is sorting required in linear search?
  5. Write one real-life example.

Long Questions

  1. Explain linear search with example.
  2. Write algorithm of linear search.
  3. Write a program for linear search.
  4. Compare linear and binary search.
  5. Explain best and worst case of linear search.

GRAPH THEORY

1. GRAPH THEORY ALGORITHMS - CLICK HERE

2. GRAPH THEORY N.DEO CHAPTER WISE QUESTION - CLICK HERE


GRAPH THEORY ALGORITHMS

 1. DEPTH FIRST SEARCH - CLICK HERE
 2. BREADTH FIRST SEARCH - CLICK HERE
 3. FLOYD ALGORITHM - 
 4. WARSHALL ALGORITHM - 
 5. PRIM'S ALGORITHM - CLICK HERE
 6. KRUSKAL'S ALGORITHM -CLICK HERE
 7. DYSTRA'S ALGORITHM -  CLICK HERE

BREADTH FIRST SEARCH ( BFS) ALGORITHM IMPLEMENTATION STEP BY STEP

BREADTH  FIRST SEARCH ( BFS) ALGORITHM IMPLEMENTATION STEP BY STEP


DEPTH FIRST SEARCH ( DFS) ALGORITHM IMPLEMENTATION STEP BY STEP

DEPTH FIRST SEARCH ( DFS) ALGORITHM IMPLEMENTATION STEP BY STEP


Monday, May 25, 2020

java theory question set 4

BALAGURUSAMY CHAPTER 4::

 SL. NO    QUESTION MARKS  PAGE NO  LINK1 LINK2  LINK3
 1. PRIMITIVE ,NON PRIMITIVE DATA TYPES  246   
 2.SIZE AND RANGE OF DATA TYPES 248    
 3.SCOPE OF VARIABLES  251   
 4. TYPE CASTING 2 53   
 5. AUTO TYPE CASTING   2 53    
 6. DEFAULT VALUE OF DATA TYPE 257   

java theory question set 3

BALAGURUSAMY CHAPTER 3::

 SL. NO   QUESTION MARKS  PAGE NO  LINK1 LINK2  LINK3
 1. WHY MAIN() IS STATIC 2 26   
 2. TOKEN 230    
 3. LITERALS  33   
 4. SEPARATORS  34   
 5. CLASSIFICATION OF JAVA STATEMENTS 36    
 6. JAVA VIRTUAL MACHINE  39   
 7. COMMAND LINE ARGUMENT  40   

java theory question set 2

 BALAGURUSAMY CHAPTER 2::


 SL. NO   QUESTION   MARKS PAGE NO LINK1 LINK2   LINK3
 1.  COMPILER AND INTERPRETER 4 13   
 2.  BYTECODE 2 13   
 3. JVM     
 4. COMPARE WITH C AND C++ 3 15   
 5. JAVA DEVELOPMENT TOOLS  TABLE 2.3   
 6. APPLICATION PROGRAMMING INTERFACE  22   

java theory question set 1

    BALAGURUSWAMY CHAPTER 1::


 SL. NO  QUESTION  MARKSPAGE NO LINK1 LINK2  LINK3
1.  DATA ABSTRACTION   2 4    
2. ENCAPSULATION  24    
 3.INHERITANCE   2 4    
 4.POLYMORPHISM  2 5   
5.  DYNAMIC BINDING  2 6   
6. MESSAGE COMMUNICATION   2  6   
7. BENEFIT OF OOPS  3 8   



Tuesday, May 19, 2020

COMPUTER ARCHITECTURE LAB ASSIGNMENT

 1. LDA , STA instruction IN COMPUTER ARCHITECTURE  LINK
 2.  addition of two hexadecimal numbers  LINK
 3.   addition of three hexadecimal numbers  LINK
 4. 1'S COMPLEMENT OF A NUMBER     LINK
 5. 2'S COMPLEMENT OF A NUMBER  LINK
 6. SUBTRACTION of two hexadecimal number  LINK
 7. LDA DIRECT MODE , INDIRECT MODE   LINK
 8. STA direct mode indirect mode  LINK
 9. ADD DIRECT MODE INDIRECT MODE  LINK 
 10. AND INSTRUCTION DIRECT INDIRECT MODE  LINK
 11. OR OPERATION USING AND INSTRUCTION  LINK
 12. ADDITION OF TWO DECIMAL ADDITION  LINK
 13.CIR INSTRUCTION  LINK
 14. CIL INSTRUCTION   LINK 
 15.CLE,CME INSTRUCTION   LINK 
 16.4TIMES CIL   LINK 
 17. 4TIMES CIR  LINK 
 18. BUN INSTRUCTION LINK 
 19.ISZ INSTRUCTION   LINK 
 20.SPA INSTRUCTION  LINK
 21. SNA INSTRUCTION  LINK 
 22. SZA INSTRUCTION  LINK
 23.SZE INSTRUCTION  LINK
   


POINTER

1. int array and int pointer in c language  LINK
2. char pointer and char array in c language LINK

OPERATOR IN C LANGUAGE

UNARY ++ - LINK
UNARY --     LINK
OUTPUT OF printf("%d %d %d ", x++,x,++x ) LINK


C PRACTICAL

1. BASIC  
2. IF-ELSE
3. LOOP
4. NESTED LOOP
5. POINTER  -- LINK
6. PREFIX , POSTFIX OPERATOR  -- LINK

ADDITION OF TWO DECIMAL ADDITION


ADDITION OF TWO DECIMAL ADDITION 

OR OPERATION USING AND INSTRUCTION BY BIJAN KRISHNA PAUL


                   OR OPERATION USING AND INSTRUCTION 

sta direct mode indirect mode BY BIJAN KRISHNA PAUL


                                  sta direct mode indirect mode BY BIJAN KRISHNA PAUL


AND INSTRUCTION DIRECT INDIRECT MODE BY BIJAN KRISHNA PAUL

           AND INSTRUCTION DIRECT INDIRECT MODE BY BIJAN KRISHNA PAUL


ADD DIRECT MODE INDIRECT MODE BY BIJAN KRISHNA PAUL

                  ADD DIRECT MODE INDIRECT MODE BY BIJAN KRISHNA PAUL


LDA DIRECT MODE INDIRECT MODE BY BIJAN KRISHNA PAUL

                             LDA DIRECT MODE INDIRECT MODE BY BIJAN KRISHNA PAUL

char pointer and char array in c language


                                                   char pointer and char arrray in c language 

int array and int pointer in c language

                                                   int array and int pointer in c language

printf("%d %d %d ", x++,x,++x ) in c language

printf("%d %d %d ", x++,x,++x ) in c language