Data Structure
  • টাইম এন্ড স্পেস কমপ্লেক্সিটি
    • সূচনা
    • টাইম কমপ্লেক্সিটি
    • O(N) টাইম কমপ্লেক্সিটি
    • O(logN) টাইম কমপ্লেক্সিটি
    • O(sqrt(N)) টাইম কমপ্লেক্সিটি
    • টাইম কমপ্লেক্সিটির কিছু উদাহরন
    • টাইম কমপ্লেক্সিটি থেকে টাইম ক্যালকুলেট করা
    • স্পেস কমপ্লেক্সিটি
  • মডিউল ২ঃ STL Vector
    • ২-০ঃ সূচনা
    • ২-১ঃ ভেক্টর ইনিশিয়ালাইজেশন এবং কন্সট্রাক্টর
    • ২-২ঃ ভেক্টর ক্যাপাসিটি ফাংশন
    • ২-৩ঃ ভেক্টর মডিফাইয়ার ফাংশন -১
    • ২-৪ঃ ভেক্টর মডিফাইয়ার ফাংশন -২
    • ২-৫ঃ ভেক্টর এক্সেস এবং ইটারেটর
    • ২-৬ঃ ভেক্টরে ইনপুট নেয়া
    • ২-৭ঃ স্ট্রিং এর ভেক্টর
  • Prefix Sum and Binary Search
    • সূচনা
    • Range Sum Query (Codeforces)
    • Prefix Sum পরিচিতি
    • Prefix sum ইমপ্লিমেন্টেশন
    • Binary Search (Codeforces)
    • বাইনারি সার্চ পরিচিতি
    • বাইনারি সার্চ ইমপ্লিমেন্টেশন
  • মডিউল ৫ঃ Singly Linked List
    • ৫-০ঃ সূচনা
    • ৫-১ঃ Linked List কেন?
    • ৫-২ঃ Linked List কেন? (পার্ট ২)
    • ৫-৩ঃ Create a Node
    • ৫-৪ঃ Constructor of Node
    • ৫-৫ঃ Dynamic Node
    • ৫-৬ঃ Singly Linked List কিভাবে তৈরি হয়
    • ৫-৭ঃ Printing Singly Linked List
    • ৫-৮ঃ Printing Singly Linked List (Animated)
  • মডিউল ৬ঃ Singly Linked List Operation
    • ৬-০ঃ সূচনা
    • ৬-১ঃ পয়েন্টারের রেফারেন্স
    • ৬-২ঃ Tail এ ভ্যালু Insertion
    • ৬-৩ঃ যেকোন পজিশনে ভ্যালু Insertion
    • ৬-৪ঃ Head এ ভ্যালু Insertion
    • ৬-৫ঃ যেকোন পজিশনের ভ্যালু Deletion
    • ৬-৬ঃ Head ডিলিট
    • ৬-৭ঃ Error Handling
    • ৬-৮ঃ Singly Linked List এ ইনপুট
  • মডিউল ৭ঃ Singly Linked List recap
    • ৭-০ঃ সূচনা
    • ৭-১ঃ Singly Linked List recap
    • ৭-২ঃ Insert at Singly Linked List Recap
    • ৭-৩ঃ Insert at Head and Tail at Singly Linked List Recap
    • ৭-৪ঃ Delete from Singly Linked List Recap
    • ৭-৫ঃ Delete Head from Singly Linked List Recap
    • ৭-৬ঃ Take Singly Linked List Input Recap
    • ৭-৭ঃ Printing Singly Linked List in Reverse
    • ৭-৮ঃ Sort Singly Linked List
    • ৭-বোনাসঃ Singly Linked list all operations complexity analysis
  • মডিউল ৯: Doubly Linked List
    • ৯-০ঃ সূচনা
    • ৯ -১ঃ Doubly Linked List
    • ৯-২ঃ Doubly Linked List দেখতে কেমন?
    • ৯-৩ঃ Doubly Linked List এর যেকোনো position এ value insert
    • ৯-৪ঃ Insert at Head and Tail in Doubly Linked List
    • ৯-৫ঃ Insert Operation on Doubly Linked List Animated
    • ৯-৬ঃ Delete Operations on Doubly Linked List
    • ৯-৭ঃ Complexity Analysis
    • মডিউল ৯-৮ঃ Doubly Linked List এ input নেয়া
  • মডিউল ১০: STL List and Cycle Detection
    • ১০-০ঃ সূচনা
    • ১০-১ঃ List Constructors
    • ১০-২ঃ List Capacity Functions
    • ১০-৩ঃ List Modifiers Functions
    • ১০-৪ঃ List Operations and Access Related Function
    • ১০-৫ , ১০-৬ঃ Reverse a Singly Linked List
    • ১০-৭ঃ Reverse a Doubly Linked List
    • ১০-৮ঃ Detect Cycle in Singly Linked List
  • মডিউল ১১ঃ Problem Solving using Linked list
    • মডিউল ১১-০ঃ সূচনা
    • মডিউল ১১-১ঃ Middle of the Linked List
    • মডিউল ১১-২ঃ Linked List Cycle
    • মডিউল ১১-৩ঃ Remove Duplicate from Sorted List
    • মডিউল ১১-৪ঃ Reverse Linked List
    • মডিউল ১১-৫ঃ Palindrome Linked List
    • মডিউল ১১-৬ঃ Delete Node in a Linked List
  • Module 13: Stack Implementation and STL
    • মডিউল ১৩-০ঃ সূচনা
    • মডিউল ১৩-১ঃ What is stack (animation)
    • মডিউল ১৩-২,৩ঃ What is stack
    • মডিউল ১৩- ৪,৫ঃ Stack Implement using Array
    • মডিউল ১৩-৬ঃ Stack Implement using List
    • মডিউল ১৩-৭ঃ Stack Implement using Doubly Linked List
    • মডিউল ১৩-৮ঃ STL Stack
  • মডিউল ১৪ঃ Queue Implmentation and STL
    • ১৪-০ঃ সূচনা
    • ১৪-১,১৪-২ঃ Queue কী এবং Queue এর কিছু বাস্তব উদাহরণ
    • ১৪-৩ঃ Singly Linked List এর সাহায্যে Queue তৈরি করা
    • ১৪-৪ঃ Doubly Linked List এর সাহায্যে Queue তৈরি করা
    • ১৪-৫ঃ STL List এর সাহায্যে Queue তৈরি করা
    • ১৪-৬ঃ Queue এর STL লাইব্রেরি
    • ১৪-৭ঃImplement Stack using Queue (Leetcode)
    • ১৪-৮ঃ Implement Queue using Stacks (Leetcode)
  • মডিউল ১৫ঃ Problem Solving using Stack & Queue
    • মডিউল ১৫-০ঃ সূচনা
    • মডিউল ১৫-১ঃ Valid Parentheses (Leetcode)
    • মডিউল ১৫-২ঃ Backspace String Compare (Leetcode)
    • মডিউল ১৫-৩ঃ Insert Element At Bottom of Stack (CodingNinjas)
    • মডিউল ১৫-৪ঃ Maximum Equal Stack Sum (CodingNinjas)
    • মডিউল ১৫-৫ঃ Reversing a Queue (CodingNinjas)
    • মডিউল ১৫-৬ঃ Reverse Stack Using Recursion (CodingNinjas)
  • মডিউল ১৭: Binary Tree Implementation
    • মডিউল ১৭-০ঃ সূচনা
    • মডিউল ১৭-১ঃ Discussion about Tree Data Structure
    • মডিউল ১৭-৩ঃ Discussion about Binary Tree
    • মডিউল ১৭- ৪ঃ Create a Binary Tree
    • মডিউল ১৭-৫ঃ Pre Order Traversal of Binary Tree
    • মডিউল ১৭-৭ঃ Post Order Traversal of Binary Tree
    • মডিউল ১৭-৮ঃ In Order Traversal of Binary Tree
  • মডিউল ১৮ঃ Operations On Binary Tree
    • ১৮-০ঃ সূচনা
    • ১৮-১ঃ Level Order Traversal of Binary Tree থিওরি
    • ১৮-২ঃ Level Order Traversal of Binary Tree ইমপ্লিমেন্টেশন
    • ১৮-৩ঃ Binary Tree Input থিওরি
    • ১৮-৪ঃ Binary Tree Input ইমপ্লিমেন্টেশন
    • ১৮-৫ঃ Count Number of Nodes of a Binary Tree
    • ১৮-৬ঃ Count Number of Leaf Nodes of a Binary Tree
    • মডিউল ১৮-৭ঃGet the Maximum Height of a Binary Tree
  • মডিউল ১৯ঃ Problem Solving using Binary Tree
    • মডিউল ১৯-০ঃ সূচনা
    • মডিউল ১৯-১ঃ Is Node Present (Coding Ninjas)
    • মডিউল ১৯-২ঃ STL Pair, Node Level (Coding Ninjas)
    • মডিউল ১৯-৩ঃ Left View Of a Binary Tree (Coding Ninjas)
    • মডিউল ১৯-৪ঃ Diameter Of Binary Tree (Coding Ninjas)
    • মডিউল ১৯-৫ঃ Special Binary Tree (Coding Ninjas)
    • মডিউল ১৯-৬ঃ Reverse Level Order Traversal (Coding Ninjas)
  • মডিউল ২১ঃ Binary Search Tree Implementation
    • মডিউল ২১-০ঃ সূচনা
    • মডিউল ১৭-১ঃ What is BST
    • মডিউল ২১-২ঃ How to Handle Duplicate in BST
    • মডিউল ২১-৩ঃ Search in BST
    • মডিউল ২১-৫ঃ Insert in BST
    • মডিউল ২১-৭ঃ Convert Array to BST
  • মডিউল ২২ঃ Heap Implmentation
    • ২২-০ঃ সূচনা
    • ২২-১ঃ Complete Binary Tree কী
    • ২২-২ঃ Complete Binary Tree এর Array Representation
    • ২২-৩ঃ Heap কী
    • ২২-৪ঃ Heap এ Insertion এর থিওরি
    • ২২-৫ঃ Heap এ Insertion ইমপ্লিমেন্টেশন
    • ২২-৬ঃ Heap এ Deletion থিওরি
    • ২২-৭ঃ Heap এ Deletion ইমপ্লিমেন্টেশন
  • মডিউল ২৩ঃ STL Priority Queue, Map and Set
    • মডিউল ২৩-০ঃ সূচনা
    • মডিউল ২৩-১ঃ Priority Queue কি?
    • মডিউল ২৩-২ঃ কিভাবে STL Priority Queue কাজ করে
    • মডিউল ২৩-৩ঃ Custom Compare Class for Priority Queue
    • মডিউল ২৩-৪ঃ map কি?
    • মডিউল ২৩-৫ঃ কিভাবে STL map কাজ করে
    • মডিউল ২৩-৬ঃ Count Words in a String using Map
    • মডিউল ২৩-৭ঃ কিভাবে STL set কাজ করে
Powered by GitBook
On this page
  1. মডিউল ১০: STL List and Cycle Detection

১০-৩ঃ List Modifiers Functions

Previous১০-২ঃ List Capacity FunctionsNext১০-৪ঃ List Operations and Access Related Function

Last updated 10 months ago

List কে মডিফাই করার বিভিন্ন ফাংশনঃ 1. List এসাইনঃ আমরা চাইলে একটি List এ আরেকটি List এসাইন করতে পারি। যদি ঐ দুইটি List সাইজ সমান হয় , সেক্ষেত্রে এই এসাইনের টাইম কমপ্লেক্সিটি হবে O(1) , অন্যথায় এর টাইম কমপ্লেক্সিটি হবে O(N)

list<int> my_list = {1,2,3,4} ;

list<int> new_list ;

new_list = new_list ; // new_list এর মধ্যে my_list er সব ভ্যালু এসাইন হয়ে যাবে। 
  1. push_back() -> এই ফাংশনের মাধ্যমে আমরা List এর শেষের দিকে একটি ভ্যালু insert করতে পারি । অর্থাৎ এটি insert_at_tail এর মতো কাজ করে। একটি ভ্যালু insert করার পর list টির সাইজ ১ বেড়ে যাবে। এই ফাংশনের টাইম কমপ্লেক্সিটি হলো O(1).

list<int> my_list = {1,2,3,4} ;

my_list.push_back(6) ; // ডান সাইডে ভ্যালু ৬ insert করবে

for(int element : my_list ) {

cout << element << " " ;

} // 1 2 3 4 6
  1. push_front() -> এই ফাংশনের মাধ্যমে আমরা List এর প্রথম দিকে একটি ভ্যালু insert করতে পারি । অর্থাৎ এটি insert_at_head এর মতো কাজ করে। একটি ভ্যালু insert করার পর list টির সাইজ ১ বেড়ে যাবে। এই ফাংশনের টাইম কমপ্লেক্সিটি হলো O(1).

list<int> my_list = {1,2,3,4} ;

my_list.push_front(6) ; // বাম সাইডে ভ্যালু ৬ insert করবে

for(int element : my_list ) {

cout << element << " " ;

} // 6 1 2 3 4
  1. pop_back() -> এই ফাংশনের সাহায্যে আমরা List এর সর্ব ডানের ভ্যালুটি ডিলিট করতে পারি। ভ্যালু কমে যাওয়ার কারণে List এর সাইজ ও ১ কমে যাবে। এই ফাংশনের টাইম কমপ্লেক্সিটি O(1).

list<int>my_list = {5,6,7,8,9} ;

my_list.pop_back() ; // ডান সাইডে ভ্যালু 9 delete হয়ে যাবে

for(int element : my_list) {

cout << element << " " ;

} // 5 6 7 8 
  1. pop_front() -> এই ফাংশনের সাহায্যে আমরা List এর সর্ব বামের ভ্যালুটি ডিলিট করতে পারি। ভ্যালু কমে যাওয়ার কারণে List এর সাইজ ও ১ কমে যাবে। এই ফাংশনের টাইম কমপ্লেক্সিটি O(1).

list<int>my_list = {10,5,6,7,8} ;

my_list.pop_front() ; // বাম সাইডে ভ্যালু ১০ delete হয়ে যাবে

for( int element : my_list) {

cout << element << " " ;

} // 5 6 7 8 
  1. my_list.insert() : এই ফাংশনের সাহায্যে আমরা List এর যেকোন index (not similar to array) এ ভ্যালু এড করতে পারবো। এই ফাংশনের টাইম কমপ্লেক্সিটি হলো O(N+K) যেখানে N হলো list এর সাইজ এবং K হলো আমরা কয়টি ভ্যালু insert করবো তার সংখ্যা। ধরেন আমরা চাচ্ছি আমাদের list এর k তম index ভ্যালু ১০ এড করতে। এই ক্ষেত্রে আমরা লিখবো , তার my_list. insert(next(my_list.begin(),2),value) এবং তার ভ্যালু। next() হলো একটি ফাংশন যার সাহায্যে আমরা List এর শুরু থেকে শুরু কোন একটি index এর পয়েন্টার পাবো।

list<int> my_list = {5,6,7,8,9} ;

my_list.insert(next(my_list.begin(),2) , 10 ) // list টির ২ নাম্বার index ১০ insert হয়ে যাবে। 

for(auto element : my_list){
cout << element << " " ; 
} 
// 5 6 10 7 8 9 
  1. my_list.erase() : এই ফাংশনের সাহায্যে আমরা কোনো একটি List এর নির্দিষ্ট index এর ভ্যালু ডিলিট করে দিতে পারি। এই ক্ষেত্রেও ফাংশনের ঐ index এর পয়েন্টার দিতে হবে , যা আমরা next ফাংশনের সাহায্যে খুব সহজে বের করে নিতে পারি।

list<int> my_list = {5,6,7,8,9} ;

my_list.erase(next(my_list.begin(),2)) ; // list টির ২ নাম্বার index delete হয়ে যাবে 

for(auto element : my_list){
cout << element << " " ; 
} 
// 5 6 8 9 

ভেক্টরের মতো replace and find ও List এর ক্ষেত্রে কাজ করে

  1. replace() -> এই ফাংশনের সাহায্যে আমরা list এর কোন একটি নির্দিষ্ট রেঞ্জের একটি নির্দিষ্ট ভ্যালুকে অন্য একটি ভ্যালু দিয়ে রিপ্লেস করে দিতে পারি। এই ফাংশনের টাইম কমপ্লেক্সিটি হলো O(N) .

Syntax : replace(my_list.begin() , my_list.end() , target_value , change_value)

list<int>my_list = {1,2,3,4,7,6,4,5,4,3,4} ;

replace(my_list.begin() , my_list.end() , 4, 100) // এই ফাংশন টি list এর যে যে স্থানে ভ্যালু 4 আছে তা চেঞ্জ করে 100 করে দিবে 

for(int element : my_list) {

cout << element << " "  ;

} // Output :  1 2 3 100 7 6 100 5 100 3 100 
  1. find() -> এই ফাংশনের সাহায্যে আমরা List এর কোন একটি ভ্যালু আছে কিনা খুজে দেখতে পারি। এই ফাংশন আমাদের একটি ইটারেটর রিটার্ন করে যা ঐ ভ্যালুটির ইন্ডেক্সে পয়েন্ট করা থাকে, আর যদি ভ্যালুটি খুজে না পায় তবে my_list.end() এ পয়েন্ট করে থাকে । এই ফাংশনের টাইম কমপ্লেক্সিটি হলো O(N).

Syntax : find(my_list.begin() , my_list.end() , target_value )

list<int> my_list = {1,2,3,4,7,6,4,5,4,3,4} ;

auto it = find(my_list.begin() , my_list.end() , 6) ; // ৬ ভ্যালুটি list এর মধ্যে পেলে প্রথম যে জায়গায় ভ্যালুটি আছে তার ইটারেটর টা রিটার্ন করা হবে


if( it !=my_list.end()){ // যদি ভ্যালুটি পাওয়া না যায় তবে it তে my_list.end() স্টোর হবে। 
cout << "found the value " << *it << endl } // যেহেতু ইটারেটর একটি পয়েন্টার এর মতো কাজ করে , তাই আমরা it কে dereferencing করে তার ভ্যালু দেখতে পারবো
else {
cout << "not found" << endl ;
} 
Drawing
Drawing
Drawing
Drawing
Drawing