Python Program To Find Decimal Equivalent Of Binary Linked List Last Updated : 22 Jun, 2022 Comments Improve Suggest changes Like Article Like Report Given a singly linked list of 0s and 1s find its decimal equivalent. Input: 0->0->0->1->1->0->0->1->0 Output: 50 Input: 1->0->0 Output: 4 The decimal value of an empty linked list is considered as 0. Recommended: Please solve it on "PRACTICE" first, before moving on to the solution. Initialize the result as 0. Traverse the linked list and for each node, multiply the result by 2 and add the node's data to it. Python3 # Python3 program to find decimal value # of binary linked list # Node Class class Node: # Function to initialise the # node object def __init__(self, data): # Assign data self.data = data # Initialize next as null self.next = None # Linked List class contains # a Node object class LinkedList: # Function to initialize head def __init__(self): self.head = None # Returns decimal value of binary # linked list def decimalValue(self, head): # Initialized result res = 0 # Traverse linked list while head: # Multiply result by 2 and # add head's data res = (res << 1) + head.data # Move Next head = head.next return res # Driver code if __name__ == '__main__': # Start with the empty list llist = LinkedList() llist.head = Node(1) llist.head.next = Node(0) llist.head.next.next = Node(1) llist.head.next.next.next = Node(1) print("Decimal Value is {}".format( llist.decimalValue(llist.head))) # This code is contributed by Mohit Jangra Output : Decimal value is 11 Time Complexity: O(n) where n is the number of nodes in the given linked list.Auxiliary Space: O(1), no extra space is required, so it is a constant. Please refer complete article on Decimal Equivalent of Binary Linked List for more details! Comment More infoAdvertise with us Next Article Python Program To Find Decimal Equivalent Of Binary Linked List kartik Follow Improve Article Tags : Linked List Python Programs DSA Juniper Networks Python-DSA +1 More Practice Tags : Juniper NetworksLinked List Similar Reads Python program to Search an Element in a Circular Linked List A linked list is a kind of linear data structure where each node has a data part and an address part which points to the next node. A circular linked list is a type of linked list where the last node points to the first one, making a circle of nodes. Example: Input: CList = 6->5->4->3->2 3 min read Python Program To Delete Middle Of Linked List Given a singly linked list, delete the middle of the linked list. For example, if the given linked list is 1->2->3->4->5 then the linked list should be modified to 1->2->4->5 If there are even nodes, then there would be two middle nodes, we need to delete the second middle element. For example, if g 4 min read Python Program To Delete Alternate Nodes Of A Linked List Given a Singly Linked List, starting from the second node delete all alternate nodes of it. For example, if the given linked list is 1->2->3->4->5 then your function should convert it to 1->3->5, and if the given linked list is 1->2->3->4 then convert it to 1->3. Recomm 3 min read Python Program For Finding The Middle Element Of A Given Linked List Given a singly linked list, find the middle of the linked list. For example, if the given linked list is 1->2->3->4->5 then the output should be 3. If there are even nodes, then there would be two middle nodes, we need to print the second middle element. For example, if given linked list 4 min read Python Program For Searching An Element In A Linked List Write a function that searches a given key 'x' in a given singly linked list. The function should return true if x is present in linked list and false otherwise. bool search(Node *head, int x) For example, if the key to be searched is 15 and linked list is 14->21->11->30->10, then functi 4 min read Python Program For Finding The Length Of Loop In Linked List Write a function detectAndCountLoop() that checks whether a given Linked List contains loop and if loop is present then returns count of nodes in loop. For example, the loop is present in below-linked list and length of the loop is 4. If the loop is not present, then the function should return 0. Re 4 min read Python3 Program for Clockwise rotation of Linked List Write a Python3 program for a given singly linked list and an integer K, the task is to rotate the linked list clockwise to the right by K places.Examples: Input: 1 -> 2 -> 3 -> 4 -> 5 -> NULL, K = 2 Output: 4 -> 5 -> 1 -> 2 -> 3 -> NULLInput: 7 -> 9 -> 11 -> 1 5 min read Python Program For Sorting A Linked List Of 0s, 1s And 2s Given a linked list of 0s, 1s and 2s, sort it.Examples: Input: 1 -> 1 -> 2 -> 0 -> 2 -> 0 -> 1 -> NULL Output: 0 -> 0 -> 1 -> 1 -> 1 -> 2 -> 2 -> NULL Input: 1 -> 1 -> 2 -> 1 -> 0 -> NULLÂ Output: 0 -> 1 -> 1 -> 1 -> 2 -> NULL Source: Microsoft Interview | Set 1 Recommended: Please solve it on "PRAC 3 min read Python Program To Delete N Nodes After M Nodes Of A Linked List Given a linked list and two integers M and N. Traverse the linked list such that you retain M nodes then delete next N nodes, continue the same till end of the linked list.Difficulty Level: Rookie Examples: Input: M = 2, N = 2 Linked List: 1->2->3->4->5->6->7->8 Output: Linked L 3 min read Python Program to Multiply Two Binary Numbers Given two binary numbers, and the task is to write a Python program to multiply both numbers. Example: firstnumber = 110 secondnumber = 10 Multiplication Result = 1100 We can multiply two binary numbers in two ways using python, and these are: Using bin() functions andWithout using pre-defined funct 2 min read Like