Liam's Blog


  • Home

  • Archives

  • Tags

  • Categories

  • Photos

  • About

Counting Inversions

Posted on 2018-08-27 | Post modified 2018-08-31 | In Algorithms , Languages , Divide and Conquer , Python

Problem

Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum. Formally speaking, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j

Example

  • The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 3).
  • The sequence 1, 3, 5, 2, 4, 6 has three inversions (3, 2), (5, 2), (5, 4).
Read more »

coffee-with-latte-art scraper

Posted on 2018-08-15 | Post modified 2018-08-15 | In Side Projects , Coffee Scraper

Prolog Programming for AI - Chapter 3 Exercises

Posted on 2018-08-13 | Post modified 2018-08-12 | In Languages , Prolog

Relations

  • Membership (has more procedural meaning)

  • Membership (has more declarative meaning)

  • Concatenation (or append)

  • Delete the last three emelemts

  • Delete the first three and the last three elements

    Read more »

LeetCode #1 Two Sum

Posted on 2018-08-12 | Post modified 2018-09-11 | In Algorithms , Hash Table , LeetCode , Brute Force , Difficulties , Algorithms , Data Structures , Easy , Hash Table , Array , Brute Force

Problem

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example

1
2
3
4
Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
Read more »
1…1718
Liam Wang

Liam Wang

Liam's Personal Blog

174 posts
133 categories
64 tags
© 2019 Liam Wang
Powered by Hexo
Theme - NexT.Muse